I've worked with firebase and firestore for 3 years now.
Here's some things you should know to design your database 👇🧵
#firebase #nosql #flutterdev #javascript
Here's some things you should know to design your database 👇🧵
#firebase #nosql #flutterdev #javascript
Firestore is a NOSQL database.
🧐Let’s see what is a NOSQL database.
This means that when in a standard RDBMS (sql database) you prefer to never repeat data, NOSQL is the opposite.
In NOSQL repeating data is not a bad practice.
🧐Let’s see what is a NOSQL database.
This means that when in a standard RDBMS (sql database) you prefer to never repeat data, NOSQL is the opposite.
In NOSQL repeating data is not a bad practice.
Now we understand that firestore is about :
- high availability
- partition tolerance
- bad consistency
- high availability
- partition tolerance
- bad consistency
♟️All is about queries.
While you design your RDBMS with table and relations, try to design your firestore database with the queries you’ll need.
As I said It’s ok to duplicate data.
While you design your RDBMS with table and relations, try to design your firestore database with the queries you’ll need.
As I said It’s ok to duplicate data.
Let’s take an example.
You have a collection containing users informations.
You create a collection storing users's messages like a social feed.
This social post will contain fields:
- user id , user name
- message...
We won’t make a GET to get user name for each messages.
You have a collection containing users informations.
You create a collection storing users's messages like a social feed.
This social post will contain fields:
- user id , user name
- message...
We won’t make a GET to get user name for each messages.
Counter example
You have a collection of buying events.
As you may want to have correct information, it’s ok to do another query to get user informations (for example as the user can update his own infos).
All is about balance between consistency and performance.
You have a collection of buying events.
As you may want to have correct information, it’s ok to do another query to get user informations (for example as the user can update his own infos).
All is about balance between consistency and performance.
Firestore is document database
This means that firestore provides you the ability to create subdocument and create a real hierarchy.
This means that firestore provides you the ability to create subdocument and create a real hierarchy.
Security rules
❌Don’t add user role into a collection
👌 Use the authentication claims.
+ You can access claims directly in security rules
+ user cannot access and update it
❌Don’t add user role into a collection
👌 Use the authentication claims.
+ You can access claims directly in security rules
+ user cannot access and update it
Complex string search
That’s not really where nosql shines... You won’t have that amazing functions that you have in sql (phonetic search, contains...).
👉Don’t have much data in your collection ⇒ retrieve it all and filter it in code.
👉Too much data ⇒ algolia or elastic
That’s not really where nosql shines... You won’t have that amazing functions that you have in sql (phonetic search, contains...).
👉Don’t have much data in your collection ⇒ retrieve it all and filter it in code.
👉Too much data ⇒ algolia or elastic
Here it is
Would have so much more to say about firebase or nosql but this will be for another thread.
Did you learn something here?
Share your experience using firebase and nosql 👇
Would have so much more to say about firebase or nosql but this will be for another thread.
Did you learn something here?
Share your experience using firebase and nosql 👇
@tomlarkworthy You can have a document related to another.
Someone can update or delete one while many are fetching them.
What is the result of this?
Sql has complex locks that ensure that anyone touching their table will wait the end of operation and many other scenario.
Someone can update or delete one while many are fetching them.
What is the result of this?
Sql has complex locks that ensure that anyone touching their table will wait the end of operation and many other scenario.
@tomlarkworthy It can feel consistent on a small app because you don't have that many simultaneous write/reads.
But no. NoSQL is not consistent like a sql database by design.
But no. NoSQL is not consistent like a sql database by design.
جاري تحميل الاقتراحات...