Nguyen Le Phong

Foundations of Software ArchitecturePart 15 of 15

Eventual Consistency Is a Promise About Time

Eventual consistency from the user's side: how stale each feature may be, how the screen should say pending, and how to catch data that never catches up.

A customer messages support: they placed an order, the payment went through, but their points balance still shows the old number. Nothing is down. The order is real, the payment is real, and the points update is probably sitting in a queue a few seconds behind. From the customer's side, though, your app just contradicted itself.

A support teammate and an engineer compare a phone, a laptop and order slips in a back office full of parcels, after a payment went through but the points balance hasn't caught up.
For users, eventual consistency shows up as two parts of the app that are both right, just not at the same moment.

That gap between "true here" and "true everywhere" is what eventual consistency is about. The definition fits in one sentence. The real work is in three questions: how long the gap may last, what people see while it's open, and how you find out when it never closes. Let's take them one at a time.

What the promise actually says

Werner Vogels, Amazon's CTO, wrote the definition most of us still use: if no new updates are made to an item, eventually all reads will return the last updated value (Eventually Consistent, Revisited). He calls the time between a write and the moment every reader sees it the inconsistency window. Without failures, its size depends on communication delays, system load and the number of replicas.

Notice what the definition leaves out: how long "eventually" is. Your database won't decide that for you. Your product has to.

Why put up with the gap at all? In the same essay, Vogels points to the CAP theorem: in a large distributed system, network partitions will happen, so the real choice during one is between consistency and availability. Relax consistency and the system keeps taking requests while the network misbehaves. Insist on it and some requests have to wait or fail. For a loyalty balance, showing points a few seconds late beats refusing the order.

Strong consistency, where every read after a commit sees the new value, is the comfortable option inside one database. Across services, regions, caches and search indexes, it costs latency, coupling and sometimes availability. Managed services put a price tag on it. In DynamoDB, eventually consistent reads are the default and cost half as much as strongly consistent ones, and reads from a global secondary index are always eventually consistent (DynamoDB read consistency). The trade can go the other way, too: in December 2020, Amazon S3 switched to strong read-after-write consistency for all objects at no extra charge (AWS announcement). So eventual consistency is a choice you make for each piece of data. It's neither a badge for fancy architectures nor a flaw to apologize for.

Give every feature a consistency budget

Doug Terry at Microsoft Research made this point with a baseball game. The official scorekeeper, the umpire, a radio reporter and a fan who checks the score once a day all read the same score, and each needs a different guarantee. His conclusion: "Eventual consistency is insufficient for most of the participants, but strong consistency is not needed either" (Replicated Data Consistency Explained Through Baseball).

Your features work the same way. Write a budget down for each one, in words everyone in the room can read:

Feature How stale can it be? What the user sees meanwhile
Payment result before "Order confirmed" Not at all A spinner until the payment service answers
The new order in "My orders" A few seconds The order with a "Processing" label
Loyalty points Under a minute "Points on the way" next to the order
Search results for a new listing A few minutes Nothing special, people expect search to lag a little
Analytics dashboard Hours "Updated 2 hours ago"

The numbers above are examples. Pick your real ones with product and support in the room.

A table like this ends an argument you've probably sat through. Product says users are confused, engineering says the queue is fine, support says tickets keep coming in. Without a budget, nobody can say whether a 40-second delay is healthy or a bug. With one, it's a lookup.

Let the screen say "pending"

If the profile page shows the old balance with no hint that anything is happening, the user reads it as final. Show the new order with a "points on the way" label and the same delay reads as normal. That little label is your consistency model, explained to the user before they have to guess.

In practice it means one more state in your data model. Instead of only success and failure, a reward might look like this:

type RewardStatus = "pending" | "credited" | "needs_review";

Once the state exists, support can see it too. "Your points are pending and usually land within a minute" is a far easier reply than "let me check with engineering."

Hands arrange status cards and tokens on a table, sorting which steps of one customer journey happen right away and which arrive later.
Writing a budget for each step makes it obvious which facts must be instant and which can show up a bit later.

Small guarantees that make lag feel less broken

Some lag nobody notices, and some lag looks like a bug. Vogels lists a few guarantees that sit between strong and plain eventual consistency, and two of them do most of the work for users:

  • Read-your-writes: once you've updated something, you always see your update and never an older value. You change your shipping address and the next page shows the new one, even if another region hasn't caught up yet.
  • Monotonic reads: once you've seen a value, you never see an older one. Refresh and see 120 points, refresh again and see 90 because you hit a stale replica: that's still technically eventually consistent, and it still looks broken.

A few common ways to get there: send a user's reads to the primary for a short while after they write, pin a session to one replica, or have the client send the version it last saw so the server never answers with anything older. You don't need this everywhere. You need it on the screens people open to check their own changes.

Measure the lag, then reconcile

Eventual consistency that nobody watches slides into plain inconsistency: data that was supposed to catch up and never did. A few habits keep that from happening:

  • Know the normal lag of each queue, projection, cache and replica, and alert when it crosses the budget, not only when a process crashes.
  • Make sure a real person looks at the dead-letter queue, and that replaying a message is safe because the consumer is idempotent.
  • Run a reconciliation job that compares the source of truth with its copies: paid orders against invoices, reservations against stock, records against the search index.

Most nights the reconciliation job finds nothing, and that's the point. The night it finds a gap, you fix it before a customer has to report it. If events go missing between the database commit and the message broker, the outbox pattern closes that hole. If a multi-step business process has to undo earlier steps when a later one fails, you're looking at a saga.

An operations teammate and a colleague go through parcels, slips and a laptop in a warehouse back room at dusk, comparing records before the next day starts.
A nightly comparison finds gaps before customers do. Most nights it finds nothing, which is exactly what you want.

Try this week

  • Pick one flow that crosses services and write a budget for each step: how stale it can be and what the user sees meanwhile.
  • Add a pending state to one screen where users see stale data with no hint today.
  • Put the lag of your busiest queue or replica on a dashboard, with an alert at the budget.
  • Find out who checks the dead-letter queue, and when they last did.

For the bigger picture of which service owns which data, read Who Owns the Data? next.

What did you think?

Frequently asked questions

What is eventual consistency?
In Werner Vogels's definition, if no new updates are made to an item, eventually all reads return the last updated value. The time until every reader sees a write is the inconsistency window. Its length depends on network delays, load and the number of replicas, and the definition doesn't say how long it may be. Your product has to decide that.
Is eventual consistency bad for users?
Not if you set a staleness budget per feature and show pending states on screen. Doug Terry's baseball paper at Microsoft Research argues that most readers need something between the two extremes: plain eventual consistency is too weak for them, and strong consistency isn't needed.
What is read-your-writes consistency?
A guarantee that once you've updated something, you always see your own update and never an older value. Common ways to get it are routing a user's reads to the primary for a short while after a write, pinning a session to one replica, or sending the last-seen version with each read.
When do you need strong consistency?
When showing a stale value would break trust: a payment result before saying an order is confirmed, a seat or stock reservation, an account balance after a withdrawal. Many databases let you choose per read. DynamoDB, for example, lets GetItem, Query and Scan set ConsistentRead to true on tables and local secondary indexes, and strongly consistent reads cost twice as much as eventually consistent ones.
How do you monitor eventual consistency in production?
Track the lag of each queue, replica and projection against an agreed budget and alert when it's crossed. Make sure someone reviews the dead-letter queue, keep consumers idempotent so replays are safe, and run a reconciliation job that compares the source of truth with its derived copies.