Contention: two buyers, one seat
Whenever two users can try to take the same scarce thing at the same time, the design needs an explicit answer to who wins, and the answer is almost always an atomic conditional write in one database rather than a distributed lock.
What you'll be able to do
- Demonstrate the read-check-write race and fix it with an atomic conditional update or a version check
- Choose between pessimistic locks, optimistic concurrency and isolation levels, and avoid deadlock with lock ordering
- Design a time-limited reservation so a user can hold an item while they pay
- Explain why a distributed lock needs a fencing token, and handle a single extremely hot item
Before this: picking-a-datastore, replication-and-consistency
Log in to read the rest of this lesson
Whenever two users can try to take the same scarce thing at the same time, the design needs an explicit answer to who wins, and the answer is almost always an atomic conditional write in one database rather than a distributed lock. This walkthrough runs about 24 minutes, with runnable code you can edit and re-run as you read. A new account gets 7 days of Pro free, no card required.
Log in to continueThe first module of every track is free to read on the web: see what's open in System design.