Concurrency, Locking & Distributed Locks

Race conditions, optimistic vs pessimistic locking, atomic ops, Redis/etcd locks, fencing tokens and deadlocks — the bugs that only show up at 3 AM under load.

About 110 minutes · 15 exam questions · 9 interview questions · 2 code labs

What you will learn

  1. Race conditions: check-then-act and read-modify-write
  2. Concurrency inside one Node process: the event loop is not a mutex
  3. Optimistic locking: version columns and compare-and-set
  4. Pessimistic locking: SELECT ... FOR UPDATE, NOWAIT, SKIP LOCKED
  5. Atomic operations & CAS: let the storage enforce the invariant
  6. Duplicates: unique constraints and idempotency keys
  7. Distributed locks with Redis: SET NX PX and safe release
  8. Redlock, fencing tokens and consensus-backed leases (etcd/ZooKeeper)
  9. Producer-consumer, worker pools and SKIP LOCKED queues
  10. Deadlocks: detection, prevention and retry
  11. Scenario playbook: the seven concurrency incidents interviewers love

Previous: Idempotency, Distributed Transactions, 2PC & Sagas · Next: Data Systems Theory: System Models, Ordering, Encoding & Derived Data