Start here. This is the direct spoken answer to practice first.
Overview
Uses expected versions and conditional writes so delayed or retried Python tasks cannot commit stale decisions.
A queued task can start after the underlying record has changed, so I include an expected version or transition identity with the work. When the worker writes, it uses a conditional update such as WHERE id = ? AND version = ?. If no row changes, the task is stale and must not overwrite the newer state. Reloading the record without comparing versions is not enough because another update can happen before the write.