Fencing Tokens and Distributed Locking

In this post I’m gonna share a concept called Fencing Tokens, which I learned from the book Designing Data-Intensive Applications.

Fencing tokens is a mechanism that is used to protect against faulty writes to storage systems that happen in distributed systems.

Let’s take an example. Suppose we have a storage resource (file, DB) and two nodes (A, B) that want write to this storage. Node A acquires the lock to write to this storage from a Lock Service. The Lock Service issues the lock based on a time-lease, which means that a node can have the lock only for fixed amount of time and then it expires. Now Node A has the lock and can start writing, however unfortunately it goes into a Garbage Collection (GC) cycle, at this point Node A has the lock, unresponsive and basically waiting for the GC cycle to finish.

Continue ReadingFencing Tokens and Distributed Locking