Distributed Systems · Agreeing and coordinating
Distributed locks
A distributed lock lets one machine at a time do a job. Every such lock is a lease that can expire under a paused holder, so the protected resource must reject stale holders using fencing tokens.
- Time25 min
- LevelSenior
- Pictures11 diagrams
- Check6 questions






Worker 1 acquires gets a 10-second lease and fencing token 33.
Worker 1 wakes unaware of the pause, it writes with token 33.
Storage refuses it has already seen 34, so token 33 is rejected.
Idempotent work running it twice does no harm, so an overlap costs nothing.
One owner per key route each account to one worker, so nobody competes.
Database row lock the database you already trust serializes the writes.