Everything so far assumed one machine. Replication answers its failure and sharding answers its ceiling, and both are the single-node mechanisms of this track projected across a network. The interesting material is not how they work but what they quietly change: acknowledged writes that can disappear, reads that return the past, constraints the database stops enforcing, and operations — failover, resharding, restore — whose real duration is set by the slowest client, the busiest partition and the headroom you did not provision.
The payoff of Chapter 4 is that the replication stream is the WAL: the primary ships the same redo records it uses for crash recovery, and a physical standby is a server in permanent crash recovery that never finishes. That framing predicts its properties. The standby is physically identical page for page, so it cannot have different indexes, a different major version or a subset of tables. Everything the primary writes, including vacuum, index builds and bulk loads you never meant to replicate, costs the standby the same replay work. And it inherits every corruption the primary writes, which is why a replica is availability, not a backup.
Logical replication decodes the WAL into row changes and ships those instead. It buys cross-version upgrades, table subsets and a CDC feed, and it pays in exactly the places physical replication was free. DDL is not replicated in PostgreSQL's built-in logical replication, so a schema migration applied in the wrong order stops the subscriber on the first row that no longer fits. Sequences are not replicated, so a subscriber promoted during a migration hands out ids that collide with ones already used. Tables without a primary key or replica identity cannot replicate updates and deletes efficiently. And the decoding slot on the publisher holds WAL until the subscriber confirms it, so a stalled consumer is a disk-full outage on the primary (6.3 returns to this). Use logical replication as a migration and integration tool with a runbook, not as the HA mechanism.
The same write-ahead log from Chapter 4 is the replication protocol: the primary streams its WAL to each replica, which replays it to reconstruct an identical copy. Replicas serve read-only traffic and stand ready to be promoted if the primary fails. This is why understanding the WAL was a prerequisite — replication is just the log, shipped.
Single-leader is the workhorse because there is exactly one serialization point for writes. The alternatives remove it and pay in conflicts. Multi-leader (typically one leader per region) looks like a latency win until two regions update the same row within the replication delay; the usual resolution is last-write-wins on timestamps, which discards one of two acknowledged writes, and does so silently. The honest use of multi-leader is data that is partitioned by region anyway, where conflicts are structurally impossible, and in that case you have built geo-sharding and should call it that.
Leaderless (Dynamo-style) replication writes to W of N replicas and reads from R, and the quorum arithmetic R + W > N is supposed to guarantee a read sees the latest acknowledged write. The arithmetic is correct and the guarantee is weaker than it reads. Under a partition, sloppy quorums accept the write on stand-in nodes outside the key's home set, so both quorums are met and still do not intersect. Concurrent writes resolved by timestamp lose one writer. A write that reached fewer than W nodes is reported as failed but may still be visible to later reads. Tunable consistency is real, but R + W > N buys "usually recent", not linearizable, and a design that needs compare-and-set belongs on a consensus system (6.6).
Left: the arithmetic that leaderless stores sell. Right: what hinted handoff does to it — during a partition the write is accepted by a stand-in node outside the key's home replicas, so W is satisfied and R is satisfied and the read still misses the write. Even strict quorums are not linearizable on their own: concurrent writes resolved by last-write-wins timestamps silently drop the loser, and a read concurrent with a partial write can see v2 then v1 unless read repair completes synchronously.
The part that actually hurts in production is not replication but failover, because the system must decide a primary is dead using only the absence of messages — and a 40-second GC pause, a saturated NIC or a hung fsync all look identical to death. Set the detection timeout short and you fail over on every stall, each one an opportunity to lose the async tail; set it long and a real crash means that many seconds of total write unavailability. Worked example, illustrative numbers: at 5,000 commits/s with 200 ms of replica lag at the moment of failure, a promotion discards roughly 1,000 transactions that clients were told had committed. That number, not the lag graph, is what to put in front of the product owner.
Two independent loss sources. The pink tail on the left is the async data-loss window: transactions the client saw commit that never left the old primary. The block at ④ is worse — a primary that was only slow, not dead, keeps accepting writes from clients the router hasn't moved yet. When it rejoins, its divergent timeline must be discarded (pg_rewind or a rebuild). Only fencing — an epoch/term check the storage or proxy enforces, or power-fencing the node — closes ④; a timeout never does.
The quieter failure is split brain. Promotion is a decision made by an orchestrator (Patroni, Orchestrator, a cloud control plane); the old primary does not learn about it unless something tells it. Any client still holding a pooled connection or a cached DNS answer keeps writing to it, and now two timelines diverge. The only real defence is fencing with a monotonically increasing epoch — the old primary must be unable to commit, not merely asked to stop — plus a hard rule that a demoted node never rejoins without rewinding to the promotion point. A review question worth asking of any HA design: "walk me through what the old primary does if it was paused, not dead, for 45 seconds."
Failover time is a sum, and teams quote only the smallest term. Illustrative budget for an orchestrated PostgreSQL failover: detection at three missed 10-second health checks is 30 s; leader-lock expiry in the consensus store adds whatever TTL it was given; promotion itself is seconds if the standby is caught up but equals its replay backlog if it is not (a standby 54 GB behind, per 6.3, is not a failover target for the next hour); then the routing layer. DNS with a 30-second TTL is honoured by some clients and cached for the process lifetime by others; connection pools hold sockets to the dead primary until TCP gives up, which with default keepalives can be minutes. Real RTO is dominated by the slowest client, not the database. Two design rules follow: route through a proxy or a virtual IP the orchestrator controls rather than DNS, and exclude a standby from candidacy when its replay lag exceeds the promotion budget, because promoting a far-behind replica converts a short outage into a long one and a larger data loss.
Sync versus async is the fsync trade of Chapter 4 replayed over the network: a synchronous commit exists on two machines before the client hears "committed" and pays a round-trip for it; an asynchronous commit is acknowledged from one machine and carries a data-loss window equal to whatever had not shipped. The right way to state that window is in transactions at peak, as in 6.1, because "sub-second lag" sounds harmless until it is multiplied by the commit rate.
Synchronous
Zero data loss on primary failure — the commit is on ≥2 nodes. Cost: every commit pays a network round-trip.
Asynchronous
Fast commits, no network wait. Cost: a primary crash can lose the last few unshipped transactions.
The same trade as fsync in Chapter 4, now over the network. Synchronous replication guarantees a committed transaction survives losing the primary, at the price of round-trip latency on every commit; asynchronous is fast but has a data-loss window. Many systems compromise with quorum acks (wait for k of n) to get durability without waiting for the slowest replica.
A usable decision rule, in terms a product owner can sign. If the agreed RPO is "zero acknowledged transactions", you need sync to at least one standby in a different failure domain, and you need two such standbys (any 1 of 2) or the RPO costs you availability. If the RPO is a count of transactions greater than zero, divide it by peak commit rate to get the lag budget in seconds, and alert when p99 lag exceeds half of it, since the loss is set by lag at the instant of failure, not by average lag. If the only standby that can satisfy sync is cross-region, the question is no longer replication mode but whether the hot rows survive the 1/RTT ceiling above; if they do not, the answer is async cross-region plus sync in-region, and the accepted loss is a regional disaster's lag window, stated explicitly. Majority-quorum acks are also the building block consensus systems use for strong consistency at scale (6.6).
Three things the sync/async binary hides. First, "synchronous" is a spectrum of what the replica has done before it acks. PostgreSQL's synchronous_commit alone offers remote_write (in the standby's OS cache), on (flushed to its disk) and remote_apply (replayed and visible). Only the last gives read-your-writes on that standby; the first two protect durability but a read routed there can still be stale. Teams routinely buy sync replication believing they bought consistent replica reads, and did not.
Second, synchronous with one standby is an availability regression. If the single named sync standby dies, PostgreSQL commits block indefinitely — you converted a replica failure into a primary outage. MySQL's semi-sync takes the opposite default: after rpl_semi_sync_master_timeout it silently falls back to async, so the durability guarantee you designed for evaporates exactly during the incident when it matters, and returns later without anyone noticing. Neither is wrong; what is wrong is not knowing which one you have. The robust shape is ANY k of n (e.g. any 1 of 2 standbys in different zones), which tolerates a standby loss without either blocking or degrading.
Third, quorum latency is an order statistic. With "any 1 of 2", commit latency is the faster of two round-trips, which is usually tighter than a single fixed standby — adding a replica can reduce p99 commit latency. The geography sets the floor: same-zone round-trips are sub-millisecond, cross-zone typically low single-digit milliseconds, cross-region tens of milliseconds. A single-row-update workload at 1 ms local commit that goes cross-region sync pays that RTT on every commit and, for a hot row serialized by its lock, caps that row at roughly 1/RTT updates per second — about 25/s at an illustrative 40 ms. The cost of sync is lock hold time, not latency: before enabling it, rank rows by lock-wait time and compute this ceiling for the top ten, because the change that fixes RPO is also the change that caps checkout throughput.
An async replica is usually milliseconds behind and occasionally hours behind, and the application cannot tell which from the connection string. The anomalies are the familiar ones — read-your-writes, monotonic reads (a second read on a more-lagged replica goes backwards in time), causal order (a reply visible before its message) — and the non-obvious point is where they hurt. User-facing staleness is usually tolerable. What breaks is machine readers: a job that writes a row on the primary and enqueues its id, and a worker that reads the id from a replica and finds nothing, then marks the job failed or, worse, creates the row again. Queue-driven read-after-write through replicas is the most common source of "impossible" duplicates in systems that added read replicas late.
A replica is always a little behind. A user who writes to the primary then immediately reads from a replica can see old data — the "read-your-writes" violation. Lag is not just a metric; it is a correctness question. Fixes: read from the primary after a write, use causal/monotonic-read tokens, or require the replica to have caught up to your write's log position before answering.
The fixes differ in who pays. "Read from the primary for N seconds after a write" is cheap to build and quietly wrong: N is a guess about lag, and on the day lag exceeds it the bug returns exactly when the system is under stress. Session pinning to one replica fixes monotonic reads but not read-your-writes. The robust mechanism is a log-position token: the write returns its commit LSN (or GTID), the client carries it, and a replica serves the read only once it has replayed past that position, otherwise waiting briefly or redirecting to the primary. That turns lag from a correctness bug into a latency cost, and it degrades in the right direction. Its second-order risk is the redirect: if a lag spike sends every token-carrying read to the primary, the read load you moved off the primary comes back at the worst moment. Cap the redirect rate and let reads wait or fail rather than stampede.
Why lag goes from milliseconds to hours is worth knowing mechanically. On the primary, many backends generate WAL in parallel; on a PostgreSQL physical standby, a single startup process replays it (MySQL has parallel appliers, but they are bounded by how much of the stream is provably independent). So lag is a throughput race, not a latency number, and replay is often I/O bound on random page reads the primary served from cache: a standby with a cold or smaller buffer pool replays more slowly than the primary wrote. Illustrative: a batch job pushes the primary to 60 MB/s of WAL, the replica applies 45 MB/s; it falls behind 15 MB/s, 54 GB an hour, and the drain after the job ends runs only at the headroom above the steady write rate.
Illustrative numbers. The backlog grows at 15 MB/s for an hour. What decides the recovery is not the replica's apply rate but its headroom over the steady write rate: 10 MB/s of headroom drains 54 GB in 90 minutes, 25 MB/s in 36. A replica provisioned at "comfortably above average WAL rate" can have almost no headroom at peak, which is why lag incidents last far longer than the load spike that caused them.
The capacity consequence runs against intuition: read replicas do not add write capacity, and every replica must replay the full write stream while also serving its share of reads. A replica sized smaller than the primary to save money is exactly the replica that falls behind first, and adding replicas to a write-heavy cluster adds nodes that each carry the full replay cost. The sizing rule is apply headroom at peak WAL rate (measure it with the replica also under read load), with a target of catching up from the largest routine batch within the staleness budget of the most sensitive replica reader.
The second mechanism is the replica-query conflict. Replay wants to remove row versions that a long analytic query on the replica still needs (the MVCC snapshots of Chapter 3). The replica must either pause replay — lag grows for as long as the query runs, capped by max_standby_streaming_delay — or cancel the query. Turning on hot_standby_feedback avoids the cancellation by telling the primary to keep those versions, which moves the cost to the primary as vacuum bloat. There is no free setting: you choose between replica lag, cancelled queries and primary bloat, and "run analytics on the read replica" silently picks one of them. The related trap is an abandoned replication slot: the primary retains WAL for a consumer that never returns until the disk fills and the primary stops. Cap it (max_slot_wal_keep_size) and alert on retained WAL bytes, not just on lag.
Design-review questions for read replicas
Sharding is what you do when the write stream, the working set, or the time to rebuild one node no longer fits one machine. Range partitioning keeps scans local and puts every write of a sequential key (timestamp, auto-increment id) on the last shard; hash partitioning spreads keys and turns every range scan into a fan-out. That choice is well known and matters less than the three that follow: which key, where the secondary access paths live, and how you will move data later.
Range partitioning
✓ range scans stay on one shard ✗ hotspots: sequential keys (timestamps) all hit one shard
Hash partitioning
✓ even load, no hotspots ✗ range scans hit every shard; resharding moves data (use consistent hashing)
The partition key is the most consequential schema decision in a sharded system. A bad key (low cardinality, or one that co-locates a hot tenant) creates a hotspot shard that bottlenecks the whole cluster no matter how many nodes you add.
The partition key should be chosen from the transaction boundary, not the table. List the write paths that must be atomic and the reads that must be fast, and find the entity that appears in nearly all of them — usually tenant, account or user. If more than a few percent of transactions would span two values of the candidate key, it is the wrong key, because each of those becomes a distributed commit (6.5). Cardinality needs to exceed the planned node count by two or more orders of magnitude so that placement has room to balance, and the key must be present on every table that joins to it, which is the migration cost 6.7 warns about.
Two things the range-vs-hash framing misses. The first is that hash partitioning spreads keys, not load. A single hot key — the celebrity account, the one enterprise tenant, the global counter — lands on one shard under every hash function. With 20 shards the fair share is 5% each; one tenant at 30% of traffic makes its shard carry six times the average, and the cluster's headroom is set by that one node. Fixes are application-level: split the hot entity's key (salting or sub-keys, paying for it with fan-out reads), give it a dedicated shard via a directory, or cache in front of it. No placement algorithm solves a single hot key.
The second decision is where every non-key access path lives. A table sharded by tenant still needs lookup by email at login, by external order id from a webhook, by SKU from search. Each such path is a secondary index, and on sharded data it has to be either local (each shard indexes its own rows, so a lookup probes every shard) or global (the index is itself partitioned by the indexed value, so a lookup is targeted but every write touches extra shards).
Local (partitioned with the rows)
Writes are single-shard and the index is always consistent with its rows. Every lookup not on the partition key is a scatter-gather, and a unique constraint on the column cannot be enforced.
Global (partitioned by the indexed value)
Reads are targeted. But a row write now touches its shard and one index shard per indexed column — a distributed transaction, or an async update that makes the index briefly lie.
This is the choice the range-vs-hash framing hides: every secondary access path must pick where its fan-out lives. Five global indexes turn one logical insert into up to six shard writes; a read-heavy lookup table with a local index turns every lookup into N probes. Most systems default to local and make global indexes opt-in precisely because the write amplification is invisible until it isn't.
Two consequences surprise teams. Uniqueness on anything but the partition key is no longer a constraint the database enforces; with local indexes it is unenforceable, and with a global index it is a cross-shard write on every insert. The practical patterns are to make the unique attribute a partition key of its own lookup table (an email → user id table, sharded by email, written first as a reservation), or to accept eventual detection and a reconciliation job. And id generation stops being a sequence: per-shard sequences collide on merge and leak shard identity into ids, while time-ordered ids (Snowflake-style, UUIDv7) are unique without coordination but, as range keys, recreate the last-shard hotspot. Hash-partition on them, or partition on the tenant and use them only as a clustered key within it.
The second is that the day-one scheme matters less than the resharding story, because you will reshard, under load, probably during growth you did not predict. The standard mature answer is to decouple logical partitions from physical nodes: pre-split into far more partitions than you have nodes (hundreds or thousands), place them by a mapping table, and rebalance by moving whole partitions. That is the idea behind Citus shard placement, Couchbase vBuckets and Kafka partition reassignment; range-split systems (Bigtable descendants, CockroachDB, TiKV) go further and split and merge ranges automatically as they grow or get hot.
Modulo placement moves N/(N+1) of keys; ring and fixed-partition schemes move roughly 1/(N+1), the theoretical minimum. The table's real lesson is the right-hand column: the cheap-to-rebalance schemes spread load evenly, which is the wrong goal when one tenant or key is 30% of traffic — only range splitting and directories can isolate skew.
The online move itself is the dangerous part: copy a snapshot of the partition, stream changes from its log until the copy is caught up, briefly block writes, flip routing, then unblock. The cutover window is where incidents live — routing caches that don't flip, writes that land on the source after the snapshot but before the block, and the copy traffic itself competing with production I/O. Budget the copy honestly: moving 2 TB at a throttled 100 MB/s is about 5.5 hours per move, and if the cluster is resharding because it is out of headroom, it has little I/O to spare for the copy. As a rule of thumb, start resharding at 60–70% utilisation, not at 95%.
① snapshot copy
hours
Bulk copy of the partition at a known log position.
Competes with production I/O; throttle, or p99 on the source shard climbs for the whole copy.
② log catch-up
minutes
Stream changes since the snapshot until the gap is small.
Never converges if the partition writes faster than the copy applies — the same race as replica lag.
③ write freeze
ms – s
Block writes on the source, drain the final tail.
Freeze length = remaining tail ÷ apply rate. Clients see it as a latency spike or lock timeouts.
④ route flip
ms
Bump the partition's epoch in the routing map.
Clients with cached routes write to the source. Source must reject writes carrying the old epoch.
⑤ drain & delete
hours – days
Keep the source read-only, then drop it.
Delete too early and there is no rollback; too late and the disk you meant to free is still full.
Only phase ③ is visible to users, and its length is set by phase ②: if catch-up has converged to a few MB of tail, the freeze is milliseconds; if it has not, the tool either waits forever or freezes writes for as long as it takes. The correctness hinge is ④ — without an epoch check on the source, a stale router silently writes to a partition that no longer owns the key, and those writes vanish when ⑤ runs.
Put the pieces together for a fleet. Illustrative: 40 shards at 2 TB each, growing to 60. Each of the twenty new nodes ends up holding 1/60 of the 80 TB, drawn from every existing node, so roughly 27 TB moves in total. At 100 MB/s per move and four concurrent moves (more than that and source I/O suffers), the rebalance is about 19 hours of wall-clock copying, before catch-up and cutovers, and it must be paused during peak. That is why fixed partitions need to be pre-split for the final node count you can imagine, not today's, and why the operation needs to be routine enough to run weekly: a resharding procedure exercised once a year is a resharding procedure that will fail the one time it is needed.
A query that carries the partition key is routed to one shard and behaves like the single-node system of Chapter 5. One that does not becomes a scatter-gather, and the planner problems multiply: a cross-shard ORDER BY … LIMIT 20 must fetch 20 rows from each shard and merge, so page 50 of a result at 40 shards pulls 1,000 × 40 = 40,000 rows through the coordinator to return 20; a cross-shard join either co-locates both tables on the same key, broadcasts the smaller table, or reshuffles one side across the network. The coordinator is also now a single process holding N partial results in memory, which is where aggregate queries on sharded clusters run out of memory first.
Cross-shard writes need atomic commit, classically two-phase commit: prepare on every participant, then commit once all vote yes. Count its cost in lock hold time rather than messages. Each participant holds its locks from its first write through prepare (a durable log flush), the coordinator's decision (another durable flush) and the commit message. Illustrative, same-zone: two round-trips at 0.5 ms plus three fsyncs at 1 ms is roughly 4 ms of locks held, versus about 1 ms for a single-shard commit, so a contended row loses around three-quarters of its throughput ceiling the moment its transaction spans a second shard. Cross-zone participants multiply that. And if the coordinator dies between the two phases, every participant is blocked holding those locks until it comes back.
Scatter-gather read
A query without the partition key must ask every shard and merge — as slow as the slowest shard.
Two-phase commit (cross-shard write)
Atomicity across shards needs 2PC, which is slow and can block on coordinator failure — the tax of distributed writes.
Sharding scales capacity, but the moment a query or transaction spans shards you inherit the hard problems of distributed systems. The design goal is to pick a partition key so that the common queries and transactions stay on a single shard.
The scatter-gather cost is worse than "as slow as the slowest shard" suggests, because slowness compounds with fan-out. If each shard independently has a 1% chance of a slow response, a query touching N shards hits at least one with probability 1 − 0.99N. That is the curve below, and it is why a cluster that looks healthy shard-by-shard produces an ugly p50 for fan-out queries once it grows past a few dozen shards.
A query waits for its slowest participant, so a per-shard tail event with probability p shows up in 1 − (1−p)N of fan-out queries. At 50 shards, 40% of scatter-gather queries pay some shard's p99 — the shard p99 has become the query's median-ish latency. The lever is not faster shards but smaller N (route by key, keep a global index) or engineering the per-shard p99.9; hedged requests only help if each shard has a replica to hedge against.
The 2PC blocking window also has a concrete, underappreciated cost: a participant that has voted yes holds its row locks and its transaction state until it hears the outcome, and cannot unilaterally decide. In PostgreSQL an orphaned PREPARE TRANSACTION survives restarts, keeps its locks, and pins the xmin horizon so vacuum cannot reclaim anything newer — a coordinator bug becomes table bloat and lock timeouts days later. Any design using native 2PC needs a janitor that finds prepared transactions older than a threshold and resolves them against the coordinator's durable log. The alternative most teams pick is to avoid atomic cross-shard commit entirely with sagas and idempotent compensations — which trades atomicity for visible intermediate states the application must tolerate.
Two costs of sharding show up nowhere in the query path. The first is that there is no longer a consistent snapshot of the database. A scatter-gather read runs on N independent snapshots taken microseconds apart, so a transfer committed across two shards can appear on one side and not the other; backups taken per shard restore to N slightly different instants, and a point-in-time restore of the whole cluster to a consistent moment requires either a global commit timestamp or a coordinated restore point that briefly pauses cross-shard commits. Ask how a full-cluster restore is proven consistent before assuming it is. The second is connection fan-out: if each of 200 application instances keeps a pool of 20 connections to every shard, a 40-shard cluster receives 200 × 20 = 4,000 connections per shard, far beyond what a process-per-connection engine handles well. Sharding forces a routing proxy or a shared pooler tier, and that tier becomes a new availability dependency on every query.
The engineering response is to design cross-shard operations out: choose a partition key so that the common transactions and joins stay within one shard (co-locate a customer's orders with the customer), and reserve scatter-gather and 2PC for the rare cases. When you cannot avoid them, you are paying the irreducible tax of distributing data — which is the context in which NewSQL makes its pitch.
CAP is over-quoted — partitions are rare, and the everyday trade is latency vs consistency (PACELC's point) — but it names the real fork: AP systems (async replicas, Dynamo-style stores) stay up and reconcile later; CP systems refuse divergence and go unavailable on the minority side. NewSQL — Spanner, CockroachDB, TiDB, YugabyteDB — is the attempt to get SQL semantics with horizontal scale on the CP side. The trick is to shard the data and replicate each shard via a consensus protocol (Raft or Paxos), so every write commits on a majority quorum of that shard's replicas. Consensus gives strong consistency, automatic failover (a new leader is elected the moment the old one is unreachable), and — because there are many shards each with its own consensus group — horizontal write scale.
CAP says under a network partition you choose consistency or availability. Classic async replicas lean AP-ish (stale reads); NewSQL systems (Spanner, CockroachDB, TiDB, YugabyteDB) shard data and replicate each shard via a consensus protocol (Raft/Paxos), committing on a majority quorum. That buys strong consistency, automatic failover, and horizontal scale together; the price is a majority round-trip on every write and, under a partition, unavailability for any range whose majority is on the other side — CP, not a repeal of CAP.
A common misreading is that NewSQL replaces 2PC. It does not: a transaction touching rows in two ranges still runs an atomic-commit protocol across two consensus groups (Spanner's 2PC over Paxos groups, TiDB's Percolator-style protocol over Raft, CockroachDB's transaction records with parallel commits). What changes is that the coordinator and every participant are themselves replicated state machines, so a single node crash no longer leaves locks held with nobody able to decide — the blocking failure of 6.5 becomes a leader election. The latency does not go away. A cross-range write pays consensus rounds on each group plus the commit protocol, and in a multi-region layout every one of those rounds is a WAN round-trip unless the leaders are placed near the writers.
That placement question is the real design work in these systems. Where does each range's leader live, and does it follow the data's writers? Are reads served by the leader (fresh, but a WAN hop for remote clients) or by follower reads at a slightly stale timestamp? Is the table's primary key sequential, which recreates the range-partitioning hotspot of 6.4 inside the NewSQL cluster? And how does the system bound clock uncertainty — Spanner waits it out on every commit (commit wait, sized to the TrueTime uncertainty bound), while HLC-based systems instead restart reads that fall into the uncertainty window, which shows up as retry errors the application must handle.
Put numbers on the multi-region case, illustratively. Three regions with 30–70 ms between them, five replicas per range spread 2-2-1. With the leader in region A, a single-range write commits when a majority (3 of 5) acks: the two local replicas plus the nearest remote one, so roughly one 30 ms round-trip. A transaction touching three ranges whose leaders sit in three different regions pays the client-to-leader hops plus consensus on each plus the commit protocol, which can reach several hundred milliseconds even with pipelining. The same hot-row arithmetic as 6.2 then applies with a 30 ms floor: a contended row tops out around 30 updates per second. The lesson is that NewSQL moves the partition-key problem from "which shard" to "which region": tables keyed so that a user's rows share a region with the user (regional-by-row placement, or explicit leader pinning) get single-region latency, and everything else pays the WAN on every write.
When is it worth it over sharded PostgreSQL or MySQL? The case is strong when cross-shard transactions are a real, non-trivial share of writes (so 2PC with blocking coordinators would be your life), when you need multi-region writes with zero RPO, or when the team cannot staff the resharding and failover machinery of 6.1 and 6.4 and would rather buy it. It is weak when the workload is already cleanly partitioned by tenant (sharded Postgres gives single-node latency and a mature ecosystem), when p99 single-row latency under 2 ms is a requirement, or when the application leans on engine features — extensions, specific isolation behaviour, stored procedures — the NewSQL system emulates only partly. Serializable-by-default systems also surface retry errors under contention that the application must handle; a codebase written against READ COMMITTED needs an audit of every transaction for retry safety before it moves.
The decision framework: reach for replication first — it is simpler and solves availability plus read scaling, which is what most systems actually need, and single-leader async-with-quorum covers a huge range. Reach for sharding only when writes or data size genuinely exceed one node, because it imposes a permanent tax of careful partition-key design and cross-shard complexity. Treat consistency as a dial you set per operation — strong where correctness demands it (route to primary, use consensus), relaxed where staleness is harmless (read from replicas).
Where the conventional advice is wrong: "shard when you outgrow one box" is usually too early and too late. Too early, because a single modern primary with fast NVMe and a large buffer pool handles far more than most teams assume, and vertical scaling plus replicas plus moving analytics off the OLTP store defers sharding for years. Too late, because the time to choose the partition key and make every table carry it is while the schema is small — retrofitting a tenant id into every foreign key and query path is the expensive part, not the cluster. A practical trigger is whichever arrives first: the write rate or working set is projected to exceed roughly half of the largest instance you would be willing to run within the next 12–18 months, or a single restore/rebuild of the database takes longer than your recovery-time objective allows.
Questions a principal engineer asks in the review
The unifying insight is that distributed databases are the single-node fundamentals of this track, projected across a network that can delay and drop messages. It is the WAL that replicates, the transactions of Chapter 3 that now need distributed commit, and the query planner of Chapter 5 that now must cost the network. The last chapter turns from scaling the relational model to leaving it — the non-relational engines built for shapes of data the row-and-table store serves poorly.
Replication
Availability + reads
Lag
A consistency bug
Sharding
Write + size scale
NewSQL
Consensus for both
Where next