Part 8 of 8 · 2 min read
Exercises
Easy
Easy 1: Booking rate (20 minutes)
2 million rooms, 60 per cent occupied, average stay 4 days. Give reservations a day and per second.
Done when: you write 300,000 a day and about 3.5 per second.
Hint
2,000,000 × 0.6 / 4.
Easy 2: Funnel (20 minutes)
With 3.5 bookings per second and 10 per cent passing each step, give the booking page and detail page query rates.
Done when: you write 35 and 350 per second.
Hint
Multiply by 10 each step back.
Easy 3: Overbooking test (20 minutes)
A room type has 100 rooms, a limit of 110 per cent and 108 reserved. Is a request for 2 allowed? For 3?
Done when: you write yes for 2 (110) and no for 3 (111).
Hint
Compare reserved plus wanted with 110.
Medium
Medium 1: Inventory rows (30 minutes)
5,000 hotels, 4 room types each, rows for 365 days. How many inventory rows?
Done when: you write 5,000 × 4 × 365 = 7,300,000.
Hint
Multiply the three numbers.
Medium 2: Rows touched (30 minutes)
A guest books 2 rooms from 1 June to 4 June (3 nights). Which rows change and by how much?
Done when: you write 3 rows, for 1, 2 and 3 June, each total_reserved plus 2.
Hint
Nights are 1, 2 and 3 June, not the check-out day.
Medium 3: Retry cost (30 minutes)
Eight users try to book the last 8 rooms with optimistic locking, all reading the same version. Count the write attempts.
Done when: you write 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 = 36.
Hint
Each round has one winner.
Hard
Hard 1: Draw the booking flow (60 minutes)
Draw the full flow from clicking continue to a paid reservation. Show the reservation id, the inventory check, the payment step and the status changes.
Done when: a sequence diagram with at least five parts, the idempotency key and the statuses.
Hint
The status changes from pending to paid after payment.
Hard 2: Sharding plan (60 minutes)
For 120,000 queries per second and 16 shards, give the load for each shard if the hotels are evenly spread, and if one hotel gets 10 per cent of all traffic. Propose a fix.
Done when: a figure of 7,500 per second for an even spread, at least 12,000 on the shard of the hot hotel, and a fix such as a dedicated shard.
Hint
10 per cent of 120,000 is 12,000.
Hard 3: Mock interview (60 minutes)
Answer "design a hotel booking system" aloud in 35 minutes and mark yourself on the four steps. List two missed topics.
Done when: a recording, a score on each step, and two named gaps.
Hint
Use the four-step framework as a checklist.