Firestore — Serverless NoSQL document database
A real-time NoSQL database with offline sync, live listeners, and granular security rules. Ideal for mobile/web apps that want live updates without building a backend.
Firestore is a serverless NoSQL document database with two modes (set at project creation, immutable): Native mode (real-time listeners, offline sync, mobile/web SDKs, security rules — the default) and Datastore mode (legacy compatibility with the old Cloud Datastore, no realtime). For any new app: Native mode.
Data model: documents (up to 1 MiB, JSON-like, typed fields) inside collections (top-level or nested as subcollections under a document). Documents have implicit indexes on every field; composite indexes (multi-field sort/filter) must be declared — Firestore returns a console link on the first failed query to auto-create one.
Querying: filter + orderBy + limit expressions evaluated by indexes only (no full-collection scans), returning paginated results. No SQL joins — model relationships by denormalizing, storing IDs + redundant data, or querying in parallel from the client. Collection-group queries span all subcollections with the same name across the database.
Real-time listeners: .onSnapshot() / watch() streams incremental updates (added/modified/removed) over HTTP/2. Scales to millions of concurrent listeners; pricing adds per-document-read on each change. Latency-optimized for a few thousand listeners per query — shard hot collections for higher fan-out.
Transactions & batched writes: atomic read-then-write on up to 500 docs, with optimistic concurrency (retry on contention). Good for small aggregates (incrementing counters, transferring between two docs) but not for cross-document SQL-style transactions over large sets.
Security Rules: a domain-specific language evaluated on every client request, with access to auth context, requested path, resource data before/after, and request.time. Deploy via firebase CLI. Combined with (attestation that the request comes from a legitimate app), this replaces a traditional API tier for many use cases.
Pricing: per-document-read ($0.06/100k in Native mode, per-100k discount as volume grows), per-document-write ($0.18/100k), per-document-delete ($0.02/100k), per-GB stored ($0.18/month). No idle charges. Cost shapes the data model — denormalize writes carefully.
Grounded on https://cloud.google.com/firestore/docs