Menu

Distributed locks are leases: why you need fencing tokens
📰

Distributed locks are leases: why you need fencing tokens

DEV Community: redis·Ayush Soni·3 days ago
#RZEgnYOf
#devtoredis#devto#dev#lock#token
Long article (1079 words) — no AI summary yet.
Reading 0:00
15s threshold

Here's how a distributed lock ends up held by two processes at once, with no bug in the lock itself:

Worker 1 acquires the lock, with a 10-second lease so that a crashed holder can't block everyone forever.

Worker 1 pauses. A long garbage-collection pause, a virtual machine being migrated, a process swapped to disk, a slow network call. Fifteen seconds pass.

The lease expires. Worker 2 acquires the lock and starts its work.

Worker 1 resumes. From its point of view, no time has passed: it holds the lock. It carries on writing.

Two writers, one "exclusive" resource. Martin Kleppmann laid this out clearly in his 2016 essay on distributed locking, and it applies to every lock with a timeout, whichever store implements it: Redis, ZooKeeper, etcd, a database row.

The underlying point: a distributed lock with a timeout is a lease , and a lease can end without its holder finding out in time.…

Continue reading — create a free account

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