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.
Read the original → docs.cloud.google.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.