AlgoViz

Concurrency in an LLD round

medium 40 min

Sooner or later the interviewer asks what happens when two users do it at the same time.

Watch lesson5:07

Remember it

The few things worth knowing cold, and how to make them stick.

Memory hook

Share, rule, guard, price.

The ice rink: one board and two gates (correctness), a bell at the sharpening bench (coordination), two pairs for three guests (scarcity).

Cheat sheet

Correctness
shared and written: lock
Coordination
waiting: blocking queue
Scarcity
too few: semaphore, pool
Safe already
local, confined, immutable
Gap
decide, then change
Guard
private, beside the data
Slow call
reserve, call, confirm
Event loop
the gap is at the await
Lock reach
one process
Time
ask early, show in verify

Spot it when you see

  • Last one, balance, unique: correctness
  • Worker, background, when ready: coordination
  • Pool, limit, at most: scarcity

Tricks that stick

  • Finger on the field: shared, written, rule, gap, wait.
  • Wrong, waiting, or not enough: that is correctness, coordination, scarcity.
  • If you can say the rule, you know where the lock goes.

Do not forget

  • A concurrent map and two calls
  • A lock only on the way in
  • Calling a network inside the lock
  • Polling with sleep
  • A queue without a limit