Both Writes Succeeded

Two clients update the same key in a system that dual-writes to a primary database and a search index. Nothing crashes. Every call returns success.

time client write to database write to search index
t1 teal X = A ok
t2 red X = B ok
t3 red X = B ok
t4 teal X = A ok

What is the state afterwards, and what fixes it?

A

Wrapping each client's pair of writes in a database transaction fixes it, because the transaction serializes the two clients and forces their writes into the same order at both stores

B

The database holds B and the index holds A, permanently, with no error raised anywhere. Retries cannot help because nothing failed. The fix is to give the writes a single order, by sending them to one log or by capturing the database's own change log, so both stores apply the same sequence

C

The stores converge on B once the index's asynchronous refresh runs, because the index applies writes in commit order regardless of arrival order

D

The database holds B and the index holds A until the next write to X, and making both writes idempotent removes the divergence because replaying either one restores agreement