Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Multi-Leader Conflicts:
Beyond Last-Write-Wins.

A +180 ms NTP clock skew on an EU-West leader causes older EU writes to overwrite newer US-East updates under Last-Write-Wins (LWW), silently dropping 60 updates/sec.
Start the journey5 stages
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When a single bottleneck threatens end-to-end availability, eliminate LWW silent data loss by replacing physical wall-clock LWW with Hybrid Logical Clocks (HLC) plus Dotted Version Vectors for conflict detection, and use CRDTs (PN-Counter / OR-Set) or per-key home-region routing for concurrent mutations.

TL;DR30-second simplified summary
▾

Core Mechanics: An active-active multi-region platform (US-East, EU-West, AP-South, RTTs 75–180 ms) processes 15,000 writes/sec for shopping carts, feature toggles, and inventory counters.

Visual & Structural Flow: Depicts 3-Region CRDT Convergence Without Coordination (US-East Leader -> EU-West Leader -> AP-South Leader -> Async Anti-Entropy); LWW Silent Drop vs. OR-Set Observed-Dot Convergence (US-East (Dot u1) -> EU-West (Dot e2) -> Async Merge).

Trade-Offs & Production: Running synchronous 2PC or cross-region Paxos/Raft across US-East, EU-West, and AP-South adds 180+ ms RTT to every write and halts availability during WAN partitions. Conflict-free replicated data types power globally distributed active-active systems: Global Shopping Carts & Collaborative Editors: Amazon Dynamo-style OR-Sets and Yjs/Automerge text CRDTs.

Failure Modes & Application: Conflict-free replicated data types power globally distributed active-active systems: Global Shopping Carts & Collaborative Editors: Amazon Dynamo-style OR-Sets and Yjs/Automerge text CRDTs.

Full walkthrough · 5 stages
01
STAGE 01 · WHY IT MATTERSL4 · FUNDAMENTALS

Why Multi-Leader Conflict Resolution & CRDTs Matter.

Why this matters: The mechanism: understand how Why Multi-Leader Conflict Resolution & CRDTs Matter works from first principles.

Think of Why Multi-Leader Conflict Resolution & CRDTs Matter as the intuition layer for Multi-Leader Conflicts: Beyond Last-Write-Wins: The mechanism: understand how Why Multi-Leader Conflict Resolution & CRDTs Matter works from first principles.

An active-active multi-region platform (US-East, EU-West, AP-South, RTTs 75–180 ms) processes 15,000 writes/sec for shopping carts, feature toggles, and inventory counters. Using Last-Write-Wins (LWW) with System.currentTimeMillis() silently drops concurrent cart items and overwrites increments whenever NTP clocks drift during WAN partitions.

02
STAGE 02 · IMPACTL5 · APPLIED DESIGN

Real-World Impact of Wall-Clock LWW.

Why this matters: The problem: see what breaks without Real-World Impact of Wall-Clock LWW under real concurrency or scale.

Physical-clock LWW causes silent data loss in active-active topologies:

  1. Lost Concurrent Updates: Two users (or tabs) adding different items to a shared cart in US-East and EU-West overwrite each other; one item vanishes.
  2. NTP Clock Skew Bias: A region with a 200 ms forward NTP drift permanently wins every LWW tie, dropping valid writes from other regions.
  3. Broken Counters: Concurrent count = count + 1 updates overwrite instead of summing.
Active-Active Multi-Region Replication

3-Region CRDT Convergence Without Coordination

US-East Leader15k w/s local | HLC + CRDTEU-West Leader75ms RTT | OR-Set /…AP-South Leader180ms RTT | DVV conflict75-180ms async

1.PN-Counter: Separate P/N maps per region; merge takes element-wise max().

2.OR-Set (Cart): Observed-Remove Set tags each add with UUID; concurrent add+remove keeps add.

3.HLC + DVV: Hybrid Logical Clocks + Dotted Version Vectors detect true concurrency.

4.Zero WAN Locks: All 3 regions accept local writes during WAN partitions.

State-based CRDTs (PN-Counter, OR-Set) and Dotted Version Vectors guarantee strong eventual consistency across partitioned leaders.

Engineering Decision Framework
Problem
How to implement Multi-Leader Conflicts: Beyond Last-Write-Wins without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When a single bottleneck threatens end-to-end availability, eliminate LWW silent data loss by replacing physical wall-clock LWW with Hybrid Logical Clocks (HLC) plus Dotted Version Vectors for conflict detection, and use CRDTs (PN-Counter / OR-Set) or per-key home-region routing for concurrent mutations.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Multi-Leader Conflicts: Beyond Last-Write-Wins experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · NAIVE SOLUTIONL5 · APPLIED DESIGN

