Stage 4 · Provision
Database Scaling Strategies
Distributed SQL (NewSQL)
CockroachDB, Spanner, TiDB — strong consistency at scale with SQL semantics.
What Is NewSQL?
NewSQL databases combine the scalability of NoSQL with the ACID guarantees and SQL interface of traditional relational databases. They distribute data across multiple nodes while maintaining strong consistency and full SQL support. This eliminates the choice between scale and consistency.
How Distributed SQL Works
Distributed SQL databases use consensus protocols (Raft, Paxos) to replicate data across nodes. Each table is divided into ranges, and each range is replicated across multiple nodes. Transactions span multiple ranges using two-phase commit or parallel commits.
SQL Query: UPDATE accounts SET balance = balance - 100 WHERE id = 1
┌─────────────┐
│ SQL Layer │ Parses, plans, optimizes
└──────┬──────┘
│
┌──────▼──────┐
│ Transaction │ Coordinates distributed transaction
│ Layer │ Two-phase commit across ranges
└──────┬──────┘
│
┌──────▼──────┐ ┌─────────┐ ┌─────────┐
│ Range 1 │────►│ Range 2 │────►│ Range 3 │
│ (Raft Group)│ │(Raft Grp)│ │(Raft Grp)│
│ 3 replicas │ │ 3 replicas│ │ 3 replicas│
└─────────────┘ └─────────┘ └─────────┘The SQL layer handles query processing. The transaction layer coordinates ACID transactions across ranges. Each range uses Raft consensus for replication.
CockroachDB
CockroachDB is a distributed SQL database designed for global applications. It automatically shards data, handles rebalancing, and provides serializable isolation. It is wire-compatible with PostgreSQL, making migration straightforward.
- Automatic range splitting and rebalancing as data grows.
- Geo-partitioning for data locality and compliance.
- Serializable isolation by default.
- PostgreSQL wire protocol — use any Postgres driver or ORM.
Google Spanner
Spanner is Google's globally distributed database with external consistency (stronger than linearizability). It uses TrueTime (atomic clocks + GPS) to order transactions globally without coordination. Spanner is the gold standard for distributed SQL but is only available on GCP.
Spanner uses atomic clocks and GPS receivers to maintain a globally synchronized clock with bounded uncertainty. This enables externally consistent transactions without the latency penalty of global coordination.
TiDB
TiDB is an open-source distributed SQL database compatible with MySQL. It separates compute (TiDB server) from storage (TiKV), allowing independent scaling. TiDB is popular in the Chinese tech ecosystem and handles HTAP (hybrid transactional/analytical) workloads well.
Tradeoffs
- Higher latency per query — Distributed transactions add 10-50ms overhead.
- Operational complexity — More nodes to manage, monitor, and upgrade.
- Cost — More infrastructure than a single database instance.
- Limited ecosystem — Some SQL features (certain joins, stored procedures) may not be supported.
Use NewSQL when you need SQL semantics, strong consistency, and horizontal scale. If you can tolerate eventual consistency, NoSQL is simpler. If you do not need horizontal scale, PostgreSQL is battle-tested and mature.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.