SystemExpertsSystemExperts
Pricing

Patterns

35 items

Horizontal Scaling Pattern

15mbeginner

Retry with Backoff Pattern

15mbeginner

Queue-based Load Leveling Pattern

20mintermediate

Replication Pattern

25mintermediate

Caching Strategies Pattern

25mintermediate

Fan-out Pattern

20mintermediate

Fan-in Pattern

20mintermediate

Persistent Connections Pattern

20mintermediate

Load Balancing Pattern

20mintermediate

Circuit Breaker Pattern

20mintermediate

Bloom Filters Pattern

20mintermediate

Time-Series Storage Pattern

20mintermediate

Bulkhead Pattern

20mintermediate

Batch Processing Pattern

20mintermediate

Write-Ahead Log Pattern

20mintermediate

API Gateway Pattern

20mintermediate

Backend for Frontend Pattern

20mintermediate

Sidecar Pattern

20mintermediate

Idempotency Pattern

20mintermediate

Rate Limiting Pattern

20mintermediate

Backpressure Pattern

20mintermediate

Pub/Sub Pattern

25mintermediate

Eventual Consistency Pattern

25mintermediate

Sharding Pattern

25madvanced

Conflict Resolution Pattern

25madvanced

Strong Consistency Pattern

30madvanced

Leader Election Pattern

25madvanced

Consensus Protocols Pattern

30madvanced

Stream Processing Pattern

25madvanced

Change Data Capture Pattern

25madvanced

Distributed Locking Pattern

25madvanced

Two-Phase Commit Pattern

25madvanced

LSM Trees Pattern

25madvanced

Event Sourcing Pattern

30madvanced

CQRS Pattern

28madvanced
System Design Pattern
Consistencyconflict-resolutionlwwcrdtvector-clocksmergeadvanced

Conflict Resolution Pattern

Handling concurrent updates in distributed systems

Used in: Collaborative Editing, Multi-region DBs, Offline Apps|25 min read

Summary

Conflict resolution handles the situation when multiple writers update the same data concurrently in distributed systems. Without coordination, concurrent writes can cause data loss or inconsistency. Strategies include: Last-Write-Wins (simple but lossy), application-level merge (custom logic), CRDTs (mathematically guaranteed convergence), and operational transforms (used by Google Docs). The right strategy depends on your data semantics - counters can use CRDTs, documents need operational transforms, and shopping carts can merge sets. This pattern is essential for any system with multiple writers, including multi-region databases, offline-capable apps, and collaborative editing.

Key Takeaways

Concurrent Writes Are Inevitable

In distributed systems, writes can happen simultaneously on different nodes. Network partitions mean nodes can't always coordinate. You must handle conflicting writes - the question is how.

Last-Write-Wins is Lossy

Using timestamps to pick 'latest' write is simple but discards data. If user A adds item and user B changes quantity simultaneously, one change is lost. Acceptable for some data, dangerous for others.

CRDTs Guarantee Convergence

Conflict-free Replicated Data Types are data structures that mathematically guarantee all replicas converge to same state. No coordination needed. Used by Redis, Riak, and collaborative apps.

Scenario: Multi-region database

  1. User in US updates profile: `name = "Alice"`
  2. User in EU updates profile: `name = "Alicia"` (same user, different device)
  3. Both writes happen during network partition
  4. When partition heals, which value wins?

Without conflict resolution: - Arbitrary winner based on arrival order - Or database rejects one write (unavailable) - Or data becomes inconsistent across regions

Concurrent Write Conflict

Summary

Conflict resolution handles the situation when multiple writers update the same data concurrently in distributed systems. Without coordination, concurrent writes can cause data loss or inconsistency. Strategies include: Last-Write-Wins (simple but lossy), application-level merge (custom logic), CRDTs (mathematically guaranteed convergence), and operational transforms (used by Google Docs). The right strategy depends on your data semantics - counters can use CRDTs, documents need operational transforms, and shopping carts can merge sets. This pattern is essential for any system with multiple writers, including multi-region databases, offline-capable apps, and collaborative editing.

Key Takeaways

Concurrent Writes Are Inevitable

In distributed systems, writes can happen simultaneously on different nodes. Network partitions mean nodes can't always coordinate. You must handle conflicting writes - the question is how.

Last-Write-Wins is Lossy

Using timestamps to pick 'latest' write is simple but discards data. If user A adds item and user B changes quantity simultaneously, one change is lost. Acceptable for some data, dangerous for others.

CRDTs Guarantee Convergence

Conflict-free Replicated Data Types are data structures that mathematically guarantee all replicas converge to same state. No coordination needed. Used by Redis, Riak, and collaborative apps.

Operational Transforms for Documents

OT transforms concurrent operations to apply cleanly. If user A inserts at position 5 and user B deletes at position 3, OT adjusts A's position to 4. Powers Google Docs and real-time collaboration.

Application Semantics Matter

Best resolution strategy depends on data meaning. Shopping cart: merge items (union). Counter: sum values (add-only). User profile: per-field merge. One size does not fit all.

Detect Before Resolve

Use vector clocks or version vectors to detect conflicts. Only resolve when actual conflict detected. Most writes don't conflict - optimize for the common case.

Pattern Details

Scenario: Multi-region database

  1. User in US updates profile: `name = "Alice"`
  2. User in EU updates profile: `name = "Alicia"` (same user, different device)
  3. Both writes happen during network partition
  4. When partition heals, which value wins?

Without conflict resolution: - Arbitrary winner based on arrival order - Or database rejects one write (unavailable) - Or data becomes inconsistent across regions

Concurrent Write Conflict

Trade-offs

AspectAdvantageDisadvantage

Premium Content

Sign in to access this content or upgrade for full access.