Restaurant Reservation (OpenTable–class)
Problem statement
Search restaurants, available tables by time party size, hold slot, confirm with payment hold, waitlist, no double booking across POS integration.
How it works
- Inventory = discrete slots (table combinations) or capacity buckets per time window.
- Hold with TTL similar to ticketing; sync to in-house POS for ground truth tables.
Analogy: Airline seats but tables turn every 90 minutes and party size changes which “seat map” fits.
High-level design
Rendering diagram…
Components explained — this design
| Component | What it is | Why we use it here |
|---|---|---|
| Booking API | Validates party size, time, restaurant rules. | Encapsulates policy (max party, blackout dates). |
| PostgreSQL inventory | Tables/slots and booking rows. | Unique constraints prevent double booking at commit time. |
| Redis hold TTL | Temporary soft lock on slot. | Improves UX with hold without keeping SQL transactions open during user payment typing. |
| Stripe auth hold | Reserve funds / card check. | Reduces no-shows and card testing fraud. |
| POS webhook | Informs online system of table merges/breaks. | Ground truth for physical restaurant chaos. |
Shared definitions: 00-glossary-common-services.md
Low-level design
Modeling tables
- Table entities with
min_party,max_party,combinable_withfor joinable tables. - Time slots materialized or generated — index
(restaurant_id, slot_start).
Concurrency
- Transaction:
UPDATE slots SET booked=true WHERE id=? AND booked=false— single row hot; partition by restaurant acceptable.
Walk-ins vs reservations
- Overbooking model statistical risk — explicit business rule with compensation policy.
Notifications
- SNS SMS reminders 24h; ICS calendar email attachment.
E2E: book 7pm party of 4
Rendering diagram…
Tricky parts
| Problem | Solution |
|---|---|
| POS says table broken | Webhook cancels slot; notify user + reoffer alternatives |
| Google Maps busy integration | Popularity signal not authoritative inventory |
| Fraud bookings | Card auth + device fingerprint |
Caveats
- No-show fees — legal disclosure + local consumer laws.
- Accessibility requests — metadata not just party size.
Azure
- Azure Communication Services SMS; SQL elastic pools per city shard.