Skip to main content

Distributed Locking

Difficulty: Medium | Topic #17

What to Learn​

Why distributed locks are needed, Redis-based locks (SET NX EX), Redlock algorithm, fencing tokens to handle lock expiry races, lock contention and its impact on throughput.

Resources​

Covered by Problems​

ProblemDifficultyLink
Ticketing System (Ticketmaster)Medium→
Online AuctionMedium→
Job SchedulerMedium→
Online ChessHard→

Key Concepts to Master​

  • Why network partitions make distributed locking hard
  • Redis SET NX EX for simple single-node locks
  • Redlock algorithm across 5 nodes for higher correctness
  • Fencing tokens to prevent stale lock holder actions
  • Lock-free alternatives (optimistic locking, CAS) as a performance improvement