Understanding Cloud Firestore: A Modern NoSQL Database

When developing, choosing the right database is crucial. Cloud Firestore, a NoSQL database from Google's Firebase suite, stands out for its integration capabilities with mobile, web, and server applications. What makes Firestore unique is its real-time listeners and offline support, ensuring data synchronization and low-latency operations, even in environments with limited internet connectivity.
Cloud Firestore vs. Realtime Database: A Comparative Overview
cloud firestore
- Intuitive Data Model: Firestore leverages a document and collection model, simplifying data management.
- Advanced Querying: Supports complex queries and efficient sorting mechanisms, tailored for faster, more effective data retrieval.
- Scalability: Built for larger scales, offering superior scalability over the Realtime Database.
- Offline Support: Functional offline data support for Android, iOS, and web clients.
- Reliability and Performance: Data is distributed across multiple data centers, ensuring top-notch reliability and performance.
- Flexible Security Rules: Non-cascading rules provide a combination of authorisation and validation.
- Pricing Model: Charges are primarily based on operations like read, write, and delete, with lower rates for bandwidth and storage.
Realtime database:
- Simple Data Model: Utilizes a JSON tree structure, which is straightforward but less flexible compared to Firestore.
- Basic Querying: Offers deep queries but with limited sorting and filtering options
- Offline Support: Available for Android and iOS mobile clients.
- Zonal Availability: Limited to specific zones, offering extremely low latency.
- Pricing: Costs are incurred based on bandwidth and storage, typically higher than Firestore.
- Cascading Security Rules: Separates the concepts of authorization and validation for enhanced security.
On the other hand, both databases offer client-first SDKs, real-time updates and a free tier for initial use.
Data Model

Unlike traditional SQL databases, Cloud Firestore is a document-oriented database, meaning no rows or columns. Data is stored in documents, which are organised into collections.
Documents
As per the documentation, documents is a unit of storage and it consists of lightweight records that contains fields.
Collections
Collections are organised in documents.
To understand collections better, let's take the example of users.

Users can be thought of as a collection. Inside of the collection, there could be various users, represented as documents. Each of these documents will consists of objects, storing user data in the form of key-value pairs.
References
Each document is uniquely identified in the Firestore in terms of its reference. Collection as well may be reference.
Reference a document:
final user1DocumentReference = db.collection("users").doc("user1");
Reference a collection:
final userCollectionReference = db.collection("users")
Wrapping Up
Cloud Firestore's capabilities in real-time data syncing, scalability, and offline support make it a formidable choice for modern application development. Its flexible and intuitive data model caters to a wide range of use cases, from simple to complex, ensuring developers have the tools they need to build efficient and reliable applications.
About Me
I am Zaahra, a Google Women Techmakers Ambassador who enjoy mentoring people and writing about technical contents that might help people in their developer journey. I also enjoy building stuffs to solve real life problems.
To reach me:
LinkedIn: https://www.linkedin.com/in/faatimah-iz-zaahra-m-0670881a1/
X (previously Twitter): _fz3hra
GitHub: https://github.com/fz3hra
Cheers,
Umme Faatimah-Iz-Zaahra Mujore | Google Women TechMakers Ambassador | Software Engineer