Option 2: Async Replication and the Out-of-Order Problem
Why Entries Arrive Out of Order
Under async replication there is no single sequencer deciding "this happens before that" — each node ships its WAL entries the moment it commits, over a network with variable latency. A packet can queue behind other traffic, take a slower route, or get retried after a drop. The result: the order entries are generated in is not the order they arrive in at a remote node. This is different from the clock-drift problem in the Multi-Master Problem part — HLC already gives every entry a correctly ordered timestamp. The problem here is that a correctly-timestamped entry can still show up late, after the node has already moved on and applied later entries.
Does It Actually Matter? Three Scenarios
Late arrival is only a problem under specific conditions. Walk through when it does and doesn't matter:
| Scenario | Example | Does late arrival matter? |
|---|---|---|
| Different keys | US writes name=hat, India writes city=BOM | No. Each key's value is independent — applying city=BOM late has no effect on name. Order across keys never matters. |
| Same key, causally related | India reads name=hat (already replicated from US), then writes name=hat-red | No. India's write has a strictly higher HLC because it observed the US write first (The Multi-Master Problem's whole point). Applying by highest-timestamp-wins reproduces the correct causal order even if messages arrive late. |
| Same key, concurrent | US writes name=hat and India writes name=sat at nearly the same instant, neither having seen the other's write | Yes — this is the hard case. There is no causal relationship to reconstruct. Whichever one a node applies first is arbitrary, and a second, unrelated local write can land on top before the remote one even arrives. |
The walkthrough below is the third case — the only one that actually requires a resolution strategy (see Conflict Resolution Strategies).
Walking Through the Hard Case
India applies its own log in order: t=100 → "sat", t=110 → "shi". India's database now shows "shi". Then — late — US's entry name="hat" (t=101) finally arrives, after India has already moved past t=101 and committed t=110. From India's point of view, an entry timestamped earlier than what it already applied just showed up.
What The Node Actually Does With It
Two separate questions get answered in two separate steps — conflating them is the usual source of confusion:
- Step 1 — Append to the log. Unconditional, always happens. The moment India receives the entry, it appends
name="hat" (t=101)to the end of its local log, at the log position corresponding to when it arrived — not t=101, which is when it was generated. This is just India durably recording "I received this write." It happens regardless of what the entry contains, how late it is, or what the current state says. Nothing has been decided aboutname's value yet. - Step 2 — Apply to state. Conditional, decided separately. Applying is a distinct operation: look up the current value for key
name— "shi" — and decide whether this newly-appended entry should overwrite it. India does not replay t=100 or t=110 to do this; it only ever compares against the single current value. - The resolution strategy decides step 2's outcome. The comparison ("shi" @ t=110 vs. "hat" @ t=101) is resolved by LWW or vector clocks (see Conflict Resolution Strategies). That decision determines whether "hat" gets applied (overwriting state) or not (state stays "shi", with "hat" surfaced as a conflict) — but either way, the entry is already sitting in the log from step 1, permanently, as a record that it happened.