Skip to solution
hardSystem Design

What is the difference between strong and eventual consistency?

307 views
01

Understand the problem

Compare consistency models.

consistency
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Strong vs. Eventual Consistency: What Is the Difference?

Target Audience: Junior & Senior Software Engineers preparing for System Design Interviews — no prior system design knowledge assumed. Difficulty: Medium

How to read this doc: Every concept is explained in plain language first. Right after, you'

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Strong vs eventual consistency: replica read simulation
Run Playground
class ReplicatedStore {
  constructor(initialValue) {
    this.primaryValue = initialValue;
    this.replicaLog = {
      replica1: [[0, initialValue]],
      replica2: [[0, initialValue]],
    };
  }

  write(value, replicaArrivalTimes) {
    this.primaryValue = value;
    for (const [replicaId, arrivalTime] of Object.entries(replicaArrivalTimes)) {
      this.replicaLog[replicaId].push([arrivalTime, value]);
    }
  }

  strongRead(now) {
    return this.primaryValue;
  }

  eventualRead(replicaId, now) {
    let latest = this.replicaLog[replicaId][0][1];
    for (const [arrivalTime, value] of this.replicaLog[replicaId]) {
      if (arrivalTime <= now) latest = value;
    }
    return latest;
  }
}

const store = new ReplicatedStore('v0');
store.write('v1', { replica1: 5, replica2: 10 });

console.log('strong_read(t=1):', store.strongRead(1));
console.log('strong_read(t=100):', store.strongRead(100));
console.log('eventual_read(replica1, t=3):', store.eventualRead('replica1', 3));
console.log('eventual_read(replica1, t=6):', store.eventualRead('replica1', 6));
console.log('eventual_read(replica2, t=6):', store.eventualRead('replica2', 6));
console.log('eventual_read(replica2, t=11):', store.eventualRead('replica2', 11));
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 78 of 99 decoded in the System Design track. One more won't hurt.

Back to track