Skip to main content
← PROBLEMS / ARCHITECTURE
An end-to-end domain learning journey

CAP & PACELC
Consistency-Latency Trade-Offs.

Even with zero network partitions, PC/EC multi-region Raft clusters pay cross-continent quorum and leaseholder RTTs on every read and write, blowing past tail-latency SLAs.
Start the journey5 stages
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When a single bottleneck threatens end-to-end availability, apply PACELC per workload: keep monetary/inventory writes PC/EC on regional leaseholders, and serve 95% catalog reads PA/EL via local follower reads (`AS OF SYSTEM TIME '-5s'`) with HLC session tokens for read-your-own-writes.

TL;DR30-second simplified summary
▾

Core Mechanics: CAP only describes behavior during a network partition (P). In practice, partitions are rare, while Else (E, normal operation) is 99.99% of production time.

Visual & Structural Flow: Depicts PC/EC Remote Leaseholder Tax vs. Regional Homing (us-east-1 (Lease) -> eu-west-1 (75ms) -> ap-south-1 (195ms)); HLC Session Router: Local Follower Reads vs. Leaseholder Writes (API Edge Router -> Local Follower (<4ms) -> Regional Leaseholder -> Remote DR Replicas).

Trade-Offs & Production: Two naive shortcuts fail in production: Co-Locating All 3 Raft Replicas in One Region: Achieves < 5 ms writes, but a single region outage loses quorum and availability. Every global distributed database exposes explicit PACELC knobs: CockroachDB & YugabyteDB: REGIONAL BY ROW tables pin leaseholders to user geography while.

Failure Modes & Application: Every global distributed database exposes explicit PACELC knobs: CockroachDB & YugabyteDB: REGIONAL BY ROW tables pin leaseholders to user geography while follower_read_timestamp() serves global GLOBAL catalog tables locally.

Full walkthrough · 5 stages
01
STAGE 01 · WHY IT MATTERSL4 · FUNDAMENTALS

Why CAP alone misses the everyday speed-of-light tax.

Why this matters: The mechanism: understand how Why CAP alone misses the everyday speed-of-light tax works from first principles.

CAP only describes behavior during a network partition (P).

In practice, partitions are rare, while Else (E, normal operation) is 99.99% of production time.

02
STAGE 02 · IMPACTL5 · APPLIED DESIGN

390 ms checkout latency and 11,700 pinned connections.

Why this matters: The problem: see what breaks without 390 ms checkout latency and 11,700 pinned connections under real concurrency or scale.

When Raft leaseholders sit in us-east-1:

  1. Read & Write RTT Amplification: ap-south-1 catalog reads (57,000 RPS) travel 195 ms to the remote leaseholder; ap-south-1 writes wait for IN-US + quorum replication (390 ms+ p99).
  2. Connection Pool Bloat: 60,000 RPS × 0.195 s = 11,700 concurrent open DB connections just waiting on speed-of-light travel.
Geo-Distributed Raft Quorum

PC/EC Remote Leaseholder Tax vs. Regional Homing

us-east-1 (Lease)3,000 w/s + US readseu-west-1 (75ms)Follower read <4ms (-5s)ap-south-1 (195ms)Follower read <4ms (-5s)US-EU 75ms / US-IN 195ms

Serving catalog reads from local followers cuts 57,000 RPS from 195 ms to <4 ms, slashing open connections 50x.

Engineering Decision Framework
Problem
How to implement CAP & PACELC Consistency-Latency Trade-Offs without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When a single bottleneck threatens end-to-end availability, apply PACELC per workload: keep monetary/inventory writes PC/EC on regional leaseholders, and serve 95% catalog reads PA/EL via local follower reads (AS OF SYSTEM TIME '-5s') with HLC session tokens for read-your-own-writes.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When CAP & PACELC Consistency-Latency Trade-Offs experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · NAIVE SOLUTIONL5 · APPLIED DESIGN

Naive fixes (and why they break durability or RYW).

Why this matters: The problem: see what breaks without Naive fixes under real concurrency or scale.

Two naive shortcuts fail in production:

  • Co-Locating All 3 Raft Replicas in One Region: Achieves < 5 ms writes, but a single region outage loses quorum and availability.
  • Unbounded Async Follower Reads: A user updates their shipping address, refreshes, hits a follower 5 s behind, and sees the old address (Read-Your-Own-Writes violation).
Request & State Flow

Naive fixes (and why they break durability or RYW)

CallerService EntryCore ProcessorState Store1. Submit bounded request2. Apply domain invariant3. Persist or read state4. Return verified response
04
STAGE 04 · ENTERPRISE SOLUTIONL6 · SCALE & TRADE-OFFS

Enterprise solution: Workload-Split PACELC + Bounded Staleness.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Split workloads explicitly across PC/EC and PA/EL:

  • Catalog Reads (95% = 57,000 RPS, PA/EL): Serve from local regional replicas with bounded staleness (AS OF SYSTEM TIME '-5s'), cutting latency from 195 ms to < 4 ms and open connections from 11,700 to 228.
  • Geo-Partitioned Writes (5% = 3,000 RPS, PC/EC): Home user/order Raft ranges to the user's region (5-replica Raft: 3 in home region for < 8 ms local quorum, 2 remote for DR) while keeping global inventory/wallet writes strongly consistent.
  • Read-Your-Own-Writes Guard: Attach an HLC session cookie (last_write_hlc) for 5 s after a mutation to route that user's reads to the leaseholder.
Workload-Split PACELC

HLC Session Router: Local Follower Reads vs. Leaseholder Writes

API Edge RouterChecks last_write_hl…Local Follower(<4ms)PA/EL catalog AS OF…RegionalLeaseholderPC/EC 3-AZ local…Remote DR ReplicasHLC…5% write / RYW -> lease

Catalog traffic stays local at <4 ms while mutations and 5-second RYW windows route to the regional leaseholder.

-- 1. PA/EL Catalog Read (< 4ms on local ap-south-1 follower)
SELECT sku_id, price_cents, title
FROM catalog
AS OF SYSTEM TIME follower_read_timestamp()
WHERE sku_id = 'SKU-9912';

-- 2. PC/EC Geo-Partitioned Order Table (CockroachDB REGIONAL BY ROW)
ALTER TABLE orders SET LOCALITY REGIONAL BY ROW;
05
STAGE 05 · SYSTEM DESIGN APPLICATIONSL7 · STAFF / PRINCIPAL

Where PACELC workload splitting is used in production.

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Every global distributed database exposes explicit PACELC knobs:

  • CockroachDB & YugabyteDB: REGIONAL BY ROW tables pin leaseholders to user geography while follower_read_timestamp() serves global GLOBAL catalog tables locally.
  • Google Spanner: Uses TrueTime (< 7 ms uncertainty) to serve stale reads (exact_staleness = 15s) at any replica with zero lock contention.
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

How do you prevent Read-Your-Own-Writes (RYW) anomalies when serving 95% of reads via `AS OF SYSTEM TIME '-5s'` local follower reads?

Recommended Learning Flow