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.
Loading suggestions...