We chose to build a simple todo application to see what are the main benefits of Firebase and what are the challenges in building a Firebase app. The idea was that the user opens the web page, adds tasks to the list and then each day gets a notification email with a list of tasks for the day. Additionally, the email contains info about your overdue tasks and a list of tasks you’ve completed the day before. Angular was chosen as the framework - it has a native Firebase library which lets you perform user authentication and access data.
One of the main challenges turned out to be the organization of data in the database. At first, we tried the simplest approach: a collection called todos has objects inside of it, which are stored by user Id as their key, inside of them the tasks are stored with unique Ids as keys. Right now Firebase Database queries are limited - certain query options can’t be combined.
Because of one of the main challenges turned out to be the organization of data in the database. At first, we tried the simplest approach: a collection called todos has objects inside of it, which are stored by user Id as their key, inside of them the tasks are stored with unique Ids as keys. Right now Firebase Database queries are limited - certain query options can’t be combined. Because of this, we had to choose, either we want to order the documents by date or filter them with user’s search query on the database side and perform the other action on the client side.
Later we decided to use the user’s email as the key for their data - and quickly realized that emails can’t be used as keys because they contain dots, so the dots had to be replaced with commas for storage and backward at the stage when the email notifications are sent. This turned out to be a poor decision - in Firebase there is no easy way to restrict user access if the data is stored with anything else other than the user UID.
At some point, we decided to rewrite the code to group the data by date in addition to grouping by the user. Without grouping, everything could have become slow at later stages when there would be a lot of data. Another reason was that with documents grouped by the date it would be much easier to get the data for notification emails - we could just query by date.
In the past, there was a Firebase component called queue that provided intermediate logic for data writes. After the point where users wrote to the queue, some server logic could have been added to process and write the data to the appropriate collection. But this project seems to be no longer maintained and is largely replaced with Firebase Functions. We tried to recreate the queue with Firebase Functions and it could have been done but wouldn’t be pretty.