🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Spanner and CockroachDB

Data SystemsDistributed SQLđŸŸĸ Free Lesson

Advertisement

Data Systems

Spanner and CockroachDB

Google Spanner pioneered globally distributed SQL. CockroachDB brought those ideas to the open-source world. Master their architectures, consensus protocols, and the trade-offs between them.

  • Global Transactions — Serializable ACID across regions
  • Consensus — Paxos (Spanner) vs Raft (CockroachDB)
  • Consistency — External consistency vs serializable

These databases prove you don't have to sacrifice consistency for global scale.

Google Spanner

TrueTime

Spanner Architecture

Zone: us-central1Spanserver (Paxos leader)Tablet (data + Paxos logs)Child 1Child 2Zone: eu-west1Spanserver (Paxos leader)Tablet (data + Paxos logs)Zone: ap-south1Spanserver (Paxos leader)Tablet (data + Paxos logs)PaxosPaxos

CockroachDB

Raft Consensus

FeaturePaxos (Spanner)Raft (CockroachDB)
UnderstoodComplexEasier to reason about
MembershipManualDynamic
Leader electionImplicitExplicit
ImplementationCustomReference implementation

Spanner vs CockroachDB

FeatureSpannerCockroachDB
ConsensusPaxosRaft
Time SourceTrueTime (atomic clocks)Hybrid Logical Clocks (HLC)
DeploymentGCP onlyAny cloud, self-hosted
ConsistencyExternal consistencySerializable
LatencyLower (TrueTime)Higher (HLC uncertainty)
CostHigher (GCP pricing)Lower (open source)
Maturity10+ years7+ years

When to Use Each

Use CaseRecommended
Global financial system on GCPSpanner
Multi-cloud distributed SQLCockroachDB
Need lowest latency globallySpanner
Need to avoid vendor lock-inCockroachDB
Already invested in GCPSpanner
Need self-hosted optionCockroachDB

Practice Exercises

  1. Architecture Comparison: Compare the write paths of Spanner and CockroachDB. What happens when a write arrives in the US but the leader for that data is in Europe?

  2. Transaction Design: Design a distributed transaction for transferring money between accounts in different regions. How do you handle the coordination and ensure consistency?

  3. Consistency Analysis: Explain the difference between external consistency and serializability. Why does Spanner's TrueTime matter?

  4. Migration Planning: Your team is migrating from PostgreSQL to CockroachDB. What are the main challenges, and how would you approach the migration?


What to Learn Next

-> NewSQL and Distributed SQL Overview of NewSQL databases and distributed SQL concepts.

-> PostgreSQL Deep Dive Advanced PostgreSQL features, extensions, and optimization.

-> SQL Deep Dive PostgreSQL, MySQL, indexing strategies, and query optimization.

-> Distributed Consensus Paxos, Raft, and consensus protocols.

-> Data Replication Sync vs async replication, leader election, and consistency.

-> CAP Theorem Consistency models, availability, and partition tolerance.

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement