Menu

A Distributed Lock Is Just a UNIQUE Constraint
πŸ“°

A Distributed Lock Is Just a UNIQUE Constraint

DEV Community: backendΒ·Rishi Kant RanaΒ·7 days ago
#wX6FLih2
#devtobackend#devto#dev#mutex#lock_name
Long article (1000 words) β€” no AI summary yet.
Reading 0:00
15s threshold

Every backend eventually needs the same primitive: run this job on exactly one

instance at a time. A nightly report. A poller that shouldn't fire twice. A

reconciliation job that would corrupt data if two copies raced each other. The

need is boring and universal β€” which is exactly why it's strange how heavy the

usual answers are.

ZooKeeper / Consul / etcd β€” a whole coordination service to run, monitor, and page someone about, just so a job doesn't double-fire.

Redis Redlock β€” a new dependency, and its correctness under partition and clock skew has been debated in public for years.

SELECT ... FOR UPDATE β€” fine for a lock held for one transaction. Wrong shape for "hold this for the next 20 minutes" β€” it blocks other queries and a hung connection holds the lock forever.

If you already run Postgres or MySQL, none of that is necessary.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.