Why this matters
- CAP is the most cited and most misunderstood theorem in distributed systems interviews — seniors are expected to apply it to real components, not recite definitions.
- Partitions happen in production (misconfigured ACLs, AZ failures, cable cuts) — systems that pretend partitions cannot occur ship subtle double-spend bugs.
- ShardPay documents a CP vs AP decision per service: the payment ledger rejects writes during quorum loss; the merchant notification feed keeps accepting events and reconciles later.
- Interviewers probe whether you can name what you sacrifice and how you detect the partition scenario in metrics and runbooks.
Choose CP for payments, AP for activity feeds
CAP in one partition
When two ledger replicas lose connectivity, they cannot both accept writes and still guarantee that every reader sees the same balance. If both accept writes (AP), balances diverge until reconciliation. If one side rejects writes (CP), some clients see errors but committed data stays consistent across surviving nodes.
ShardPay's ledger shard runs three replicas in one region. During an inter-AZ partition, the minority side stops accepting transfers and returns 503 ShardUnavailable while the majority continues committing. Merchants see a brief error banner; no account is debited twice across divergent copies.
Key points
- Consistency (CAP) — Every read returns the most recent write or an error. In CAP terms this is linearizable agreement on shared state, not eventual convergence. ShardPay applies this definition to the ledger primary: a balance read after a successful transfer must reflect that transfer or fail loudly.
- Availability (CAP) — Every request to a non-failing node receives a non-error response within a bounded time. ShardPay's activity feed API stays available during partition by accepting writes locally and enqueueing them for merge — users still see "payment sent" even if cross-region sync is delayed.
- Partition tolerance — The system continues operating despite arbitrary message loss or delay between nodes. Real WAN and cloud networks always partition eventually; pretending otherwise is not an option. ShardPay assumes partition tolerance everywhere and explicitly chooses C or A per component when a split is detected.
- CP (Consistency + Partition tolerance) — Sacrifices availability on the minority side during a partition so writes do not fork. ShardPay's ledger is CP: if a shard cannot reach a write quorum, it refuses new debits rather than risk inconsistent balances.
- AP (Availability + Partition tolerance) — Sacrifices strong consistency during a partition; replicas may diverge and reconcile later. ShardPay's merchant notification feed and analytics counters are AP — stale counts are acceptable; lost notifications are not.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 2 sections
- Why partition tolerance is not optional
- Designing CP vs AP per component
Test yourself
Answer these before moving on — recall is what makes it stick.