Theory
Two databases, one choice
FestConnect Mobile needs to store data in the cloud, events, registrations, and Firebase gives you a choice of two NoSQL databases: the Realtime Database and Cloud Firestore. Both are hosted, both sync in real time, both work offline. But they organise data differently and suit different needs.
Before writing storage code (the next unit), you should know which to pick and why. This lesson compares them so you can choose deliberately. In short: Firestore is the newer, more structured option; the Realtime Database is the older, simpler one.
Theory
How each stores data
The Realtime Database stores your entire app's data as one big JSON tree, a single nested structure of keys and values. It is simple and extremely fast for basic real-time syncing, and it has been around a long time. The downside: as data grows, that one tree can become deeply nested and awkward, and its querying is limited (simple, shallow queries), so complex data is harder to structure and scale.
Cloud Firestore instead organises data into collections of documents (which can hold subcollections), the model you saw on the web side. This structure supports richer queries and scales more flexibly, at the cost of being a little more involved. It is the newer, generally recommended choice.
At a glance
| Aspect | Realtime Database | Cloud Firestore |
|---|---|---|
| Data model | One big JSON tree | Collections of documents (with subcollections) |
| Queries | Simple, limited, shallow | Richer, more powerful |
| Scaling | Less flexible | Scales better |
| Maturity | Older, very low latency | Newer, generally recommended for new apps |
| Both | Real-time sync, offline support | Real-time sync, offline support |
Formula
Which to choose
For most new apps, including structured data like FestConnect's events and registrations, Firestore is the sensible default: its collections-and-documents model and richer queries fit real app data, and it scales well.
Reach for the Realtime Database when your needs are very simple and low-latency, basic data that maps naturally to a JSON tree, or when you are working with an existing project already built on it. Both are good; the decision comes down to how structured your data is and how complex your queries need to be. When unsure, Firestore is the safer modern pick.
Quiz
How does the Firebase Realtime Database store your app's data, compared with Cloud Firestore?
- Both store data as SQL tables with rows and columns
- The Realtime Database stores everything as one large JSON tree, while Firestore organises data into collections of documents
- The Realtime Database uses collections and documents; Firestore uses a JSON tree
- Neither can sync data in real time
Show the answer
The Realtime Database stores everything as one large JSON tree, while Firestore organises data into collections of documents
The Realtime Database stores all data as a single large JSON tree, whereas Cloud Firestore organises data into collections of documents (which can contain subcollections). Option A is wrong: both are NoSQL, neither uses SQL tables with fixed rows and columns. Option C reverses them: it is Firestore that uses collections/documents and the Realtime Database that uses the JSON tree, not the other way round. Option D is false: both databases support real-time syncing (and offline). The core distinction is the data model: one JSON tree (Realtime Database) versus structured collections and documents (Firestore).
Think first
Why does Firestore's collections-and-documents model scale and query better than one JSON tree?
Both are NoSQL and sync in real time. Why is Firestore's structure often better for growing apps? Then tap.
Show the answer
Because Firestore's data is broken into many small, independent DOCUMENTS grouped in collections, which lets you fetch and query exactly what you need, while the Realtime Database's single JSON tree tends to pull in more than you want and offers only shallow queries. In the Realtime Database, everything lives in one nested tree, and queries are limited and largely shallow, so structuring complex data often forces awkward choices, and because the tree is one connected structure, reading part of it can require loading a chunk of nested data you did not need, which wastes bandwidth and slows things as data grows (a problem sometimes called 'fan-out'). Firestore instead stores data as separate documents inside collections: you can query a collection with real filters and ordering, retrieve just the specific documents that match, and page through results, without dragging along unrelated data. Because documents are independent units, Firestore can also distribute and scale them across its infrastructure more flexibly, and its query performance depends on the size of the RESULT set, not the whole dataset, so it stays fast as data grows. Subcollections let you nest related data (an event's registrations) without bloating the parent document. The trade-off is that Firestore is a bit more structured to work with, and the Realtime Database can still win for very simple, ultra-low-latency needs. But for typical growing apps with real queries, Firestore's document model is why it scales and queries better, and why it is the usual default today. Small independent documents beat one giant tree when data and queries grow.
Summary
Key takeaways
- Firebase offers two NoSQL databases: the Realtime Database and Cloud Firestore; both sync in real time and work offline.
- The Realtime Database stores all data as one big JSON tree: simple and very low latency, but limited querying and less flexible scaling.
- Cloud Firestore organises data into collections of documents (with subcollections): richer queries and better scaling.
- Firestore is newer and generally recommended for new apps, especially with structured data.
- Choose Firestore for structured data and complex queries (the usual default); the Realtime Database for very simple, low-latency needs or existing projects.
- Firestore scales and queries better because independent documents let you fetch exactly what you need, unlike one connected JSON tree.
- Memory hook: Realtime Database is one JSON tree, Firestore is collections of documents; Firestore is the modern default.