Naive Solution (and Why It Breaks).

Why this matters: The problem: see what breaks without Naive Solution under real concurrency or scale.

Think of Naive Solution (and Why It Breaks) as the intuition layer for Multi-Leader Conflicts: Beyond Last-Write-Wins: The problem: see what breaks without Naive Solution under real concurrency or scale.

Running synchronous 2PC or cross-region Paxos/Raft across US-East, EU-West, and AP-South adds 180+ ms RTT to every write and halts availability during WAN partitions. Conversely, wall-clock LWW (max(timestamp)) silently drops concurrent cart additions and is vulnerable to NTP backward jumps.

Design Trade-Off

Naive Solution (and Why It Breaks)

Before · Async Primary / Split-Brain
  • Stale leader overwrites state
  • Clock skew breaks lease order
  • Full-table sync on reboot
After · Quorum + Monotonic Fencing
  • Majority quorum prevents split-brain
  • Fencing tokens reject zombies
  • Merkle/WAL catch-up in O(log N)
04
STAGE 04 · ENTERPRISE SOLUTIONL6 · SCALE & TRADE-OFFS

Enterprise Solution: Hybrid Logical Clocks, Dotted Version Vectors & CRDTs.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Match the conflict-resolution primitive to each data type:

  • Counters -> PN-Counter CRDT: Maintain per-region increment (P[region]) and decrement (N[region]) vectors. Merging takes max() per region, guaranteeing commutative, associative, idempotent convergence.
  • Shopping Carts -> Observed-Remove Set (OR-Set): Tag every add(item) with a unique (region, seq/uuid) dot; remove(item) only tombstones observed dots so concurrent add + remove never loses a newly added item.
  • Causal Ordering -> HLC + Dotted Version Vectors (DVV): Replace System.currentTimeMillis() with Hybrid Logical Clocks (HLC) for bounded causal ordering, and use DVVs to surface sibling conflicts when human/domain merge is needed.
Concurrent Cart Add + Remove (OR-Set)

LWW Silent Drop vs. OR-Set Observed-Dot Convergence

US-East (Dot u1)EU-West (Dot e2)Async Merge1. add(Shoes, u1) at t=100ms2. add(Hat, e2) at t=105ms (NTP+5ms)3. LWW: drops Shoes! | OR-Set:{Shoes(u1), Hat(e2)}

OR-Set merges keep both concurrent additions regardless of NTP clock skew.

import time

class HLC:
    def __init__(self):
        self.pt = 0
        self.l = 0

    def local_event(self) -> tuple[int, int]:
        wall = int(time.time() * 1000)
        if wall > self.pt:
            self.pt, self.l = wall, 0
        else:
            self.l += 1
        return (self.pt, self.l)

    def receive(self, msg_pt: int, msg_l: int) -> tuple[int, int]:
        wall = int(time.time() * 1000)
        prev_pt = self.pt
        self.pt = max(prev_pt, msg_pt, wall)
        if self.pt == prev_pt == msg_pt:
            self.l = max(self.l, msg_l) + 1
        elif self.pt == prev_pt:
            self.l += 1
        elif self.pt == msg_pt:
            self.l = msg_l + 1
        else:
            self.l = 0
        return (self.pt, self.l)

class PNCounter:
    def __init__(self):
        self.p, self.n = {}, {}
    def inc(self, region: str, val: int = 1):
        self.p[region] = self.p.get(region, 0) + val
    def value(self) -> int:
        return sum(self.p.values()) - sum(self.n.values())
    def merge(self, other: 'PNCounter'):
        for r, v in other.p.items(): self.p[r] = max(self.p.get(r, 0), v)
        for r, v in other.n.items(): self.n[r] = max(self.n.get(r, 0), v)
05
STAGE 05 · SYSTEM DESIGN APPLICATIONSL7 · STAFF / PRINCIPAL

Where CRDTs & Multi-Leader Resolution Apply in System Design.

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Conflict-free replicated data types power globally distributed active-active systems:

  • Global Shopping Carts & Collaborative Editors: Amazon Dynamo-style OR-Sets and Yjs/Automerge text CRDTs.
  • Multi-Region Feature Flags & Counters: Redis Enterprise CRDTs (Active-Active Geo-Distribution).
  • Offline-First Mobile Apps: Local-first state sync across flaky networks.
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does a PN-Counter CRDT merge per-region maps using element-wise `max()` instead of summing or taking a single scalar?

Recommended Learning Flow