← Building blocks

Pick consistency or availability under partition

Consistency & coordinationsenior

When nodes cannot talk, do you refuse writes or accept divergent ones?

Say it like this

Under a partition I need the trip record to stay consistent, so that path refuses writes it cannot replicate, while presence stays available and reconciles later.

Basic solution

Decide per feature. Balances and inventory favour consistency (refuse); likes and presence favour availability (accept and reconcile).

CP stores (Spanner, etcd, Zookeeper)AP stores (Cassandra, Dynamo)

One partition, two decisions

During the partition the trip store on the minority side refuses writes (CP) while presence keeps accepting pings on both sides and merges afterwards (AP).

How it works

  1. A network partition is a failure where the network between two groups of replicas stops carrying traffic, so replicas in group A cannot talk to replicas in group B, while clients can still reach at least one of the groups.
  2. A write arrives at a replica on one side. That replica has to answer the client now, without knowing what the other side is doing: it can accept the write and store it locally, or refuse it.
  3. Choosing consistency means the replica checks whether its side still holds a majority of the copies (2 of 3, 3 of 5). If it does not, it refuses the write and usually refuses reads too, returning an error until the partition heals. The result is that no client anywhere can read two different values for the same key.
  4. Choosing availability means replicas on both sides accept writes and store them locally. When the network heals, the two sides exchange what they stored and find keys that were written on both sides. Those conflicts are resolved by a rule: last-writer-wins keeps the version with the newest timestamp and throws the other away, vector clocks reveal which writes were concurrent so the application can merge them, or a domain rule decides (for example, a cart keeps items added on either side).
  5. When there is no partition, the choice does not apply, but a related one does: PACELC says that Else (when the network is fine) you choose between Latency and Consistency. Waiting for a replica to acknowledge before answering the client makes every write slower; not waiting means a replica can briefly serve an older value.

What the theorem does and does not say

  • It only bites while the network is actually partitioned. Partitions are rare in a single data centre, but over years of operation they are certain to happen, so the design must have an answer ready.
  • It is a per-operation decision, not a per-database label. The same store can refuse a trip assignment during a partition while still accepting a presence ping, because those two operations tolerate different failures.

Worked example

Ride matching, one region split from the rest

  • A city runs two zones. A fibre cut separates them for 4 minutes; 2,000 trips are active, 300 match requests arrive per minute. Half of those requests arrive on each side of the cut.
  • Trip assignment chooses consistency: the trip store needs a majority (2 of 3 replicas) to commit, and only zone A has two replicas. The minority zone B refuses new matches, so no driver is assigned twice. Cost: about 150 requests per minute fail with a retry hint for 4 minutes, roughly 600 failed matches, all retried once the cut heals. That is the price of never double-booking a driver.
  • Driver presence and location choose availability: each zone keeps accepting pings and serves its own last-known positions. Riders in zone B see cars that may have moved in the last few minutes; nobody is harmed, and the map corrects itself as soon as pings flow again.
  • Fare calculation after the cut: both zones may have recorded trip events for the same trip (a pickup on one side, a drop-off on the other). The merge rule orders events by their sequence number, not by wall clock, so both sides compute the same fare once they exchange events, regardless of which clock was ahead.
  • Said in the interview: assignment is CP, presence is AP, and the ledger is AP with a deterministic merge.

Variants and when each wins

CP for the operation (majority quorum)

  • Every write waits until a majority of replicas have stored it, and a side without a majority refuses writes during a partition. This wins for money, inventory, assignments and anything with a uniqueness rule, where two accepted conflicting writes would be an incident.

AP with last-writer-wins

  • Every side accepts writes, and when the sides reconnect the version with the newest timestamp is kept and the other is discarded. This is simple and wins for profile fields and preferences, where losing one of two near-simultaneous edits is harmless.

AP with mergeable data (CRDTs)

  • Counters, sets and flags whose merge rule combines both sides without losing anything, such as an add-wins set for a shopping cart. This wins for likes, view counts, presence and carts, but only works for data types that have such a merge rule.

Tunable per request

  • The same store offers both behaviours and each request picks: Cassandra consistency levels, DynamoDB strong vs eventual reads, Postgres synchronous_commit per transaction. This wins when one store holds both kinds of data and you do not want two systems.

Recommendation: list the operations, mark each CP or AP with a reason, and pick a store that can do both per request.

Failure modes

Split brain on the AP path

  • You notice two users who both bought the last item, or one driver with two trips. It happens because an operation with a uniqueness rule was allowed to accept writes on both sides of a partition, and the merge afterwards cannot undo a sale. Move that operation to a quorum write, or give it a single owner so only one side can ever accept it.

Whole system down on the CP path

  • You notice the app returning errors everywhere, including on pages that only read, for the whole length of a partition. It happens because every operation was made CP, including reads that could have tolerated a slightly stale value. Let reads and non-critical writes proceed from the local side, and reserve the majority check for the operations that need it.

Silent data loss on merge

  • You notice a user complaining that an edit they made during an outage has vanished. It happens because last-writer-wins resolved the conflict by keeping the other side's version and discarding theirs, with no record that it did so. Keep both versions and merge at the application level, or model the data as a CRDT so nothing is thrown away.

Latency tax with no partition

  • You notice p99 write latency of 150 ms even on a quiet day. It happens because every write waits for a synchronous acknowledgement from a replica in a far region before answering the client. Replicate synchronously within a region and asynchronously across regions, or pay the cross-region wait only for the operations that are CP.

Wrong mental model of availability

  • You notice a team avoiding a CP store because they believe it is unavailable whenever anything fails. It happens because they are confusing a single node failing with a partition that removes the majority. Point out that a CP store with 3 replicas keeps serving when one node dies; it only stops when it cannot reach a majority.

Interviewer follow-ups

Answer out loud before you open each one.

Is a single Postgres primary CP or AP?

It is CP in the sense that there is one copy of the truth and no divergent writes, but a partition between clients and the primary makes it simply unavailable. With a synchronous replica and automatic failover you keep consistency and regain availability after the failover window; with an async replica you risk losing the last writes on failover, which is an AP-shaped trade.

What does PACELC add?

It says the trade-off also exists when there is no partition: Else, you choose Latency or Consistency. Waiting for a replica acknowledgement on every write buys consistency at the cost of latency, and that cost is paid all day, not only during rare partitions.

Give an operation in a chat app for each side.

Assigning the next sequence number in a conversation is CP, because two messages with the same number would corrupt ordering. Updating typing indicators and last-seen is AP, because a stale or lost update is harmless and the next heartbeat fixes it.

How do you decide which side a feature belongs on?

Ask what happens if two sides accept conflicting writes. If the answer is a refund, a double booking or a corrupted invariant, it is CP. If the answer is a stale number that self-corrects, it is AP. Then ask whether the CP operation can be scoped to one shard so most of the system stays available.

Connections

Pairs with
Tune reads and writes with quorums · Accept a short delay for scale · Agree on one leader or one value · Spread across zones and regions
Pulls against
Commit across two stores