37. Reservation with a TTL, and a Unique Constraint
Scarce inventory — a seat, a room, the last unit — with far more buyers than units. Holding a database row for the minutes someone takes to pay does not scale, and checking availability before writing is a race that sells the same seat twice.
The brief
Reservation with a TTL, and a Unique Constraint. Scarce inventory — a seat, a room, the last unit — with far more buyers than units. Holding a database row for the minutes someone takes to pay does not scale, and checking availability before writing is a race that sells the same seat twice. Work from the scoping questions below. State assumptions for any unspecified load, guarantee or target, then trace your design end to end. Explain one difficult case and a credible alternative; the worked example is a reference, not a required implementation.
- Set the scope: What is the scarce item, and may it ever be reserved twice? How long does a reservation remain valid?
- Define the contract: What happens when payment completes near the expiry boundary? Can the same caller retry or extend a reservation?
- Test the boundaries: How is an expired reservation released after a worker outage?
Constraints
- Explicit scope and guarantees
- Resolve the scoping questions for Reservation with a TTL, and a Unique Constraint. Separate stated behavior from assumptions, and identify what is outside your design.
- Supported operating targets
- Declare relevant volume, latency, freshness, quality or cost targets with units. Show calculations or an evaluation plan that can test them; unspecified targets are your assumptions, not hidden pass criteria.
- Failure and boundary behavior
- Explain how your guarantees hold in a difficult case relevant to this subject. Address: Can the same caller retry or extend a reservation? How is an expired reservation released after a worker outage?
What to cover
- 01
Scope and behavior contract
Identify users, required behavior and exclusions. Answer: What is the scarce item, and may it ever be reserved twice? How long does a reservation remain valid?
- 02
State and interfaces
Define the information owned by the system and the inputs, outputs and errors at its boundaries. Resolve: What happens when payment completes near the expiry boundary? Can the same caller retry or extend a reservation?
- 03
Capacity and operating targets
Estimate the dominant workload and resource demand with units and explicit assumptions. For a learned system, also state how quality is measured and what data is available.
- 04
Architecture and central flow
Draw or describe the responsibilities needed for Reservation with a TTL, and a Unique Constraint. Trace a representative request, event or job from its input to a visible result; identify durable state owners.
- 05
Failure and boundary walkthrough
Walk through a difficult case step by step, including detection and recovery. Consider: How is an expired reservation released after a worker outage?
- 06
Tradeoffs and operations
Compare a credible alternative using your chosen workload and guarantees. Explain a remaining risk, a signal to watch and when you would change the design.
Worked designs
Explore the architecture and decisions, then build on an example with Coach.
Review rubric
AI feedback uses these criteria. Scores are practice feedback.
Scope and contracts
The scoping questions have explicit, consistent answers.
End-to-end design
State ownership and the central flow satisfy the chosen scope.
Operating evidence
Calculations or evaluations support the declared targets.
Boundaries and tradeoffs
A difficult case and an alternative are traced concretely.
Discussion
Share an approach, ask a question, or tag @Coach.
Loading discussion…