A Homework/{homeworkId}/Reminders/{taskId} collection
When a homework will be deleted: listDocuments() in the subcollection to get the task IDs -> Delete tasks
When the due date have been edited: listDocuments() in the subscollection to get the task IDs -> Delete tasks and create new ones
Disadvantage:
You need to n documents to re-schedule them, if the due date changed.
Advantage:
We can support reminders for every minute
Costs
n = amount of course members
m = amount of reminders (e.g. when every course member has 1 reminder is n = m)
Creating a homework:
Reading the default homework reminder setting, n times
Creating a reminder document, n times (maybe more than n times if someone have more than 1 default reminder) & create cloud task
Amount of reads: n
Amount of writes: n
Sending the push notification:
Cloud task triggers cloud function to send notification
Reading m times the homework information
Reading m times the notification token
Amount of reads: 2*m
Amount of writes: 0
Deleting a homework:
listDocuments in subcollection to get the task id
Delete the cloud task
Amount of reads: 1
Amount of deletions: 0
Updating the times:
Reading m reminder documents
In case we only store e.g. 24h before due date, we only need to create new cloud tasks, no new write
Amount of reads: m
Amount of writes: 0
Top-Level Reminders Collection (pull)
A top level collection with all reminders, cloud function pulls every 15 minutes
Cloud Functions pull every 15 minutes and distributes these tasks to a different cloud function
Pulling cloud function can bottleneck, sharding?
Document ID something like: {homeworkId};{reminderTime}? Advantage: Reminder to the same time will be grouped.
Costs
n = amount of course members
m = amount of reminders (e.g. when every course member has 1 reminder is n = m)
Creating a homework:
Reading the default homework reminder setting
Creating a reminder document
Amount of reads: n
Amount of writes: n
Sending the push notification:
Reading m reminder documents
Reading m times the homework information
Reading m times the notification token
Amount of reads: 3*m
Amount of writes: 0
Potential optimization: We store the notification tokens and the needed information for the notification (title and subject name) inside the reminder document. This would reduce it to m reads instead of 3m.
System Design
Subcollections approach (push)
Homework/{homeworkId}/Reminders/{taskId}
collectionlistDocuments()
in the subcollection to get the task IDs -> Delete taskslistDocuments()
in the subscollection to get the task IDs -> Delete tasks and create new onesDisadvantage:
Advantage:
Costs
n = amount of course members m = amount of reminders (e.g. when every course member has 1 reminder is n = m)
Creating a homework:
Amount of reads: n Amount of writes: n
Sending the push notification:
Amount of reads: 2*m Amount of writes: 0
Deleting a homework:
listDocuments
in subcollection to get the task idAmount of reads: 1 Amount of deletions: 0
Updating the times:
Amount of reads: m Amount of writes: 0
Top-Level Reminders Collection (pull)
{homeworkId};{reminderTime}
? Advantage: Reminder to the same time will be grouped.Costs
n = amount of course members m = amount of reminders (e.g. when every course member has 1 reminder is n = m)
Creating a homework:
Amount of reads: n Amount of writes: n
Sending the push notification:
Amount of reads: 3*m Amount of writes: 0
Potential optimization: We store the notification tokens and the needed information for the notification (title and subject name) inside the reminder document. This would reduce it to m reads instead of 3m.
Deleting a homework:
Amount of reads: m Amount of deletions: m
Updating the times:
Amount of reads: m Amount of writes: m