Locks & Coordination
Making sure exactly one worker does a thing — book this seat, run this job.
Distributed SystemsIntermediate5 hrs4 key ideas · 4 applied designs
0%
your progressOverview
Making sure exactly one worker does a thing — book this seat, run this job.
Key ideas
- Prefer optimistic concurrency (version checks, conditional writes) when conflicts are rare.
- Distributed locks need leases with expiry and fencing tokens, or a paused client can act after losing the lock.
- Seat and room holds are short leases that convert into bookings or expire.
- Schedulers partition work by key so most tasks never contend.
Trade-offs
- Pessimistic locks are simple but serialize throughput.
- Lock services add a dependency that must be as available as the system it protects.
In the real world
Redis SET NX PX (and its caveats)ZooKeeper recipesDynamoDB conditional writes
Keywords
LeasesOptimistic concurrencyFencing