Tech Interview RoomStudy guides

GCP

How do you choose between Cloud SQL, AlloyDB, Spanner, Firestore, Bigtable and BigQuery?

Advanced · 2 min read · Lesson 5 of 6 in GCP

  • Cloud SQL: managed MySQL, PostgreSQL and SQL Server; regional HA with a standby; read replicas. For typical OLTP relational workloads that fit on one primary.
  • AlloyDB for PostgreSQL: PostgreSQL-compatible with Google's storage layer; higher transactional throughput, fast analytical queries with a columnar engine, faster failover. For demanding PostgreSQL workloads.
  • Spanner: globally distributed relational database with strong consistency, SQL, and horizontal scaling of writes; up to 99.999% availability in multi-region configurations. For relational workloads that outgrow a single primary or need multi-region strong consistency (financial ledgers, global inventory), at higher cost and with schema-design constraints (avoid monotonically increasing primary keys).
  • Firestore: serverless document database with real-time listeners and offline mobile sync; strongly consistent queries. For mobile and web apps and moderate-scale document data.
  • Bigtable: wide-column NoSQL (HBase API) for massive throughput with low latency: time series, IoT, ad tech, personalisation. Access by row key and ranges only.
  • BigQuery: serverless data warehouse for analytics (OLAP) over terabytes to petabytes with SQL; not for transactional workloads.
  • Memorystore: managed Redis/Valkey and Memcached for caching.

Follow-up questions interviewers ask

Try answering each one before you open it.

How does Spanner provide external consistency, and what is TrueTime?

TrueTime is an API backed by GPS receivers and atomic clocks in Google's data centres that returns the current time as an interval with a small bounded uncertainty. Spanner assigns each transaction a commit timestamp and then waits out the uncertainty ("commit wait") before making the commit visible, so if transaction T1 commits before T2 starts, T1's timestamp is guaranteed to be smaller. Combined with Paxos replication, this gives globally consistent reads and writes without a single master clock.

How do you design a Bigtable row key?

Design the key around the main read pattern, because rows are sorted lexicographically by key and reads are by key or key range. Avoid hotspots from monotonically increasing prefixes (timestamps, sequential ids): lead with a high-cardinality field such as device id, then a reversed or bucketed timestamp (device#4711#9999999999-ts) so recent data for a device is contiguous and writes spread across nodes. Keep keys short and use column families for groups of columns read together.