Part 7 of the eight-part How Backend Systems Scale series. Keep the separate powers-of-ten estimation reference nearby for the calculations.
You upload a photo. The application confirms that it saved. You refresh your profile, and the photo is missing.
A moment later, it appears.
One possible explanation is that the save and the refresh reached different database copies. The first copy knew about the write. The second hadn’t applied it yet.
Keeping copies sounds like a way to make data safer and reads faster. It also creates a question that a single copy didn’t ask: which version is this operation allowed to observe?
On this page
- Follow a write through leader and replicas
- Why multi-leader writes are tempting
- Trace a quorum read through real versions
- Use the word consistency precisely
- Reason about conflicting copies and partitions
Follow a write through leader and replicas
Copying takes time
In a single-leader design, the leader accepts writes and sends changes to replicas. Reads may go to the leader or a replica according to the application’s routing rules:
This copying process is replication. It can support availability, read capacity, and geographic placement. It doesn’t make the copying instantaneous.
An example timeline
| Time | Event |
|---|---|
| 0 ms | Leader commits the new photo record |
| 10 ms | Client receives success |
| 30 ms | Profile read reaches a replica that has not applied the record |
| 80 ms | Replica applies the record |
The values are invented to illustrate ordering. The replica can’t return a record it hasn’t applied. Waiting a fixed number of milliseconds isn’t a general solution because lag changes with load and failures.
When should the writer receive success?
We can change when the leader acknowledges a write:
| Mode | Typical acknowledgment point | Trade-off |
|---|---|---|
| Asynchronous | Leader completes its required local work | Lower waiting time, but a promoted replica may lack recent acknowledged writes |
| Synchronous | Required replicas reach a configured acknowledgment stage | More waiting and dependency on replica availability |
“Replicated” can mean received, durably stored, or applied for queries. Those stages have different consequences.
Waiting for durable storage on a required replica can protect the commit without making it readable on every replica. Waiting for application of that commit addresses a later stage. PostgreSQL’s commit settings make this distinction explicit.
Match the read to the promise
For the person who just uploaded a photo, seeing their own saved change is a reasonable expectation. This is read-your-writes behavior.
Several designs can help:
| Approach | How it helps | Limitation |
|---|---|---|
| Read the leader | Use the node that accepted the change | More leader load; failover still needs correct routing |
| Wait for a replication position | Ensure the chosen replica has applied the required change | Needs database support and a bounded wait policy |
| Return the created data | Update the screen using the write response | Helps that screen, not every later read or another device |
| Temporarily route a user’s reads to the leader | Covers a period after a write | A fixed duration alone does not prove a replica caught up |
Returning the created data helps that screen but doesn’t settle every later read. Temporarily routing to the leader can help, but a fixed timer alone doesn’t prove a replica caught up.
The right choice depends on the operation. An approximate public view count can tolerate different freshness from an authoritative inventory reservation.
Failover is a controlled change of authority
If the leader fails, another node may be able to take over. A safe procedure needs to:
- Detect the unavailable leader.
- Choose a suitable replica.
- Promote it under the database’s failover protocol.
- Route clients to it.
- Prevent the former leader from accepting conflicting writes if it returns.
The final step protects our assumption that one node has write authority. Changing an address without controlling the old writer doesn’t establish that guarantee.
Replicas are not backups
A mistaken deletion can travel to every replica. Extra current copies and recoverable history solve different problems:
- Replicas help availability and appropriate read workloads.
- Backups preserve historical states.
- Restore tests show whether the recovery procedure works.
Use the protections required by the failures you’re trying to survive.
Estimate the replication stream
At 10^3 writes per second and roughly 10^3 bytes of change per write, the payload estimate is 10^6 bytes per second per replica.
Logs, indexes, transaction overhead, and bursts can increase the actual traffic. This calculation is an initial estimate to replace with measurements of the replication stream.
A cache doesn’t automatically fix lag either. It can load an already stale value from a replica and keep returning it after that replica catches up.
Why multi-leader writes are tempting
Suppose users edit captions in North America and Asia. A single distant leader makes one region’s writes cross a long network path. A local writable leader could shorten that path and accept some work while regions can’t communicate.
This changes who may accept a write:
| Design | Who accepts writes? | Main challenge |
|---|---|---|
| Single leader | One designated leader for the data | Failover and lag |
| Multiple leaders | More than one leader | Conflicting concurrent changes |
| Leaderless | Clients or coordinators contact several replicas | Version reconciliation and partial failures |
These patterns describe ownership of particular data. A sharded system can have many leaders overall and still use one leader per shard.
Now let both regions edit the same caption:
- Both begin with “Morning walk.”
- One writes “Morning walk with friends.”
- The other writes “A rainy morning walk.”
- Communication resumes and the two changes meet.
We need a policy for the conflict:
| Policy | What it does | Cost |
|---|---|---|
| Last write wins | Keep one value according to a defined ordering | Can discard a valid edit; clock assumptions matter |
| Keep both versions | Preserve the conflict for resolution | Someone must merge or choose |
| Application-specific merge | Combine operations where semantics permit | Requires a suitable data model |
| Assign one writer per object | Route changes to a single authority for that object | Some writes still travel or become unavailable |
Labeling timestamps as UTC doesn’t ensure clocks agree or tell us which edit the product should keep. Last-write-wins chooses one value according to its ordering rule; that can discard a valid edit.
Even a counter needs care. If two regions both read ten and write eleven, choosing either final value loses one increment. An operation-aware counter or suitable mergeable structure can preserve independent increments under its assumptions. It doesn’t follow that the same merge works for captions or last-ticket reservations.
That is why conflict resolution belongs to the application semantics, not only to the replication configuration.
Trace a quorum read through real versions
Could we accept writes without designating one leader? A client or coordinator could contact several replicas and wait for a required number of acknowledgments.
Suppose a key has a fixed replica set A, B, and C:
N = 3is the replica count.W = 2is the number required to acknowledge a write.R = 2is the number required to respond to a read.
All copies start at version 1. A completed write stores version 2 on A and B; C hasn’t received it:
| Replica | Stored version after the write |
|---|---|
| A | 2 |
| B | 2 |
| C | 1 |
List every possible two-member read set:
- A and B return version 2 from both.
- A and C return versions 2 and 1.
- B and C return versions 2 and 1.
Each read set intersects the completed write set. The arithmetic is R + W > N for the same fixed set of replicas.
The overlap exposes the new version. It doesn’t choose it for us. Returning whichever reply arrived first could still return version 1.
Our simple trace assumes one completed write and an appropriate version-selection rule. A complete protocol must also define:
- Ordering or reconciliation of concurrent writes.
- Partial writes from failed or timed-out operations.
- Behavior when substitute replicas are used.
- Version selection and repair.
Read quorums aren’t a majority vote on the payload. The relevant version may appear on only one member of the read set, and overlap alone doesn’t prove linearizability.
Compare configurations and failure tolerance
| N | W | R | Practical consequence under the fixed-set model |
|---|---|---|---|
| 3 | 2 | 2 | Reads and writes each require two available replicas; their sets overlap |
| 3 | 3 | 1 | A read needs one replica, but a write needs all three |
| 3 | 1 | 3 | A write needs one replica, but a read needs all three |
| 3 | 1 | 1 | Read and write sets can be disjoint |
The acknowledgment count lets us reason about availability under the fixed-set model:
- A write can tolerate up to
N − Wunavailable replicas for that count. - A read can tolerate up to
N − Rfor its response count. - Reachability, correctness, and latency still depend on the actual protocol.
With N = 3, W = 1, R = 3, collecting all read replies can expose the single written copy in our simple trace. Losing one replica prevents collecting those three replies.
With W = 1, R = 1, the read can reach a different copy from the acknowledged write. There is no required overlap.
What happens to an old copy?
A protocol also needs to bring copies back into agreement:
- Read repair detects an older version during a read and arranges an update.
- Background repair compares and reconciles replicas outside foreground reads.
A timed-out write may already have changed some copies. As with checkout in chapter one, the missing success reply doesn’t establish that nothing happened.
The original Dynamo paper describes one leaderless design, including versioning and failure handling. It doesn’t establish the architecture or guarantees of every later database with a similar name.
Use the word consistency precisely
Our examples have asked several different questions about visibility and ordering. Giving those questions distinct names avoids promising too much:
| Guarantee | Reader’s question |
|---|---|
| Eventual consistency | If updates stop and communication and repair succeed, do replicas converge? |
| Read-your-writes | Can I observe my own acknowledged update in later reads? |
| Linearizability | Does each operation appear to take effect on one current copy, respecting real-time ordering? |
| Transaction isolation | What interactions can concurrent transactions observe? |
Read-your-writes doesn’t imply global linearizability. Two users can each see their own writes without all operations behaving like one current copy. Transaction isolation is another dimension: it describes interactions between concurrent transactions.
When choosing a read path, state the particular guarantee the operation needs rather than say only that it must be “consistent.”
Reason about conflicting copies and partitions
Now break communication between two regions. Customers can still reach their local nodes, but the nodes can’t coordinate with the other region.
This is a network partition. During such a partition, an asynchronous distributed system cannot guarantee both:
- Linearizable consistency: operations appear to use one current copy, respecting real-time ordering.
- Availability in CAP’s sense: every request received by a non-failing node eventually completes successfully under the model.
This is more specific than ordinary uptime or a latency objective. Gilbert and Lynch’s paper states the formal result.
The product consequence depends on the operation:
| Operation | Possible decision during isolation | User-visible effect |
|---|---|---|
| Reserve the last ticket | Reject or delay writes where safe authority cannot be established | Some customers cannot buy temporarily |
| Accept a photo like | Accept locally with a suitable reconciliation design | Counts may differ temporarily |
The usual labels describe priorities under that condition:
- CP: preserve the consistency guarantee by declining work that can’t be coordinated safely; some requests become unavailable.
- AP: keep accepting the relevant operations on reachable nodes with an appropriate reconciliation model; the same immediate consistency guarantee isn’t retained.
- CA: describes a model excluding partitions, not a deployment technique that prevents networks from partitioning.
Saying “the product is AP” hides the choices we need to make. A photo like and the reservation of the last ticket can require different behavior during the same regional failure.
For the missing photo at the start, replica lag suggested a suitable read path. For the last ticket, a partition may require declining a write. Both decisions become clearer when we describe what the user is allowed to observe and what the system must preserve.
Previous: Caching from First Principles: Policies, LRU, and Cache Tiers. Next: Sharding and System Design: Placement, Movement, and Trade-offs.