Eventual consistency

What it is

Eventual consistency describes a system in which separate copies may
temporarily disagree and are expected to converge after updates stop
and the changes have been delivered and reconciled. A client can see
an older state from one replica even after another replica has
acknowledged a write. Different implementations offer different
ordering, read or conflict-resolution guarantees on the way to
convergence. The name alone gives no time bound for when a reader is
guaranteed to see a particular update.

Consider a replicated product profile. A person changes its
description in one region. A second reader can still see the
previous description while the update travels to an outlying region.
At this point both answers can be normal for the chosen read
contract. A different problem appears when two people change the
same field independently. Propagation cannot settle which result to
keep without a rule for reconciling the changes. A system could
select a winner, merge operations according to their meaning or
expose conflicts for the application to resolve. A rule that
converges mathematically can still discard a change that people care
about.

The original Amazon Dynamo paper provides one concrete design for
availability and reconciliation in a distributed key-value store.
Its choices should be read as choices of that system. Current
products may expose several models. An eventually consistent read
option in a managed database and a replicated shopping workflow have
different boundaries. Be explicit about which objects, client
sessions, regions and operations a promise covers.

Why it matters

Waiting for more coordination can improve the guarantee a reader
receives. It can also add latency or reduce the ability to complete
the operation while parts of a distributed system cannot reach one
another. When an application can use an older version safely,
letting a nearby replica answer may improve responsiveness. The
application needs a stronger boundary for decisions that cannot
tolerate obsolete data. A customer can often browse a slightly old
product description. Reserving the last item for two different
purchasers at the same time breaks a business rule.

User experience needs to represent the delay honestly. Someone who
changes a profile and sees the old version appear on the next screen
may believe their update was lost. Some systems provide a session
guarantee, a version token or another way to read one's own writes.
Keep that state when moving between service instances, or show the
confirmed write result while an asynchronous read model catches up.
A statement about a database's storage model cannot substitute for a
clear service response.

Consistency also matters for reporting. A dashboard that joins
several replicated tables may show today’s data in one panel
alongside a related table that has yet to update. If an accounting
reader needs a coherent numbered export, build the report from a
well-defined snapshot and label its time boundary. It is helpful to
distinguish the timestamp of the source event, the time the derived
view incorporated it, and the time a user downloaded the report.

What it looks like in practice

Suppose a shop keeps a search index for browsing and a transactional
store for reservations. A new product description can be indexed
after the source transaction commits. The catalogue can display an
older description briefly. The purchase workflow, however, asks the
transactional store to check and reserve stock. If the search result
claims that an item is available and the reservation fails, the
customer sees a direct response from the authoritative operation. No
promise of inventory ownership is made at the display layer.

To test this split, send an intentionally delayed catalogue event
and verify that the reservation boundary still behaves correctly.
Send two updates for the same product in reverse order and observe
that the older one does not overwrite the new description. The test
needs identifiers or sequence information that the system actually
uses to order updates. Restart the indexing consumer and verify that
reprocessing an event preserves the intended final state. Then
introduce genuine concurrent writes to the same field and exercise
the agreed merge policy.

Measure how long updates take to appear and report both typical lag
and the oldest work waiting. A process can be healthy while it is
consuming yesterday's backlog. Give operators a way to inspect a
specific product version across the primary and the derived view.
That comparison can distinguish ingestion delay, a stuck consumer
and an update that was accidentally applied out of order.

Our engineering note on selling limited stock without overselling
describes keeping the stock invariant inside a guarded transaction
and using explicit holds. The search scenario is illustrative. It
shows why an eventually updated presentation can coexist with a
tightly controlled purchasing decision. The same approach works when
a report can lag but an action based on that report still has to be
authorised and checked against current state.

Where it goes wrong

Application code may assume a short propagation delay will always be
enough. A timer that happens to work in one test can fail during an
incident or a large backlog. Use a version or a documented
consistency contract when an operation needs specific data. Where
freshness can vary, surface the data's age and build a deliberate
path for readers whose decision cannot wait.

Last-writer-wins style conflict resolution is easy to explain until
timestamps are wrong or the fields carry independent information.
Two clients editing different attributes might each write a full
record and discard the other change. Choose the update primitive
that matches the domain. Compare identities or versions before
overwriting state, and test the resolution rule with separate
clients that cannot see one another's writes at the time they act.

A derived view can stop converging entirely because a subscriber
skipped an invalid record, an event expired or a rebuild changed the
order of operations. Introduce realistic disconnects and replay
cases in a test environment. Retain enough history to rebuild within
the recovery budget and define how to detect that the derived store
has reached the authoritative state. Treat a measurable, repeatable
recovery path as part of the consistency design.

Further reading

  * Amazon Dynamo research paper describes a production design that
reconciles versions across distributed replicas.

  * DynamoDB read consistency defines the product's read options and
their scope.

  * Azure Cosmos DB consistency levels describes the different
guarantees clients can choose.

hThis page on the web	URL:https://engineer.company/glossary/eventual-consistency/	engineer.company	70
