Log inBook a Demo
BuildSeniorBackendAuto-graded

Fix a lock that lets two workers in

Two workers ran the nightly billing job at the same time. Make sure the lock only ever lets one in.Two workers ran the nightly billing job at the same time and double-charged a batch of customers. The lock in lock.py should let one worker in at a time, and it doesn't: a crashed holder never loses the lock, a second worker gets in while the first still holds it, and anyone can release anyone's lock. Rework DistributedLock so it grants leases with a TTL and a unique token, and reads time only through the injected now clock.
45 min
python

You're done when

  • While the lock is held, another caller is refused.
  • The lease expires after its TTL, so a holder that dies can't block the lock forever.
  • Releasing with the wrong token fails and the lock stays held.
  • After a new holder takes over an expired lease, the lock is theirs and the old holder's token can't release it.

What it measures

Distributed data processingKeeping the lock working when a holder disappears without releasing it.
Resilience engineeringHow the lease and the tokens stop a crashed or confused worker from breaking the lock.
Reasoning about concurrencyWhether two workers can ever hold the same key at once, including right around expiry.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

45 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo