Enqueue inside the database transaction or after commit, where do you put it?
Postgres with a Redis backed queue. If I enqueue inside the transaction, a rollback still leaves a job that goes looking for an order that does not exist. If I enqueue after commit, occasionally the process dies in the gap and the job is simply never created, which is worse because it is silent. I have also seen the worker pick the job up before the row is visible and fail on a not-found. Everyone seems to have an opinion here and I would like to hear from people running this in production rather than the theory.
@two_vcpu_club · 6mo ago
The race you described is real and faster than people expect. I instrumented ours after chasing exactly this bug: our workers were picking jobs off Redis in single digit milliseconds, and the transaction that created the row took a good deal longer than that under load because of a trigger nobody remembered writing. So the job genuinely arrived before the data existed, hundreds of times a day, and every one of those became a not-found in the logs that we had learned to ignore. The gap is not theoretical, and it gets worse under exactly the load where you least want mysterious failures.
Reply
Report