Fencing token (distributed lock)
A number that grows with each lock grant; the protected resource rejects writes with an older number, so a stale lock holder cannot do damage.
Distributed locks and leader election make sure one instance runs a scheduled job or an outbox relay. But a lock holder can pause, for a long garbage collection or a network hiccup, lose the lock without knowing, and wake up still writing while a new holder works too. A fencing token closes that gap: each grant gets a higher number and the database or storage refuses writes carrying an old one. Locks built on a cache with timeouts alone do not give this guarantee.
Related terms
- Split-brain: Two parts of a system both believe they hold the truth and accept changes independently, so their data drifts apart.
- Optimistic locking: Detecting conflicting edits with a version number: a save succeeds only if the record has not changed since it was read.
- Transactional outbox: Saving an event to an outbox table in the same database transaction as the change itself, then publishing it to the broker separately.
