Skip to content
Visual explainer 2h 30m to learn 5 steps

Choose Firestore, Bigtable or Memorystore

Match Firestore, Bigtable and Memorystore to schema, access pattern, consistency, data lifecycle and cost for a given workload.

By Invicly Tech, , in Google Cloud Engineering and Services. About 8 minutes to read.

Topic 15 of 32

In short

Firestore stores documents for apps with flexible, query-by-field data. Bigtable stores huge, sparse tables read by row key at very high rates. Memorystore is an in-memory cache that sits in front of a slower database. Pick by access pattern, not by habit.

Think of it like this: Firestore is a filing cabinet of folders, Bigtable is a giant ledger you read by page number, and Memorystore is the sticky note on your monitor.

Explained simply

Not every workload fits tables and SQL. Google Cloud has other stores built for particular shapes of data and access. Choosing well starts with one question: how will this data be read?

Firestore stores documents, which are bundles of fields kept under an ID. It suits app data such as user profiles and carts, where screens read a few documents at a time. Queries are fast because they use indexes that Firestore keeps for you.

Bigtable is for very large amounts of data read by key, such as sensor readings or click streams. You can only look things up by row key, so the key design is the whole design.

Memorystore is a cache that keeps copies of popular data in memory so reads are quick. If it loses data, the app reads again from the real database. That is why every cached item gets a time limit, called a TTL.

Press Play on a diagram to walk through it one step at a time.

CompareThree non-relational tools
Firestore
  • Documents in collections
  • Queries use indexes
  • Strongly consistent reads
  • Billed by reads, writes and storage
Bigtable
  • Wide-column, row key only
  • Single-digit millisecond at scale
  • Needs a careful key design
  • Billed by nodes and storage
Memorystore
  • In memory, very fast
  • Data can be rebuilt from source
  • Redis or Valkey engines
  • Billed by memory size
SequenceCache-aside read with a TTL
App
Memorystore
Database
  1. 1Get order:42
    App to Memorystore: Get order:42
  2. 2Miss
    Memorystore to App: Miss
  3. 3Read order 42
    App to Database: Read order 42
  4. 4Row returned
    Database to App: Row returned
  5. 5Set order:42 with 300 second TTL
    App to Memorystore: Set order:42 with 300 second TTL
MapA decision path for a new workload
How is the data read?
  • Documents by ID or filter, small to medium scale
    • Firestore
  • Huge volume by row key or time range
    • Bigtable
  • Same answers read again and again
    • Memorystore in front of a database
  • Joins and transactions across tables
    • Cloud SQL, AlloyDB or Spanner

In depth

Modelling documents in Firestore

Design documents around the questions your screens ask. A document can hold nested fields and small lists. Collections group documents, and a document can have subcollections. Reading one document is cheap and fast; joining across many is not, so copy a small amount of data into the place it is read.

Firestore creates single-field indexes automatically. Queries that filter or sort on several fields need composite indexes, which the error message tells you how to create. Document size is limited to about 1 MiB, and one document should not be updated at a very high rate.

  • Model for the read, not for tidiness
  • Add composite indexes when a query asks
  • Keep documents small
  • Use the local emulator for development

Designing Bigtable row keys

Bigtable stores rows sorted by key and spreads ranges of keys across nodes. Reads by key or key range are very fast. If every new key starts with the current time, all writes go to the last range, one node, and that node becomes a hotspot.

A better key starts with something that varies, such as a device ID, then adds time. Related rows sit together, so a range scan gets one device's recent data. Bigtable guarantees atomic changes to one row only, so keep related data in one row.

MapA row key built from parts
device-17#reverse-time
  • Device ID
    • spreads writes across nodes
  • Reverse timestamp
    • newest rows sort first
  • Column families
    • readings
    • status

Caching, TTLs and cost

Memorystore offers managed Redis-compatible and Valkey engines; check the console for what is available in your region. The usual pattern is cache-aside: read the cache, on a miss read the database and store the result with a TTL.

