Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Conflict Resolution
HLD

Conflict Resolution

When two regions disagree about the truth — strategies from avoidance to CRDTs.

The Inevitable Moment

 multi-master writes meet:

 t=0  EU: cart = {apple}
 t=0  US: cart = {banana}     (same user, racing writes)

 replicas exchange → CONFLICT: which cart is true?
 {apple}? {banana}? {apple, banana}?

 every active-active design either:
 AVOIDS conflicts by routing, RESOLVES them deterministically,
 or DIVERGES silently (the bug you discover in court).

Strategy 1: Avoidance (the best resolution)

 single-writer-per-entity eliminates conflicts by design:

 user's data: only HOME region accepts writes
              others replicate read-only.
 cross-region flows via events/sagas, not dual-writes.

 [EU]──owns user-912──►writes ✓
 [US]──replica─────────►writes REJECTED/routed

 cost: home-region outage blocks those users' writes
       until re-homing/failover. bounded blast radius —
       usually the RIGHT tradeoff.

 most systems should stop here. the rest of this lesson
 is for designs that genuinely can't.

Strategy 2: Deterministic Rules

 when concurrent writes must BOTH apply:

 LAST-WRITE-WINS (LWW):
   keep higher timestamp. 
   ⚠ clock skew lies: EU's slow clock loses real-later writes.
   mitigate with hybrid clocks + skew monitoring;
   accept silent-lost-updates as the semantic.

 DOMAIN RULES (better):
   inventory: MIN(stock) wins (conservative)
   bids:      MAX wins;  balances: never below floor
   settings:  explicit merge policy per field
   
   domain rules encode INTENT — always preferable to
   time-based arbitration when a sensible rule exists.

Strategy 3: Mergeable Types (CRDTs)

 data structures whose states MERGE mathematically,
 order-independently:

 G-Counter: {EU: 5, US: 3} merge = per-node sum → 8 ✓
 LWW-Map:   per-key LWW semantics  
 OR-Set:    add/remove with unique tags; removes win ties

 properties: commutative + associative + idempotent merges
 → all replicas converge to identical state regardless
 of delivery order. no central authority needed.

 limits: works for specific shapes (counters/sets/registers);
 arbitrary relational logic doesn't fit. libraries exist;
 don't hand-roll the math.

Choosing Per Entity Type

EntityConcurrent-write realityChoice
User profilerare, low harmLWW + version UI
Cartadditive mostlymerge-union or home-region
Stock/balancecorrectness-criticalsingle-writer / sync
Presence/countersmergeable naturallyCRDT counters
Documentshuman editingOT/CRDT text engines
 decision tree:
 can one region own it? → route there (done!)
 truly concurrent? → domain rule if expressible
                    → CRDT if shape fits
                    → LWW with eyes open
                    → manual review queue (last resort)

Interview Framing

“Two regions update the same shopping cart simultaneously” scored answer: FIRST offer write-homing as the avoidance design (and why that suffices), THEN demonstrate resolution fluency: LWW-with-clock-caveats, domain-merge for carts specifically, CRDT mention scoped honestly to fitting shapes. Leading with avoidance shows judgment; the fallback taxonomy shows depth. Both together is the complete answer.

My Private Notes

Notes are auto-saved locally to this device.