Compare

Strong vs Eventual consistency

StrongEvery search asks PRS
BOOK TICKETTomorrow · Tatkal · 1 adult

FromKSR BengaluruSBC

ToNew DelhiNDLS

Searching trains…

App serverasks PRS
PRSone writer
  • 3AAVL 2
  • booked—
  • bookings
EventualSearches read a copy
BOOK TICKETTomorrow · Tatkal · 1 adult

FromKSR BengaluruSBC

ToNew DelhiNDLS

Searching trains…

App serverreads the copy
Copysame as PRS
  • 3AAVL 2
PRSone writer
  • 3AAVL 2
  • booked—
  • bookings

Tatkal at ten: every search asks PRS itself, or reads a copy of the counts that catches up within seconds. Then the last two berths go, and Rajat taps Book. Illustrative counts and times.

Strong or Eventual consistency?

For what people only look at, like a search screen, eventual is fast, and a few seconds old is fine. For anything that decides who gets what, like a booking, it must be strong. That’s why IRCTC can show two left and still waitlist you.

DifferenceStrongEventual
A readAlways the latestMaybe a few seconds old
Its costEvery read reaches the one place that writesReads spread over copies, in milliseconds
After a writeThe next read sees itWrong for a moment, then right
At IRCTCThe booking: one writer per trainThe count a search shows
Pick it forBookings, payments, balances, stockSearch results, counts, feeds, likes

Strong vs Eventual consistency, explained step by step

1. Search at ten

Ten o’clock, and Tatkal opens. Lakhs of people search for the same few berths. On the left, strong consistency: every search asks PRS, the one system that books berths, so the answer is always the latest. On the right, eventual consistency: searches read a copy of the counts, which catches up within a few seconds. Let’s follow Rajat through both.

First, Rajat searches for tomorrow’s Karnataka Express. With strong consistency, his search goes all the way to PRS.

PRS is also booking berths for lakhs of people, so his search waits in the same queue.

Seconds later the answer comes: two berths left in 3A. Right, but slow.

Now the same search with eventual consistency. It reads the copy of the counts instead, and PRS never sees it.

The answer comes back in milliseconds: two berths left. The copy agrees with PRS, because nothing has changed yet.

2. The last two go

Next, Faf and ABD book the last two berths. PRS saves both, and 3A is now full.

Rajat searches again. PRS answers with the latest count: waitlist one. Strong means every read sees the newest write.

With eventual consistency, the copy hasn’t heard about those bookings yet. Rajat searches again, and still sees two berths left.

Within three seconds the update reaches the copy, and it says waitlist one too. Wrong for a moment, then right. That’s eventual.

3. Rajat taps Book

Finally, Rajat taps Book. His screen already said waitlist, so there’s no surprise: PRS gives him waitlist one.

On the eventual side, say he tapped Book in those three seconds, while his screen still said two left.

Bookings never read the copy: they go to PRS, which checks the real count. Rajat gets waitlist one, not a berth someone else already has.

In short

So which should you pick? For what people only look at, like a search screen, eventual is fast, and a few seconds old is fine. For anything that decides who gets what, like a booking, it must be strong. That’s why IRCTC can show two left and still waitlist you.