Exam objective 1.3 asks you to explain Cloud Spanner’s architecture, including how it achieves global distribution, strong consistency, and horizontal scaling. For someone studying for the Google Professional Cloud Database Engineer (PCDE) exam, this is crucial because Spanner is Google Cloud’s flagship database for globally distributed applications that require both massive scale and absolute data accuracy. Understanding why Spanner is special helps you answer questions about trade-offs between availability, consistency, and latency in real-world systems.
Jump to a section
A simple way to picture Cloud Spanner Architecture: Global Scale and Strong Consistency
A restaurant chain’s head chef coordinates every location to serve the exact same dish at the same time, anywhere in the world.
Imagine you run a global chain of busy restaurants in London, New York, Tokyo, and Sydney. Your signature dish is a special truffle pasta. To keep customers happy, a customer in Sydney must taste the exact same pasta as a customer in London — no variation, no delays, and no contradictions on the menu. You need every restaurant to see the same recipe, the same ingredient stock, and the same special offers at exactly the same moment. If a London chef adds truffle oil to the sauce, a Sydney chef must know about that change instantly, even if there’s a 10-hour time difference and a half-second network lag.
Now, here’s the trick: you can’t just have one single recipe book locked in a London safe, because that would make Sydney wait too long. Instead, you put a copy of the recipe book in each city, but you design a magical system that updates every copy simultaneously. When a chef in Tokyo updates the stock count, that change is written everywhere at once. Every chef sees the same numbers, reads the same ingredients, and can serve the dish without ever getting confused about what’s true. That’s what Cloud Spanner does for data. It lets businesses store database copies in multiple regions around the globe, and every copy stays perfectly in sync with strong consistency — as if there were only one single source of truth, no matter where the data is read or written.
Cloud Spanner is a fully managed, globally distributed database service from Google Cloud. It combines the benefits of a traditional relational database (like the ones that power bank accounts or inventory systems) with the ability to scale out across many servers and many geographic regions. To understand why this matters, you need to know a few fundamental concepts.
First, a database is a place where an application stores structured data — think of it like a giant, organised spreadsheet with rows and columns. A relational database uses strict rules (schemas) to ensure data integrity, meaning the data is always correct and consistent. For decades, most relational databases were single-server: one machine stored all the data. That was fine for small businesses, but a global online shop serving customers in dozens of countries would face huge problems: the single server would be too slow, and if it broke, the entire shop would go offline.
To solve these problems, engineers built distributed databases. A distributed database spreads data across many servers (horizontal scaling) and often across multiple data centres. But distributing data introduces a classic conflict: the CAP theorem. CAP stands for Consistency (everyone sees the same data at the same time), Availability (the database stays up even if some servers fail), and Partition Tolerance (the system keeps working even if network connections between servers are cut). The theorem says you can only have two out of three. Most distributed databases sacrifice strong consistency to keep availability and partition tolerance. They use a model called eventual consistency, meaning updates take time to spread — during that time, different users might see different versions of the same data. For a bank transfer or a flight booking system, eventual consistency is unacceptable. If you check your balance and see $100, then your partner sees the same $100 and both of you withdraw $100, the bank could lose money.
Cloud Spanner breaks the CAP trade-off by using Google’s global network and a technology called TrueTime. TrueTime is a service that gives every Spanner server a very accurate, synchronised clock using GPS and atomic clocks in Google’s data centres. This synchronised clock allows Spanner to order all writes (data changes) globally with extremely high precision. When a write happens, Spanner assigns it a timestamp. To read data, Spanner uses the timestamps to ensure that every read sees the most recent write — even if the reader is in a different region. This is why Spanner offers strong consistency across the entire globe. Strong consistency means that once a write is acknowledged, any subsequent read from any location will see that write, as if there were only one copy of the data.
How does horizontal scaling work in Spanner? Instead of one server, Spanner splits data into small units called splits. Each split is a range of rows. Spanner automatically distributes these splits across thousands of servers in many regions. If a region experiences a spike in traffic, Spanner can split a hot split into smaller ones or move splits to less loaded servers. This all happens without downtime. You don’t need to manually add more servers — Spanner just uses more of Google Cloud’s infrastructure as needed.
For global distribution, Spanner uses a concept called multi-region configurations. A multi-region configuration is a set of geographic regions where Spanner keeps copies of your data. For example, you can configure a Spanner instance to have replicas in London, Frankfurt, and Zurich. Each replica stores a full copy of the data. Writes are replicated synchronously across the replicas before being acknowledged to the user. This means a write is only considered successful when all replicas in the configuration have it. That’s why strong consistency is possible: every copy is always up to date. However, this also adds latency because the write must travel across continents before it’s confirmed. To reduce latency for reads, Spanner supports read-only replicas that can serve reads from a nearby copy without waiting for the full write confirmation.
The key benefits are:
Strong consistency globally: All users see the same data at the same time, no matter where they are.
Horizontal scalability: You can grow from gigabytes to petabytes by adding more servers, and Spanner manages the distribution automatically.
High availability: With data replicated across multiple regions, the database can survive entire data centre failures without losing data or going offline.
Relational features: You still get SQL queries, schema constraints (like foreign keys and unique indexes), and transactions (a group of operations that must all succeed or all fail together).
In summary, Cloud Spanner is a relational database that behaves like a single machine for consistency but scales like a web-scale distributed system. It replaces the need to build complex custom database infrastructure that tries to keep multiple copies in sync, which is error-prone and expensive to maintain. For the PCDE exam, you need to understand that Spanner’s architecture is built around synchronised clocks, automatic splitting, and synchronous replication to deliver strong consistency at a global scale.
Create a Spanner Instance
You start by creating a Spanner instance via the Google Cloud Console, the gcloud command-line tool, or an API. You assign it a name, choose a compute capacity (number of nodes or processing units), and select a regional or multi-region configuration. This instance is the container for your databases.
Choose a Multi-Region Configuration
This step determines where your data is physically stored. A multi-region configuration (e.g., `nam3` for the US or `global` for worldwide) defines a set of geographic regions that hold replicas. Each replica is a full copy of the data. This decision affects read/write latency and availability. For example, choosing a configuration with replicas in Europe, Asia, and North America means writes must be confirmed in all three before success.
Define the Database Schema
You create tables and indexes using GoogleSQL or PostgreSQL-compatible DDL. You define primary keys carefully: ideally a composite key that distributes writes evenly. You might also create interleaved tables to store child rows alongside parent rows for faster joins. This step directly affects query performance and write distribution.
Write Data with Transactions
Applications send transactions to Spanner. Each write operation (INSERT, UPDATE, DELETE) is executed inside a transaction. Spanner uses TrueTime to assign a commit timestamp. The transaction is only committed after a quorum of replicas (determined by the Paxos protocol) acknowledge the write. This ensures strong consistency: once the transaction returns success, all future reads from any replica see the new data.
Read Data with Stale or Strong Reads
Spanner offers two read modes: strong reads (read the latest committed data) and stale reads (read data from a point in the past, within a staleness bound). For strong reads, Spanner must contact the leader replica to get the most recent timestamp, which can be slower. Stale reads can be served by any read-only replica and are faster, but they may return slightly old data. The application chooses the mode per query.
Monitor and Tune
You use Cloud Monitoring and Spanner’s built-in tools to track key metrics like CPU utilisation, latency, and split hotspot indicators. If hot spots occur, you may adjust primary keys or manually split a range of rows. You also set up alerts for when the instance is approaching capacity so you can add more nodes or processing units proactively.
Backup and Restore
Spanner supports creating database backups that are globally consistent. You can schedule backups using the Console or a cron job. When restoring, you create a new database from the backup. Because backups are consistent, you can restore to any point in time within the backup window.
As a database engineer working for a fast-growing e-commerce company, you are responsible for the product catalogue service. The company has offices in London, New York, Tokyo, and Sydney, and customers worldwide expect to see the same prices, stock levels, and product details no matter which region they connect to. Previously, the company used a single database in London with read replicas in other regions. The problem was that when a price changed in London, customers in Tokyo might see the old price for up to five minutes, leading to incorrect orders and support tickets. The business cannot afford that.
You decide to migrate the product catalogue to Cloud Spanner. Here is what you do step by step:
1. You go to the Google Cloud Console and create a new Spanner instance. You choose a multi-region configuration called nam3 that spans three regions in the United States: us-central1 (Iowa), us-east1 (South Carolina), and us-west1 (Oregon). For your global use case, however, you would pick a configuration like global which includes replicas in North America, Europe, and Asia. You configure the number of read-write replicas (regions that can serve both reads and writes) and read-only replicas (regions that only serve reads, which are cheaper and faster for reading but cannot handle writes).
2. You define the database schema. The catalogue has a table called Products with columns like ProductID, Name, Description, Price, StockQuantity. You define a primary key on ProductID. Spanner uses the primary key to distribute rows across splits. You also choose an interleaved table for product reviews: each review row belongs to exactly one product, and they are stored together physically so queries for a product and its reviews are very fast.
3. You write a script to export the existing product data from the old database and import it into Spanner using the Dataflow service (a managed data processing tool). The migration runs overnight with a short maintenance window.
4. After the migration, you update the application’s connection string to point to the Spanner instance. Because Spanner offers strong consistency, you can remove all the custom code that previously tried to handle eventual consistency — for example, polling multiple replicas and comparing timestamps. The application code becomes simpler and less error-prone.
5. You monitor the system using Cloud Monitoring (formerly Stackdriver). You set up alerts for high read latency or write latency. You notice that during a flash sale in Tokyo, the Spanner instance’s split serving the most popular products becomes a hot spot (a split receiving many requests). You learn about Spanner’s automatic split management: it will eventually split the hot split into smaller ones, but you can also use a command to manually split a range of rows to distribute the load more evenly. You decide to let the automatic process handle it for now.
As an IT professional, your day-to-day tasks involve:
Designing schemas that take advantage of interleaving and proper primary key choices to maximise performance.
Choosing the right multi-region configuration based on where your users are and how critical write latency is.
Monitoring and troubleshooting performance issues using Cloud Monitoring and Spanner’s built-in transaction statistics.
Planning capacity by estimating the number of nodes or processing units needed based on QPS (queries per second) and data size.
Using Spanner’s interface to run backup and restore operations, which are also globally consistent.
The main productivity gain is that you no longer need to manage database replication, failover, or conflict resolution. Spanner handles all that under the hood. You focus on the data model and query performance, not on infrastructure.
The PCDE exam tests your understanding of Cloud Spanner’s architecture through a mix of scenario-based multiple-choice questions and, occasionally, conceptual explanations. Here are the specific things you must know cold.
First, the exam loves to ask about the CAP theorem and Spanner’s place in it. A typical question might describe a system that needs both strong consistency and high availability across regions, then ask which database service to choose. The correct answer is Cloud Spanner because it provides both consistency and availability while still handling partition tolerance (the P in CAP). The trap answer is often a Cassandra or Bigtable-like database, which offers eventual consistency. The key memorisation point: Spanner uses TrueTime to achieve strong consistency without sacrificing availability.
Second, exam questions frequently focus on TrueTime. Expect a question that asks how Spanner orders writes globally. The answer: TrueTime gives each server a globally synchronised clock with bounded uncertainty. Spanner uses timestamps from TrueTime to assign a commit order to all writes, so every server agrees on the order of events. The trap is that some students think Spanner uses a central coordinator or a global lock — it does not. TrueTime is the mechanism.
Third, the exam tests the difference between read-write replicas, read-only replicas, and witness replicas. A read-write replica can accept both reads and writes. A read-only replica can only serve reads, which reduces write latency because the write doesn’t have to be confirmed there. A witness replica participates in the voting for write commits but does not store data. The exam may present a scenario where you need to reduce read latency for a remote region — you would add a read-only replica.
Fourth, you must understand Spanner’s automatic split management. The exam might ask: for a table that experiences a ‘hotspot’ (a split receiving many writes), what does Spanner do? The answer is it automatically splits the range into smaller splits and distributes them across servers. The trap is that some answers suggest manual sharding or adding more nodes manually — Spanner does that automatically.
Fifth, the exam covers interleaved tables. An interleaved table stores child rows physically next to parent rows. This improves join performance. A question might ask how to design a schema for products and orders for low-latency queries. The correct answer is to use an interleaved table with a parent-child relationship. The trap is suggesting a separate non-interleaved table.
Other critical concepts that appear:
The difference between Spanner and Bigtable: Spanner is relational with strong consistency and SQL; Bigtable is a NoSQL wide-column database with eventual consistency.
The role of splits and how they relate to primary key design: a monotonically increasing primary key (like a timestamp) can cause all writes to go to the same split, creating a hotspot. You must design keys to spread writes across splits (e.g., using a hash prefix or a random ID).
The use of database ddl (data definition language) statements for schema changes: you can only add or drop columns if they are in the last table position or you use a specific set of rules.
How Spanner handles resharding automatically: it’s a key benefit over traditional databases.
Finally, be aware of what Spanner does not do. Spanner does not support unlimited data for a single split — you must design primary keys to avoid hot spots. Spanner does not automatically reduce node count when load decreases — you must scale down manually or use autoscaling (available for processing-unit-based instances). And Spanner does not support cross-database transactions natively — you cannot run a transaction across two different Spanner instances.
The correct answer pattern for Spanner questions: if the scenario demands strong consistency, global scale, and SQL, the answer is almost always Spanner. If the scenario demands high throughput for simple key-value lookups with relaxed consistency, the answer is probably Bigtable. If the scenario demands a fully managed, relational database for a single region with strong transactions, the answer is Cloud SQL. If the scenario demands a serverless, auto-scaling relational database with strong consistency for moderate global use, the answer is Spanner.
Cloud Spanner uses TrueTime, a globally synchronised clock service, to order all writes and provide strong consistency across any distance.
Spanner automatically manages data splits and reshards them across servers, so you do not need to manually shard your database.
Write latency in Spanner is higher than in single-region databases because every write must be replicated synchronously to a quorum of replicas before being accepted.
To avoid hot spots, you must design your primary keys to spread writes evenly across the key space, avoiding monotonically increasing values like timestamps.
Spanner offers both relational features (schemas, SQL, transactions) and noSQL-like horizontal scaling, bridging two traditionally separate database paradigms.
Multi-region configurations let you choose which geographic areas serve reads and writes, directly impacting both data locality and cost.
The PCDE exam tests Spanner’s architecture as a solution to the CAP theorem that provides both strong consistency and high availability.
These come up on the exam all the time. Here's how to tell them apart.
Cloud Spanner
Relational: supports SQL schemas, joins, and transactions
Strong consistency globally via TrueTime
Synchronous replication across regions for every write
Cloud Bigtable
NoSQL wide-column store: no SQL, no joins
Eventual consistency (by default); strong consistency only within a single cluster
Asynchronous replication (if configured); writes are acknowledged locally first
Cloud Spanner
Globally distributed multi-region support built-in
Strong consistency across all replicas
Automatic sharding and resharding
Cloud SQL
Single-region by default; optional cross-region read replicas with eventual consistency
Strong consistency only within the primary region; replicas are eventually consistent
Manual sharding if needed; no automatic split management
Spanner Strong Read
Returns the latest committed data
Must contact the leader replica
Higher latency, especially from distant regions
Spanner Stale Read
Returns data that is at most X seconds old (staleness bound)
Can be served by any read-only replica
Lower latency; can be served from the nearest replica
Read-Write Replica
Can accept write requests
Participates in the Paxos quorum for writes
Contributes to write latency because writes must be replicated to it
Read-Only Replica
Cannot accept writes; serves only reads
Does not participate in write quorum
Reduces write latency because writes do not need to be confirmed there
Mistake
Cloud Spanner is just a globally replicated version of a relational database like PostgreSQL or MySQL.
Correct
Spanner is a fundamentally different architecture. It uses TrueTime and a distributed consensus algorithm (Paxos) to achieve strong consistency, whereas PostgreSQL/MySQL replication typically offers eventual consistency or requires complex manual conflict resolution.
People are familiar with traditional databases and assume Spanner is just a wrapper around one with replication added. They underestimate the innovation in Spanner's foundational design.
Mistake
Spanner’s strong consistency means it is always faster for reads and writes than any other database.
Correct
Strong consistency does not imply speed. In fact, Spanner’s writes are slower than many databases because writes must be synchronously replicated across multiple regions before they are acknowledged. Reads can be fast if served from a local read-only replica, but write latency can be hundreds of milliseconds.
The word 'strong' implies to beginners that it is universally better in all dimensions. They confuse correctness guarantees with performance guarantees.
Mistake
You can use Spanner like a traditional relational database without thinking about primary key design.
Correct
Primary key design in Spanner is critical for performance. A poor primary key (e.g., a monotonically increasing integer) creates hot spots where all writes target a single split, causing slow performance. You must design keys to distribute writes across splits.
In traditional databases, primary key design mostly affects indexing, not write throughput distribution. Beginners don't realise that Spanner’s distributed nature makes key layout a first-order performance concern.
Mistake
Spanner can scale to zero nodes to save money when not in use, like some serverless databases.
Correct
Spanner instances require a minimum number of nodes or processing units to stay available. You cannot scale an instance down to zero. You can delete the instance entirely, but while it exists, it costs the minimum resource allocation.
Serverless databases like Firestore or BigQuery’s on-demand mode have set the expectation that databases can be completely dormant. Spanner is always-on and pre-provisioned to provide consistent low latency.
Mistake
Spanner supports all SQL features of a standard relational database.
Correct
Spanner supports a large subset of SQL, but it lacks some features like stored procedures, triggers, and foreign key cascading in all deployment modes. You must check the specific SQL dialect support.
Because Spanner is relational and supports SQL, beginners assume it is a full drop-in replacement for an existing database. Google publishes a specific SQL reference that lists supported and unsupported features.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
No. Cloud SQL supports MySQL, PostgreSQL, and SQL Server but is single-region with optional read replicas. Spanner is globally distributed with built-in strong consistency. Use Cloud SQL for single-region workloads; use Spanner when you need global scale and strong consistency.
Yes, Spanner supports foreign keys. You can define them in your schema, and Spanner enforces referential integrity. This is a key difference from many NoSQL databases.
Not directly. Spanner offers its own SQL dialect (GoogleSQL) and a PostgreSQL-compatible interface. You would need to rewrite your SQL statements to match Spanner’s dialect and adjust any MySQL-specific features. There is no direct compatibility layer.
Typically yes, because you pay for compute capacity (nodes or processing units) and storage, plus data transfer between regions. Spanner’s value is in its global consistency and reduced operational overhead. For a small single-region app, it is more expensive than a managed MySQL instance.
Spanner automatically fails over to another replica in a different availability zone or region. Because data is replicated synchronously, no data is lost. The leader role moves to a replica in a healthy location, and the database remains available.
Spanner supports databases up to 2 TB per node of storage capacity, and you can scale out to many nodes. There is no hard cap on total database size — it can grow to petabytes by adding more nodes.
You've finished Cloud Spanner Architecture: Global Scale and Strong Consistency. Continue through the PCDE study guide to build a complete picture of the exam.
Done with this chapter?