System Design: Mutual Exclusion on Distributed Systems

Scenario: x = 10. At a moment, machine A executes “x *= 10” while machine B executes “x +=10”. Either x=110 or x = 200 is correct. Unfortunately, x = 100 or x = 20 will be the result without coordination between A and B.

Solution1-Centralized Coordinator: C is the manager and only grants permission to one machine at a time. Everything is good except that C is the bottle-neck on performance and failures.

Solution2-Token Ring. Machines are linked up as one cycle/ring. A token(permission) is passed along the ring. Machine i acquires permission by waiting for the token arrival from its left node(i-1). Machine i release permission by passing the token to its right node(i+1). The good is no one-point failure in this model. But it requires O(n) messaging transmittion.

Solution3-Lamport’s Bakery Algorithm: please see wiki.

Leave a comment