satitpm-council / pm-station

"PM Station", A school radio project with music and content.
0 stars 1 forks source link

[Migration] Migrate away from Firebase to another database solution #3

Open lemasc opened 1 year ago

lemasc commented 1 year ago

At the beginning of this project, we use Firebase Firestore as a database for storing song request records, because of its ease of use and has built-in authentication. However, as more records are stored, we need a way to search and filter the records. Built-in sort and filtering by Firestore is not enough.

We quickly discover Algolia, the search engine provider, that can intergrates with Firebase to provide a full text search and filtering. We can implement easily by using the "Search with Algolia" Firebase Extension. This extension will listen for document updates via Firebase Functions, and update the objects in Algolia. By using the functions, it will cost a very little amount of money.

Why migrating away?

Actually the first is because money (haha), GCP doesn't accept prepaid credit cards, so transfering the project in each school year will be a bit harder, but it's not really an issue.

The current strategy contains fetching waterfall. The record stored for indexing in Algolia contains partial data, and needs to be update with the Firestore for an up-to-date data. When the record has updated, the records from Algolia will be out of sync for a while.

One solution is to fetch the records from both sources together, but because of Firestore pricing model, it may not be an elegant solution for enormous data. (But I accept this solution if we really need to,)

Another solution is to use a dedicated database other than Firestore, which they are many of them. I'll try experiment on each of them to see if it works.

lemasc commented 1 year ago

User Management

There's now another valid reason to use another database, user management. We need to make an interface to manage users and roles (admin, editors, etc.). The current implementation (using Firebase Auth) allows setting roles in Custom Claims, but it cannot be query or search across multiple users. We need to use a database to index users too.