Two Writes One Truth

A service writes each new listing to Postgres and then indexes it into Elasticsearch in the same request handler. A few listings per day exist in Postgres but never appear in search. What is the root cause and the durable fix?

A

The indexing call is timing out under load; retry it with exponential backoff until it succeeds

B

The two writes are not atomic, so a crash between them diverges the stores; drive indexing from a transactional outbox

C

The commit ordering is backwards; index into Elasticsearch first and write Postgres only after it acknowledges

D

The Elasticsearch call is not covered by the database transaction; move both calls inside db.transaction so they commit together