Data lifecycle differs by store. Firestore can expire documents with a TTL policy on a timestamp field, and deletion is not instant. Bigtable uses garbage collection rules on column families by age or number of versions.

Costs follow different meters: Firestore charges per operation, Bigtable per node hour, and Memorystore per memory provisioned.

Learn it in 5 short steps

About 30m each. Track them with a timer in your plan.

  1. 1
    Model documents in Firestore~30m
  2. 2
    Design Bigtable row keys~30m
  3. 3
    Cache reads with Memorystore~30m
  4. 4
    Set TTLs and data lifecycle~30m
  5. 5
    Compare cost drivers~30m

Key points

  • Firestore suits user-facing app data. Model documents around the screens that read them, and expect to add composite indexes.
  • Bigtable has one index: the row key, sorted in order. Avoid keys that start with a timestamp, which sends all writes to one node.
  • A cache holds copies, never the only copy. Set a time to live (TTL) so stale values expire.
  • Firestore has TTL policies on a timestamp field. Bigtable uses garbage collection rules by age or version count.
  • Cost drivers differ: operations for Firestore, node hours for Bigtable, provisioned memory for Memorystore.

Key terms

Tap a card to flip it. 0/5 known

Examples

text
Bad:   20261202T101500#device-17
Good:  device-17#20261202T101500

Better for newest-first reads:
       device-17#<reverse-timestamp>

Device IDs spread the writes; the suffix keeps one
device's readings together for a range scan.

Bigtable row keys for sensor readings. Lead with the device, not the time.

Cache-aside with a local Redis

Prerequisite: Docker. This models Memorystore with a local Redis container. Set a value with a 60 second TTL, read it, and watch it expire. Cleanup: stopping the container removes it.

bash
docker run --rm -d --name cache -p 6379:6379 redis:7
docker exec cache redis-cli SET order:42 '{"total":19.99}' EX 60
docker exec cache redis-cli TTL order:42
docker exec cache redis-cli GET order:42
# after 60 seconds the GET returns nothing
docker stop cache

Firestore emulator for development

Prerequisite: gcloud with the emulator component. The emulator runs locally, needs no billing and discards data on exit. Evidence: your app connects without any credentials. It does not copy every production limit or security rule behaviour exactly.

bash
gcloud emulators firestore start --host-port=127.0.0.1:8080
# in another terminal
export FIRESTORE_EMULATOR_HOST=127.0.0.1:8080
python app.py

Quick reference

  • Firestore: documents, automatic single-field indexes, composite on request.
  • Bigtable: one index, the row key. Avoid timestamp-first keys.
  • Bigtable atomicity is per row only.
  • Memorystore is a cache: set a TTL, keep the truth elsewhere.
  • Firestore cost: operations. Bigtable: nodes. Memorystore: memory.
  • Firestore TTL policies delete expired documents with some delay.

Common mistakes

  • Using Bigtable for a few gigabytes of data. A node costs money all day; Firestore or SQL is usually cheaper.
  • Caching without a TTL or an invalidation plan, so users see old data.
  • Reading many Firestore documents on every page load, then being surprised by the bill.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which store is best for a user profile document read by ID?

Question 2

2Why avoid a Bigtable key that starts with a timestamp?

Question 3

3What should every cached value have?

Question 4

4A workload needs joins and multi-table transactions. What do you pick?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Using the local Redis model, store a value with a 30 second TTL and confirm it counts down.

  2. Exercise 2medium

    Design a Bigtable row key for delivery events where you mostly read the last hour of one courier.

  3. Exercise 3hard

    Plan the data stores for a shop: carts, product catalogue reads, order history and clickstream. Justify each choice.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Is Firestore the same as Firebase?
Firestore is a database you can use from Firebase apps or from Google Cloud directly. Firebase is the wider toolkit.
When is Bigtable too much?
When the data is small or you need joins. A Bigtable cluster bills for nodes all day, so use it only for large, key-based workloads.
Does a cache make data inconsistent?
It can serve slightly old values. A short TTL or deleting the key on update keeps it close to the database.

Go deeper

ShareXLinkedInWhatsApp