ALICIA WILLIAMS: Your mission-critical applications
depend on correct data.
That's why developers rely on relational databases, which
ensure data consistency.
However, last generation's databases
weren't designed to handle today's scale and availability
requirements.
In today's episode, we're talking
about how Spanner provides the highest level of consistency
of any distributed relational database at unlimited scale.
Consistency is one of the main reasons
to choose a relational database to back your applications.
Strong consistency guarantees ensure
that data is correct, regardless of
how it's accessed or updated.
Let's say you have a banking system that transfers
money between accounts.
Consistency ensures that the debit
from one account and the credit into the other either
both succeed or both fail.
This simplifies your applications
and lets your DBAs sleep well at night.
When it comes time to scale, however,
traditional relational databases require
you to give up many of the consistency protections
that made them attractive in the first place.
This is because they rely on techniques
like sharding to divide the data across multiple instances.
The overhead required to manage these shards
typically forces operators to choose between performance
or consistency.
In addition, highly available systems
need to maintain multiple copies of the data in case
one of the shards goes down.
For many applications, uncertainty
in the form of replication lag or eventual consistency
is a recipe for complicated code and tricky bugs.
This is where Cloud Spanner can help.
Spanner is the only distributed relational database
that provides external consistency, the highest
consistency guarantee.
This means that all changes in the database
appear from the outside as if they happen sequentially.
This dramatically simplifies a developer's view of the data.
No more sharded queries, timing bugs, or compensating logic.
To your application, Spanner looks
like a familiar single-instance database.
It handles the complexities of ensuring
consistent transactions, even as infrastructure scales
up or automatically fails over.
Spanner is fully managed so your operators don't ever
have to worry about sharding or replication.
So how does Spanner provide external consistency
without sacrificing availability or performance at scale?
Let's start by imagining your database
resides on a single machine.
In this case, it could use a simple counter
to order incoming transactions.
However, a single machine can only scale up so far.
Beyond that, you'll need to distribute the work
across many machines.
Keeping a single counter would be
a bottleneck between hundreds or thousands of servers.
Spanner avoids this by allowing each machine or node
to keep its own counter using a clock, but not just any clock.
Using a combination of GPS, atomic clocks, and Google's
dedicated fiber optic network, Spanner's TrueTime technology
ensures accurate ordering of transactions
without expensive centralized coordination.
TrueTime simplifies the work that Spanner
has to do to provide strict external consistency.
This streamlining translates to better performance
and higher availability for strong ACID transactions.
Let's take a closer look at how Spanner manages the data
involved in those transactions.
Spanner partitions each table's data
into independent chunks called splits.
Each split is assigned internally to a server.
Unlike traditional sharding, these splits
are completely transparent to downstream users.
Spanner automatically optimizes its split configurations
to balance out workloads and avoid hotspots.
When a split is under heavy load,
for example, when updating the inventory of a popular product,
Spanner resizes and re-balances the affected splits
to avoid overloading individual servers.
Splitting and re-balancing happen completely
behind the scenes, dynamically adjusting based
on your data and workload.
To avoid a single point of failure,
each split in a regional instance
is replicated across three isolated zones.
Spanner uses the well-known Paxos consensus protocol
to ensure that everything stays in sync, even
as the storage and machines change underneath.
During a write, Spanner first determines
which split or splits will be affected.
Each split has a leader among its copies
that coordinates locking and replication.
The leader assigns a timestamp to the transaction using
TrueTime and tells the replicas about the updates using Paxos.
Once a majority of the replicas acknowledge the update,
the leader directs them to apply the changes
to the data at the agreed-upon timestamp.
Leadership updates dynamically within an instance,
again, to avoid single points of failure.
For a query that doesn't make any updates,
Spanner avoids the extra overhead
of taking locks, accessing an always consistent copy
of the data at the most recent timestamp.
Combined, these optimizations ensure consistency
and availability at scale.
Spanner takes distributed consistency
a step further with multi-region configurations.
Multi-region instances replicate data
over two or three separate geographic locations,
for example, the US, Europe, and Asia.
This added replication, up to nine times,
provides industry-leading five nines of availability.
But doesn't all of this come at a significant cost
to performance?
While, the underlying work that Spanner
does to ensure consistency and availability is not free.
You only pay a performance cost for what you actually use.
In other words, if a query can run without locking, it will.
Or if a write only touches one split,
it will bypass a more expensive two-phase commit.
This means that your applications
will continue to perform as they scale,
with all the same consistency guarantees.
By partitioning the data into splits,
Spanner can grow beyond a single machine
and resolve queries in parallel, improving scalability
and performance.
By replicating splits over multiple zones and regions
connected by Google's dedicated network,
Spanner is able to remain highly available, up to 99.999%,
even under the most grueling workloads.
Finally, by coordinating updates using TrueTime and Paxos,
Spanner ensures that your applications only ever see
a consistent view of the data.
The best part?
All of this is handled transparently for you
behind the scenes.
So there you have it, the magic sauce
behind Spanner's consistency at scale.
Thank you for joining us today for this episode of "Spanner--
Database Unlimited."
[MUSIC PLAYING]