Skip to main content

Database Selection

Docs: Choose a database

Key Terms​

TermDefinition
OLTP (Online Transaction Processing)Short, frequent read/write transactions (inserts, updates, deletes). Optimised for high concurrency and low latency per query. Examples: booking a seat, placing an order.
OLAP (Online Analytical Processing)Complex queries over large datasets, typically aggregations and full-table scans. Optimised for throughput over concurrency. Examples: monthly revenue reports, cohort analysis.
HTAP (Hybrid Transactional/Analytical Processing)Single system that handles both OLTP and OLAP workloads on live data, eliminating the need for a separate ETL pipeline to a data warehouse.
DWH (Data Warehouse)A store optimised for analytical queries over historical data, usually loaded via batch ETL. BigQuery is GCP's managed DWH.
Strong consistencyA read always reflects the most recent committed write, regardless of which replica serves it. Spanner guarantees this globally via TrueTime.
Eventual consistencyReplicas converge to the same state over time, but a read may briefly return stale data. Common in distributed NoSQL systems.
Horizontal scalingAdding more nodes to increase capacity. Spanner and Bigtable scale horizontally without downtime.
Vertical scalingIncreasing the CPU/RAM of a single node. Cloud SQL scales vertically (with a brief restart).
Row key (Bigtable)The only index in Bigtable; all reads and writes are keyed by it. Poor key design causes hotspots that bottleneck throughput.

Options at a Glance​

ServiceTypeBest For
Cloud SQLManaged relational (MySQL, Postgres, SQL Server)Standard OLTP, regional, < ~64TB
AlloyDBManaged Postgres-compatibleHigh-performance OLTP + analytics on Postgres
Cloud SpannerDistributed relational (proprietary)Global OLTP, strong consistency, horizontal scale
Cloud BigtableNoSQL wide-columnHigh-throughput time-series, IoT, sub-10ms reads at petabyte scale
FirestoreNoSQL documentMobile/web apps, real-time sync, hierarchical data
Spanner GraphGraph + relationalFraud detection, knowledge graphs, relationship traversal
BigQueryServerless analytics DWHSQL analytics, ML, not for OLTP
Memorystore (Redis / Valkey)In-memory cacheSession data, leaderboards, rate limiting, sub-ms reads

Decision Guide​

"Relational database, single region, standard workload" β†’ Cloud SQL. Drop-in replacement for MySQL/Postgres/SQL Server. Supports read replicas and cross-region replicas for DR.

"High-performance Postgres with built-in HTAP (analytics on live data)" β†’ AlloyDB. Up to 4Γ— faster than Cloud SQL for OLTP, with a columnar engine for analytics queries on the same data. Choose AlloyDB over Cloud SQL when performance or mixed OLTP/analytics is the key requirement.

"Global relational database with strong consistency and horizontal scale" β†’ Cloud Spanner. The answer when the exam says global, multi-region, or strongly consistent at scale. Expensive β€” don't recommend it for single-region workloads.

"High-throughput writes and reads on time-series / IoT sensor data" β†’ Cloud Bigtable. Designed for billions of rows with consistent sub-10ms latency. Schema design matters β€” rows are keyed by a single row key; design it to avoid hotspots.

"Mobile or web app that needs real-time data sync" β†’ Firestore. Offline support, real-time listeners, and a document model suit client-side apps well.

"Graph relationships (fraud detection, knowledge graphs)" β†’ Spanner Graph. Built on top of Spanner, so you get both graph traversal and strong relational consistency in one system.

"Analytical queries over large historical datasets" β†’ BigQuery. Not an OLTP database β€” no row-level transactions. Optimised for full-table scans and aggregations.

"Reduce database load for frequently read data (sessions, cart, counters)" β†’ Memorystore (Redis). Sub-millisecond reads from memory. Use it as a cache in front of Cloud SQL or Spanner, not as primary storage.

Cloud SQL vs Cloud Spanner β€” When to Choose​

FactorCloud SQLCloud Spanner
ConsistencyStrong (single-region)Strong (globally)
ScaleVertical + read replicasHorizontal (automatic)
RegionsSingle primary regionMulti-region natively
CostLowerSignificantly higher
Use whenStandard app DBGlobal app, can't accept regional failover lag

Bigtable Row Key Design​

Bigtable performance depends entirely on row key design. Common patterns:

  • Reverse domain (com.example.user) β€” avoids hotspots
  • Salted prefix β€” distribute writes across tablets
  • Avoid monotonically increasing keys (timestamps as-is) β€” causes write hotspots on the last tablet

See: Bigtable schema design best practices

Official Documentation​