Replication, partitioning and consistency
Copies buy availability and read scale, partitions buy write scale, and both cost you some form of consistency.
Replication
Single-leader replication is the default: one writer, followers for reads and failover. Synchronous followers protect against data loss at the cost of write latency; asynchronous ones are fast but can lose the last few writes on failover. Multi-leader and leaderless (quorum) designs accept writes in several places and must resolve conflicts, which is a product decision as much as a technical one.
Partitioning
Partition by a key that spreads load and keeps related data together. Hash partitioning spreads load but kills range scans; range partitioning keeps scans but invites hot spots on monotonically increasing keys like timestamps. The partition key is usually the most expensive decision in the design to reverse; say so.
Consistency, in the words interviewers use
| Guarantee | Means | Typical cost |
|---|---|---|
| Linearisable | Every read sees the latest write, as if there were one copy | Coordination on every write; unavailable during some partitions (CAP) |
| Read-your-writes | A user sees their own updates | Route the user's reads to the leader or a caught-up replica for a while |
| Monotonic reads | A user never sees time go backwards | Sticky routing to one replica |
| Eventual | Replicas converge if writes stop | Cheap; the application must tolerate stale reads |
PACELC is the more useful framing than CAP alone: under a Partition choose Availability or Consistency; Else, choose Latency or Consistency. Most real trade-offs are in the "else" branch.
Practice
Written for this site to drill the lesson. Not reported interview questions.
- A global SaaS product must keep EU customer data in the EU. Sketch the partitioning and replication scheme and what happens to a user who travels.
- Explain why a timestamp is a poor partition key for an events table and propose two alternatives.
- Design the read path for a profile page that must show a user their own edits immediately but can show other users' edits a few seconds late.
Check yourself
What does PACELC add to CAP?
Even without a partition, you trade latency against consistency.
Why is the partition key a high-stakes decision?
It decides load spread and which operations stay local, and changing it means re-partitioning all the data.