Story #38 Eventual Consistency · Read-After-Write Guarantees · Data Integrity

The Confirmation API That Read Yesterday's Balance

"The write succeeded. The read returned the old value. The user submitted again"

An expense platform migrated its reporting API to read from distributed replicas. After a write succeeded on the primary, the confirmation endpoint sometimes returned a stale value from a replica. Users interpreted it as a failed update and submitted duplicate expenses.

What happened

An expense-management company migrated its reporting API to read from geographically distributed database replicas. The write endpoint updated an employee’s available expense balance and returned a success response. The user interface immediately called a separate read endpoint to display the new balance.

The write was committed to the primary database, but replication to the read region took several seconds. The confirmation endpoint sometimes returned the old balance. Users interpreted the stale value as a failed update and submitted the expense again. In other cases, managers approved transactions using outdated totals.

The database team explained that replication lag was expected under the chosen architecture. The actual defect was that the API contract implied immediate read-after-write visibility and gave clients no version token or indication that the read was stale. The product had neither documented eventual-consistency semantics nor a reliable client strategy for handling them.

Root cause

The implementation’s consistency model did not match the contract and user workflow. Writes and reads were tested independently, not as an immediate sequence across primary and replica paths.

The fix

The company introduced a consistency contract, resource version markers, and a read-your-writes path for operations requiring immediate confirmation. Tests now measure propagation delay, verify the documented guarantee, and ensure stale reads are not presented as authoritative confirmations.

Testing gaps and preventive tests

Read-after-write tests, replication-lag simulation, version-marker validation, and tests for documented eventual-consistency behavior. The API contract must state its consistency guarantee explicitly.

Business impact

Duplicate expense submissions, inaccurate approval decisions, and a reconciliation backlog.

Lesson learned

Eventual consistency can be a valid design choice, but it must be an explicit API contract with consumer-safe behavior.

The Confirmation API That Read Yesterday's Balance