Dieser technische Artikel ist auf Englisch verfügbar.
CAP is useful when it stops being a database-labeling exercise and starts being a failure decision. The practical question is not whether a system is “CP” or “AP” on a normal Tuesday. It is what a specific operation is allowed to do when replicas can no longer communicate and the system cannot know which state is current.
That distinction matters in payment, wallet, inventory, booking, and other high-volume transactional systems. A stale profile description is usually repairable. A duplicated debit or two confirmed reservations for one seat may not be. The architecture should reflect that difference explicitly.
1. CAP Theorem Explained
The CAP theorem describes a constraint on a replicated data system during a network partition. If nodes are separated and messages between them are lost or delayed, the system cannot simultaneously guarantee both a single up-to-date view of the data and a successful response from every reachable replica.
CAP does not say that distributed systems are always inconsistent or unavailable. When communication is healthy, a system can provide consistent reads and remain available. The theorem becomes operationally important when part of the cluster cannot coordinate with the rest.
2. What C, A, and P Actually Mean
C
Consistency
Each successful read behaves as if it observed one current, authoritative copy. After a write is acknowledged, later reads do not silently return an older value.
A
Availability
Every request sent to a non-failing node eventually receives a non-error response, even when that response cannot be proven to contain the latest write.
P
Partition tolerance
The system has defined behavior when nodes cannot exchange messages reliably. Packets may be dropped, delayed long enough to look lost, or delivered across only part of the topology.
3. The “Choose Two” Misconception
“Choose two out of three” is a memorable shortcut, but it encourages the wrong design conversation. A production system does not permanently turn partition tolerance on or off. Once state is replicated over a network, partitions are a failure mode the design must handle—even if they are uncommon and even if the first symptom is only a timeout.
The more useful interpretation is: when communication is partitioned, an operation must either protect a consistent result or remain available without certainty that every replica agrees. Different requests can make different choices.
Replicas communicate
Writes propagate, reads can be routed safely, and the system may provide both consistency and availability within its normal latency budget.
Coordination is uncertain
A node cannot distinguish a failed peer from a slow link. It must reject or delay some work, or accept work that may conflict with another partition.
State must converge
Traffic is repaired, but divergent histories do not disappear automatically. The system needs replay, conflict resolution, repair, or reconciliation.
4. What Happens During a Network Partition
Consider two regions holding replicas of the same account record. In healthy operation, a client writes through Region A and the update is replicated to Region B.
Both regions agree after replication completes. The interesting behavior begins when coordination is no longer possible.
Region B cannot prove whether Region A is down, slow, or processing newer writes. A timeout provides uncertainty, not truth.
Now a second client reaches Region B. Should Region B reject the request because its state may be stale, or answer from the copy it has? CAP does not choose for us. The business invariant does.
5. Choosing Consistency During the Partition
A consistency-oriented path refuses to acknowledge an operation when it cannot establish the required authority or quorum. The client may receive a retryable error, a timeout, or a read-only response. This reduces availability, but it avoids confirming two incompatible versions of irreversible state.
The service sacrifices successful responses for this operation until it can prove that the balance invariant is safe.
Typical consistency-oriented operations include:
- Payment and wallet mutations: debits, credits, withdrawals, settlements, and idempotency records.
- Scarce-resource allocation: inventory reservation, seat booking, limited offers, and unique ownership.
- Coordination: leader election, distributed locks, and lease handoff—usually with fencing tokens so an expired holder cannot keep writing.
- Irreversible transitions: marking a payout completed or consuming a one-time token.
“Choose consistency” does not mean waiting forever. Production APIs need bounded timeouts, explicit retry semantics, idempotency keys, and an honest error response. Returning 503 retry later can be more correct than returning 200 success for an operation the system may later reverse.
6. Choosing Availability During the Partition
An availability-oriented path lets a reachable replica answer or accept a write without waiting for every region. Reads may be stale, and concurrent writes may create divergent versions. That can be a good trade when serving something slightly old is materially better than serving nothing.
The request succeeds, while repair and replication are deferred until connectivity returns.
Availability is often preferred for profile information, social and activity feeds, analytics, product descriptions, recommendations, search indexes, cached content, and notification delivery. But accepting divergent writes creates obligations:
- Define conflict semantics—last-write-wins, field merge, version vectors, application reconciliation, or a domain-specific rule.
- Keep enough version and audit information to identify which update happened and why.
- Run anti-entropy, read repair, replay, or reconciliation so “eventual” has a mechanism and an observable deadline.
7. CAP Decisions Belong to Features, Not Marketing Labels
Calling an entire payment platform “CP” hides the real architecture. The wallet ledger, customer-facing history, analytics pipeline, and notification service do not carry the same invariants. Their partition behavior should not be identical.
The same application may reject a debit, serve a stale transaction projection with a “processing” state, enqueue analytics asynchronously, and continue sending notifications during one incident. That is not inconsistency in the architecture; it is a precise allocation of guarantees.
8. Consistency Models
“Consistent” is not one binary setting. The contract a user observes can be chosen more precisely.
strongStrong consistency
After an acknowledged wallet credit, every permitted read observes that credit. Coordination is paid on the critical path.
eventualEventual consistency
An analytics counter may differ between replicas, but converges after queued events and repair complete—assuming writes stop and repair succeeds.
sessionRead-your-own-writes
A user immediately sees the profile they just edited, perhaps through sticky routing or a version token, while other users can briefly see an older copy.
causalCausal consistency
A comment is never shown before the post it replies to, while unrelated posts can be observed in different orders.
Higher coordination cost; the acknowledged version is visible.
Fast local response; a bounded stale window exists.
9. Replication and CAP
Replication topology determines where coordination occurs and which failures expose stale or conflicting state.
- Synchronous replication waits for one or more replicas before acknowledging a write. It can reduce acknowledged data loss and provide stronger visibility, but cross-region round trips increase latency and a missing quorum reduces write availability.
- Asynchronous replication acknowledges before remote replicas catch up. It improves write latency and lets the primary continue through some replica failures, but creates replication lag and a failover window in which acknowledged data may be absent from the promoted replica.
- Leader/follower architectures centralize write ordering. Follower reads scale well but may be stale; failover needs a safe promotion rule to prevent two leaders.
- Multi-leader or leaderless deployments can accept regional writes, but concurrent updates require versioning, conflict detection, and deterministic reconciliation.
10. Quorums: Useful Intuition, Not Magic
For a replica set:
Ntotal replicasWreplicas that must acknowledge a writeRreplicas consulted for a read
The overlap gives the read a chance to observe a replica that accepted the latest successful write.
The common intuition is that W + R > N creates an intersection between read and write sets. It is useful, but it is not a universal proof of strong consistency. The result also depends on reading from the same replica set, comparing trustworthy versions, resolving concurrent writes, handling sloppy quorums or hinted handoff, and defining what happens when a quorum is unavailable. Clock-based last-write-wins can still select the wrong business outcome when clocks or concurrent updates disagree.
11. CAP and Modern Databases
Product names are not CAP classifications. Modern databases expose choices through topology, consistency level, read preference, write acknowledgement, replication mode, and operation type.
PostgreSQL
A single primary gives one write authority. Synchronous standbys can strengthen durability at a latency and availability cost; asynchronous replicas can serve stale reads. Multi-region behavior depends on the replication and failover system around PostgreSQL.
MongoDB
Replica-set elections, writeConcern, readConcern, and read preference change the guarantee. Majority acknowledgement plus appropriate reads behaves differently from accepting local writes and reading secondaries.
Cassandra
Per-operation consistency levels let clients trade coordination for availability. Quorum settings, replica placement, repair, tombstones, and conflict resolution all affect the observed result.
DynamoDB
Reads can be eventually or strongly consistent within supported scopes. Global Tables replicate across regions asynchronously, so multi-region conflict and failover behavior must be designed separately.
Redis
Primary/replica replication is normally asynchronous. Cluster failover, persistence, the WAIT command, and application-level fencing influence data-loss and consistency windows; a successful command is not automatically a cross-region consensus decision.
A useful architecture review therefore asks, “What guarantee does this exact read or write use in this exact topology?” rather than, “Is this database CP or AP?”
12. CAP Is Not the Whole Story: PACELC
CAP focuses on partition behavior. PACELC adds the trade-off that exists while the network is healthy:
if Partition: choose Availability or Consistency
else: choose Latency or Consistency
P → A / C
E → L / C
Even without a partition, waiting for cross-region agreement improves consistency but increases tail latency. Serving a local replica lowers latency but may expose lag. PACELC is useful because most production time is spent in this “else” path, and users experience those latency decisions every day.
13. How I Think About CAP in Production
I start with the invariant and the failure boundary, not with a database logo. For each operation, I want explicit answers to these questions:
- Can the operation tolerate stale data, and for how long?
- Can we reject or delay it during a partition without causing a worse failure?
- What happens if two regions accept conflicting writes?
- Which record or log is the source of truth?
- How are conflicts detected, ordered, and resolved?
- What happens during failover, promotion, and failback?
- How much replication lag is acceptable to the user and to the recovery objective?
- Does this operation move money, allocate a scarce resource, or create irreversible state?
- Can divergence be repaired asynchronously, and can we prove that repair completed?
- Does the user need strong consistency, or only read-your-own-writes within a session?
The answers shape routing, quorum settings, idempotency boundaries, retry behavior, data models, SLOs, and incident procedures. They also expose where an apparently “available” system merely returns errors at a different layer or where an apparently “consistent” system has an unsafe failover path.
14. Practical Decision Checklist
- Name the operation and invariant.“Update wallet balance exactly once” is actionable; “the payment service is consistent” is not.
- Define the partition response.Reject, queue, serve stale, accept a divergent write, or degrade to read-only.
- Define authority.Leader, quorum, home region, ledger, versioned event log, or another source of truth.
- Bound staleness and recovery.State the allowed lag, repair mechanism, conflict policy, and escalation threshold.
- Test the failure.Inject latency and dropped traffic; exercise retries, elections, split-brain prevention, reconciliation, and client-visible errors.
- Observe the guarantee.Monitor replication lag, quorum failures, stale-read rate, rejected writes, conflicting versions, repair backlog, and failover RPO/RTO.
15. Conclusion
CAP is not a rule for selecting two badges for an architecture diagram. It is a framework for deciding what each operation should do when distributed state cannot be coordinated. Protect consistency where incorrect state would violate a business invariant. Prefer availability where stale or divergent state is bounded, visible, and repairable. Then make the behavior real with replication settings, versioning, idempotency, conflict handling, monitoring, and failure tests.
The senior engineering move is to make those choices per domain and per failure mode—and to document what the user will observe before, during, and after the partition.