Realtime Database or Cloud Firestore: A Decision Guide for Your Firebase Data Layer
Choosing between Firebase Realtime Database and Cloud Firestore comes down to data shape, query needs, and billing drivers. This guide compares both and shows how to validate the choice with emulators and a load test.
18 Apr 2026, 13:10 UTC

The decision you're actually making
Firebase offers two client-synced NoSQL databases, and the choice is hard to reverse once your app has users. Realtime Database (RTDB) stores one large JSON tree; Cloud Firestore stores documents in collections. Both support real-time listeners and offline caching, so feature checklists won't settle it. The deciding factors are your data shape, query needs, and how each product bills you.
Short version: default to Firestore for new apps that need flexible queries and growth headroom. Keep RTDB in contention when your workload is simple shared state, presence signals, or very frequent small updates.
Side-by-side comparison
| Factor | Realtime Database | Cloud Firestore |
|---|---|---|
| Data model | Single JSON tree | Documents in collections |
| Querying | Limited; one sort/filter key per query, shallow queries required | Compound filters, range queries, automatic indexing for common predicates |
| Typical fit | Presence, live status, small synchronized state | User profiles, catalogs, feeds, multi-entity apps |
| Scaling posture | Single-instance mindset; sharding is manual | Designed to scale automatically with usage |
| Main billing driver | Data downloaded and stored | Document reads, writes, deletes, storage, egress |
| Security Rules | Cascading rules on tree paths | Rules per document path with functions; not interchangeable with RTDB rules |
Where the trade-offs bite in practice
Denormalization pressure. In RTDB, deep nesting makes partial reads awkward, so teams flatten and duplicate data across paths. That works until an update must touch five locations atomically. Firestore's document model tolerates more structure, and batched writes make multi-document updates cleaner.
Query growth. If your roadmap includes "filter orders by status and date range" or "search products by category and price," Firestore's compound queries handle these directly. In RTDB you'd maintain custom index paths per query shape, which couples your schema to your UI.
Cost surprises run in opposite directions. RTDB charges mostly for bandwidth, so chatty fan-out of tiny payloads is cheap. Firestore charges per document read: a listener on a 500-document collection that re-syncs costs 500 reads per client. A poorly scoped listener or an N+1 fetch pattern in Firestore can dominate your bill, while the same access pattern in RTDB might barely register.
Offline behavior. Both SDKs cache data locally and queue writes while offline. Neither resolves conflicts for you — if two clients edit the same record offline, last-write-wins or your own merge logic applies. Plan conflict rules regardless of which database you pick.
Concrete check: model one real screen both ways
Take a chat-style screen with a message list and a "who's online" indicator — a common mixed workload.
- Firestore version: messages as documents in
rooms/{roomId}/messages, ordered by a timestamp field. Presence is awkward — Firestore has no native disconnect hook, so you pair it with RTDB or Cloud Functions triggers anyway. - RTDB version: messages under
/rooms/{roomId}/messageswith push keys, and presence under/presence/{uid}usingonDisconnect()to clear status when a client drops. That disconnect primitive is a genuine RTDB advantage.
A hybrid is legitimate: Firestore for the durable, queryable data; RTDB for ephemeral presence and typing indicators. Many production apps do exactly this.
Validate before committing
Run both prototypes locally with the Firebase Emulator Suite (requires Node.js and the Firebase CLI, e.g. firebase init emulators, then firebase emulators:start). Emulators let you exercise listeners, offline writes, and Security Rules without billing. Then:
- Script a representative workload — your expected read/write ratio and concurrent listener count — against a small pilot project.
- Record latency and failed operations, then check billed usage in the Firebase console under Usage and Billing.
- Write Security Rules for one sensitive path in each product; the effort difference is often revealing.
Limits, quotas, and pricing change, so re-check the current Firebase pricing page and SDK release notes immediately before implementation rather than relying on any article, including this one.
Limitations of this guide
This reflects well-established behavior of both products as general guidance; it is not a substitute for load-testing your specific access patterns. Neither database guarantees unbounded concurrent connections, and regional availability differs — verify both for your target regions.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.