~learn.
0:00 / 1:23
W07 · Search system

Search said $120. Checkout said $150. "This is a scam."

transcript

Search says the shoes are 120 dollars. Checkout says 150. The customer's verdict: this is a scam.

At 9, Elasticsearch indexes the Nike Air Max at 120. At 10, PostgreSQL, the source of truth, changes it to 150. A second later, search still says 120. The index is a second copy.

The obvious fix: write PostgreSQL, then Elasticsearch. Two updates race. 100, then 120. PostgreSQL ends at 120. But A's write to search times out. B's write lands. 120. Then A retries. A's old price lands last. Search says 100. Nothing compared versions to stop it.

So the app writes PostgreSQL. Only PostgreSQL. Every change already lands in its write-ahead log. Debezium reads it. Changes go to Kafka, in order, and a pipeline updates the index.

But batches can still retry and reorder. So every write carries a version: the change's LSN. That's its position in the write-ahead log. Later changes, later positions. An older change arrives late? Lower LSN. Rejected. The newer price stays.

Every one of those failures came from the app writing to two places. Write once. Let the database's log tell search.

Full breakdown in the lecture.