March 26, 2024 4 min read A to Z Series: E Home

Eventual Consistency: Read the System Like a Timeline

Eventual consistency means replicas may disagree for a short time, but they converge when updates finish moving through the system.

I do not treat eventual consistency as a license to confuse users. I use it when the business can tolerate read delay, and I recommend making that delay visible in metrics and user experience.

The question is how long eventual takes

When I talk about "The question is how long eventual takes", I am really asking what Eventual Consistency does when a message is late, duplicated, or missing.

A profile picture can take seconds to appear everywhere. A payment status should not drift without a clear pending state. The architecture needs to show what was accepted, what is still propagating, and what users can safely do in the meantime.

Order status example

I use "Order status example" to keep Eventual Consistency grounded in a real system, because abstract patterns are too easy to agree with and too hard to operate.

A customer changes a shipping address. The write succeeds in the account service. Search and notification views update a few seconds later from events.

Reconciliation code

When I show "Reconciliation code", I want the code in Eventual Consistency to reveal the production decision, not just the syntax.

A consumer updates a read model after the source write is complete:

void onAddressChanged(AddressChanged event) {
  searchView.updateAddress(event.customerId(), event.newAddress());
  notificationView.updateAddress(event.customerId(), event.newAddress());
}

The handler updates read models after the source event. The system accepts that search and notification views may lag, but they converge from the same event.

Sequence diagram: a change catches up

a change catches up The source of truth changes first. Other views become correct after they consume the event. sd a change catches up Customer Customer Account API Account API Event Bus Event Bus Search View Search View NotificationView NotificationView Save the new shippingaddress. Publish AddressChangedafter the write commits. Update the searchablecustomer record. Update the email template data.

The source of truth changes first. Other views become correct after they consume the event.

The user promise

Next consistency topics

Written by Arunkumar Ganesan.

What I learnt is that eventual consistency works best when the team names the lag instead of pretending it is invisible.

#DistributedSystems #EventualConsistency #EventDrivenArchitecture #Architecture