Comparison
Spanner vs DynamoDB: Global SQL or Predictable Key-Value
By Ankur NayakReviewed
Google Spanner and Amazon DynamoDB are both sharded databases in which every shard is a replicated consensus group, and both are described in detail by their builders: Spanner in its 2012 OSDI paper and DynamoDB in a 2022 USENIX ATC paper.
They are built for different promises. Spanner offers relational tables and externally consistent transactions across shards and continents, paying for it with synchronized clocks and commit wait. DynamoDB offers a key-value and document API whose every operation has bounded, predictable latency, and puts its engineering into multi-tenant isolation and fast healing.
Google Spanner
Full designAmazon DynamoDB
Full designSide by side
| Dimension | Google Spanner | Amazon DynamoDB |
|---|---|---|
| Data model | Schematized semi-relational tables with SQL queries | Items addressed by partition key (and optional sort key); limited queries |
| Shard replication | A Paxos group per tablet, replicas placed by policy across zones and regions | A Multi-Paxos replication group per partition across three Availability Zones |
| Leaders | Long-lived Paxos leaders with 10-second leases; leaders hold the lock table | One leader per partition, kept by renewing a lease; serves writes and strong reads |
| Multi-shard transactions | Two-phase commit between Paxos group leaders, with a TrueTime commit timestamp | Offered as a separate feature; the core path is single-partition operations |
| Consistency | External consistency (linearizable) for transactions; lock-free snapshot reads at any timestamp | Strongly consistent reads from the leader or cheaper eventually consistent reads from any replica |
| Clocks | TrueTime: GPS and atomic-clock masters bound uncertainty to ~1–7 ms | No special clock hardware is part of the design described |
| Multi-tenancy | Placement driver moves directories to balance load and meet constraints | Token buckets at request routers refilled by global admission control; partitions split by consumption |
| Failure healing | New leader elected when a lease expires; data moved by the placement driver in minutes | Log replicas added in seconds while full replicas are rebuilt; autoadmin replaces unhealthy nodes |
| Scale (latest public) | Designed for millions of machines and trillions of rows (2012) | 89.2M requests per second peak on Prime Day 2021 |
Verdict
Choose a Spanner-style design when the data is relational and correctness across shards and regions matters more than the last millisecond: banking ledgers, inventory, ad budgets. Choose a DynamoDB-style design when access patterns are known, operations are by key, and the priority is predictable latency for many tenants at any scale. In an interview, name the promise first (global transactions or bounded latency) and let it pick the architecture.
Frequently asked questions
Is DynamoDB like Spanner?
Partly. Both split data into shards that are each replicated with a Paxos-style consensus protocol and a leader. Spanner adds relational tables, cross-shard two-phase commit and TrueTime timestamps for global consistency, while DynamoDB keeps a simpler key-value model focused on predictable latency and tenant isolation.
Why does Spanner need atomic clocks and DynamoDB doesn't?
Spanner promises that transactions are ordered consistently with real time across the whole planet, so it needs bounded clock uncertainty to assign commit timestamps. DynamoDB's core operations are single-partition, where the partition's leader orders writes, so no global clock is required.
Which is faster, Spanner or DynamoDB?
They optimise different things. DynamoDB's single-key operations are built for consistently low, single-digit-millisecond latency. Spanner's read-write transactions pay for consensus, two-phase commit across groups and commit wait, but its snapshot reads can be served lock-free from nearby replicas.
More comparisons
- Discord vs Slack: Two Ways to Build Real-Time Chat
- Netflix vs Uber: Streaming Bytes vs Real-time State
- News Feed vs Notification Service: Two Kinds of Fan-out
- Stripe vs Adyen: Two Ways to Never Lose a Payment
- WhatsApp vs Slack/Discord-style Chat: Architecture Compared
- YouTube vs Twitch: On-Demand Video vs Live Streaming