Google Cloud Spanner: A Globally Distributed SQL Database
Spanner is a globally distributed SQL database that scales like NoSQL but keeps the strong consistency of a relational database. Use it for global applications like financial ledgers that need ACID transactions across continents.
Why it exists
Traditional databases force a choice: scale horizontally with NoSQL and accept eventual consistency, or get strong ACID guarantees with a relational database that's hard to scale globally. Spanner was created to eliminate this trade-off, offering both horizontal scalability and strong external consistency for planet-scale applications.
The mental model
Imagine a single PostgreSQL database instance, but one that is secretly spread across data centers on multiple continents. You interact with it using standard SQL, but it can handle massive traffic and survive regional outages without data loss or inconsistency. It's a relational database that inherited the scaling superpowers of a NoSQL system.
How it works
Spanner achieves this through two core technologies. First, it uses a consensus algorithm (a variant of Paxos) to replicate data and agree on changes across multiple locations, ensuring durability. Second, and most critically, it uses Google's TrueTime API. This service provides highly accurate, synchronized timestamps from atomic clocks, allowing Spanner to correctly order transactions across the globe and provide external consistency—a guarantee stronger than standard serializability.
When to use it
Use Spanner for applications that are global in nature and require uncompromising data integrity. Prime candidates include financial trading platforms, global inventory management systems, and large-scale booking systems where double-booking would be catastrophic. It's for when you need a single source of truth for a global user base. Its support for PostgreSQL and Cassandra interfaces also makes it a target for modernizing legacy systems.
When not to use it
Avoid Spanner for small, single-region applications, as it's expensive overkill. It's also a poor fit for workloads that are extremely sensitive to write latency and don't require global consistency; a standard regional database will be faster and cheaper. If your application can tolerate eventual consistency, a simpler NoSQL database is often more cost-effective.
One canonical example
A global airline's booking system must process reservations from users worldwide and guarantee that a seat is never sold twice. With Spanner, a transaction to book seat 7A on a flight from LHR to JFK can be processed with full ACID guarantees. Even if agents in London and New York try to book it simultaneously, only one transaction succeeds, and the result is instantly visible and consistent to all other agents globally.
Interview question
What unique technological component primarily enables Google Cloud Spanner to provide strong external consistency across globally distributed transactions?
- a.Its ability to process standard SQL queries with traditional ACID properties.
- b.A sophisticated sharding mechanism that partitions data across continents.
- c.An advanced variant of the Paxos consensus algorithm for data replication.
- d.Google's TrueTime API, leveraging atomic clocks for synchronized timestamps.Correct
Why? this is the answer
The card states that TrueTime API is "most critically" used to provide external consistency by correctly ordering transactions across the globe. While Paxos ensures data replication and agreement, TrueTime's synchronized timestamps are fundamental to Spanner's unique global consistency guarantee.
Just read this? Test yourself on what you have been reading.
Read the original → docs.cloud.google.com
- #databases
- #cloud
- #distributed systems
- #google cloud
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on databases — each one lists the topics its interview covers.
See open roles