Skip to content
#0772
Sqlite

Two workers, one job, and a 412

Two workers pick up the same import job. Both read status: pending. Both try to claim it. On most stacks this is where you reach for Redis, advisory locks, or a transaction wrapped around SELECT FOR UPDATE. Here you PUT the new value with ?if_match=pending. The store compares before writing, atomically. One worker gets a 200 and owns the job. The other gets 412 Precondition Failed and moves on.

No lock service, no retry loop around a transaction, no second database whose only job is coordination. Compare-and-swap is a property of every key in the store: sessions, counters, config, cron leases. The failure mode you used to architect around became a status code.

The lock is a query parameter.