SharezoneApp / sharezone-app

Sharezone is a collaborative school organization app for iOS, Android, macOS and web with +500,000 downloads. Built with Flutter & Firebase.
https://sharezone.net
European Union Public License 1.2
254 stars 46 forks source link

Rewrite Homework Reminder implementation (more cost efficient) #1604

Open nilsreichardt opened 1 month ago

nilsreichardt commented 1 month ago

System Design

Subcollections approach (push)

Disadvantage:

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:

  1. Reading the default homework reminder setting, n times
  2. 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:

  1. Cloud task triggers cloud function to send notification
  2. Reading m times the homework information
  3. Reading m times the notification token

Amount of reads: 2*m Amount of writes: 0

Deleting a homework:

  1. listDocuments in subcollection to get the task id
  2. Delete the cloud task

Amount of reads: 1 Amount of deletions: 0

Updating the times:

  1. Reading m reminder documents
  2. 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)

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:

  1. Reading the default homework reminder setting
  2. Creating a reminder document

Amount of reads: n Amount of writes: n

Sending the push notification:

  1. Reading m reminder documents
  2. Reading m times the homework information
  3. 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.

Deleting a homework:

  1. Reading m reminders
  2. Delete m reminders

Amount of reads: m Amount of deletions: m

Updating the times:

  1. Reading m reminder documents
  2. Update reminder time in m documents

Amount of reads: m Amount of writes: m