Asked at
URL Shortener (TinyURL)
Asked from Junior level upFoundations & Storage
Distributed Rate Limiter
Asked from Mid level upAPI Gateway & Security
Distributed Key-Value Store
Asked from Senior level upFoundations & Storage
Distributed Notification Service
Asked from Mid level upMessaging & Queues
Distributed Web Crawler
Asked from Mid level upDistributed Systems
Metrics & Monitoring Platform
Asked from Senior level upObservability & Time-Series
Real-Time Chat App (like WhatsApp or Slack)
Asked from Mid level upReal-Time & WebSockets
Social News Feed (like X/Twitter)
Asked from Mid level upSocial & Feed Systems
Ride-Hailing App (like Uber)
Asked from Senior level upGeospatial & Real-Time
Low-Latency Stock Exchange Matching Engine
Asked from Staff level upFintech & Low Latency
Global Video Streaming Platform (like YouTube or Netflix)
Asked from Senior level upMedia & Streaming
Distributed Hotel & Ticket Reservation System
Asked from Mid level upE-Commerce & Transactions
Shared Document Editor (like Google Docs)
Asked from Staff level upReal-Time & Distributed State
Game Leaderboard
Asked from Junior level upCaching & Data Structures
File Sync Service (Dropbox / Google Drive)
Asked from Mid level upStorage
Payment System
Asked from Senior level upPayments & Transactions
Ad Click Aggregation
Asked from Senior level upStream Processing
AI Support Assistant (RAG)
Asked from Senior level upAI Systems
LLM Inference Platform
Asked from Senior level upAI Systems
Enterprise Semantic Search
Asked from Mid level upAI Systems
AI Code Completion
Asked from Senior level upAI Systems
LLM Gateway
Asked from Senior level upAI Systems
AI Agent That Takes Actions
Asked from Senior level upAI Systems
LLM Evaluation Platform
Asked from Senior level upAI Systems
AI Document Processing Pipeline
Asked from Mid level upAI Systems

Design a Distributed Hotel & Ticket Reservation System

Asked from Mid level upDomain: E-Commerce & Transactions
Concepts to know first:

Design a booking system for hotel rooms and flash-sale tickets that many people use at once, and that never sells the same room twice.

An analogy

Think of hotel booking like reserving concert seats. When you click a seat, an egg timer starts for 10 minutes — that is a temporary lock. Nobody else can take the seat while you fill out your credit card details.

Where this design ends up. This is version 3 of 3. Part 5 builds it up from version 1 and says why each part was added.
  1. Clients
    • Guest
  2. Entry
    • API gateway
  3. Services
    • Booking service
    • Inventory service
  4. Queues, caches
    • Room holds
    • Booking events
  5. Data, outside
    • Bookings database
    • Payment provider

1. Requirements and scope

Functional Requirements
  • View available rooms for given date ranges.
  • Reserve room with 10-minute payment hold.
  • Process payment and confirm booking; auto-release room if payment times out.
Non-Functional Requirements & SLAs
  • Zero overbooking guarantee (Strict Serializability / CP model).
  • High availability for search browsing (AP model).
  • Flash-sale resilience under 100,000 concurrent booking attempts.
Key Traffic Assumptions: 5,000 hotels, 1 Million rooms total, 100,000 reservations made daily.

2. Back-of-the-envelope numbers

Writes and reads each second
  • Writes: 20,000 booking attempts a second, at peak (29%)
  • Reads: 50,000 searches a second (71%)

Balanced: reads and writes are close. Both paths need care, so neither can be slow.

Write Throughput
~1 reservation/sec avg (100,000/day ÷ 86,400); 20,000 booking attempts/sec at a flash-sale or ticket on-sale peak (most fail: few rooms)
Read Throughput
50,000 search queries/sec
Storage Growth
1M rooms × 365 days inventory = 365M date slots (~50 GB/year)
RAM Cache Footprint
Redis cluster caching room inventory availability per date range

3. API

GET/api/v1/hotels/{id}/availabilityCheck room availability for date range
POST/api/v1/reservations/holdPlace 10-minute hold: { roomId, startDate, endDate, userId }
POST/api/v1/reservations/{id}/confirmConfirm booking after payment authorization

4. Data model and storage

Storage Strategy: PostgreSQL, with a lock on the room row, or with a version number checked on each update.
ROOM_INVENTORY: (room_type_id, date, total_inventory, reserved_count, version) PRIMARY KEY (room_type_id, date)

5. The design, in three versions

Version 1: Pessimistic Row Locking in Monolith

SQL SELECT FOR UPDATE locks room inventory row during booking transaction.

Distributed Hotel & Ticket Reservation System: Version 1: Pessimistic Row Locking in Monolith Version 1 of 3

The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.

One request, step by step

Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.

GuestBooking serviceBookings database123
  • The order of the steps
  • A request or its reply

The parts: switch one off

1. Clients

Guestbooks a room

2. Services

Booking serviceruns the booking

3. Data, outside

Bookings databasethe lasting record

The steps in words0 of 3 steps shown

  1. Guest to Booking serviceHTTPS · 3 ms

    A guest books the last room for Friday.

  2. Booking service to Bookings databasequery · 8 ms

    One transaction locks the room row, checks it is free, and books it.

  3. Booking service to Guestreply · 20 ms

    The guest gets the booking.

Why this version
100% prevents double-booking.
Next bottleneck
Database locks stall threads; high contention during flash sales causes lock timeouts.

Write path, read path and failures

Each path follows one request through the final design (version 3), one hop at a time.

Write pathBook a room

  1. Client
  2. Reservation service
  3. Inventory service
  4. Payment gateway
  5. Outbox
  6. Kafka
  1. Client to Reservation service

    The user asks to hold a double room for 3 nights. The request carries an idempotency key.

  2. Reservation service to Inventory service

    The service lowers the free count for each of the 3 nights in one transaction. The update succeeds only if every night still has a room.

  3. Reservation service to Client

    It returns a hold that lasts 10 minutes.

  4. Reservation service to Payment gateway

    The user pays. The service calls the payment provider with the same idempotency key.

  5. Reservation service to Outbox

    On success it marks the booking confirmed and writes an event row in the same transaction.

  6. Outbox to Kafka

    A relay publishes the event. Other services send the email and update search.

Read pathSearch for free rooms

  1. Client
  2. Search service
  3. Redis cache
  4. Read replica
  1. Client to Search service

    The user searches for a double room for 3 nights.

  2. Search service to Redis cache

    The service reads the cached free counts for those dates.

  3. Search service to Read replica

    On a cache miss, it reads a database replica and fills the cache with a short TTL.

  4. Search service to Client

    It returns the list. A count may be a few seconds old; the hold step does the real check.

What breaks, and what happens then

  • Two users try to book the last room

    What users see
    Both press "book" in the same second.
    What the design does
    The count update is conditional, so only one succeeds. The other user sees "no longer available".
  • Payment fails or the user leaves

    What users see
    A room stays held with nobody paying.
    What the design does
    The hold expires after 10 minutes, and a worker adds the room back to the free count.
  • The payment succeeds but the confirmation is lost

    What users see
    The user is charged, but no booking is shown.
    What the design does
    The retry carries the same idempotency key, so the charge is not repeated. A reconciler compares payments with bookings and fixes any gap.
  • A flash sale sends 100,000 attempts at once

    What users see
    The inventory database could be overwhelmed.
    What the design does
    Requests wait in a queue and are worked through at a steady rate. Sold-out dates are answered from the cache.

6. Deep dives

Optimistic vs Pessimistic Concurrency
Pessimistic locking, such as SELECT FOR UPDATE, stops race conditions by locking rows. This is safe, but it sharply cuts how many writes can happen at the same time. Optimistic locking instead adds a version column: UPDATE inventory SET reserved = reserved + 1, version = version + 1 WHERE id = ? AND version = @current_version. If another transaction already changed the row, this update affects 0 rows, so the app retries.

7. Follow-up questions

  • How do you release held rooms if a user abandons checkout? (Answer: Redis key expiration notification or scheduled delay queue worker triggers inventory increment).

What it costs

Bookings are few, about one a second on average, so the database is small. The cost is search traffic and the short flash-sale peaks. Cache search results, and queue the peak so the database is not sized for it.

Another way to design it

For a flash sale, you can put every buyer in a queue and let a few through at a time. Stock is then never oversold, with no clever locking. Buyers wait in line, and they can see their place.

8. How answers are judged

A passing answer at Mid level. A complete design with numbers: about 1 reservation a second on average, spiking to 20,000 a second of booking attempts in a flash sale. It explains the 10-minute hold and goes deep on one part, such as double booking.

How each level is judged
What is judgedJuniorMidSeniorStaff
BreadthHow much of the system does the answer cover?Names the core parts: clients, servers, a database and a cache.Covers the whole main flow, from the request to the stored data and back.Builds a complete design without being led through it.Covers the system, the systems around it and who owns each part.
DepthHow far does it go into the hard parts?Explains what each part does and why it is there.Goes deep on one part, such as the database or the cache.Goes deep on the two or three riskiest parts.Goes deepest where the risk is largest, and explains why the risk is there.
DrivingWho leads the conversation?Follows the interviewer, step by step.Moves forward alone, with an occasional nudge.Leads the conversation from start to finish.Changes the problem when the question asked is not the right one.
Trade-offsAre choices compared and justified?Names more than one option.Says why one option was picked over another.Compares options in detail, with what each one costs.Ties each choice to cost, speed and risk for the business.
Unclear questionsWhat happens when the question is vague?Answers the questions that are asked.Asks questions to make the problem clear.Sets the scope and says what is left out.Questions the assumptions behind the problem itself.
ScopeWhat does it consider beyond the normal path?Covers the normal path, when everything works.Adds what happens when a part fails.Adds growth: what breaks at ten times the load, and the fix.Adds abuse, cost and the daily work of running the system.

Requirements and scope

Strong answer
Before I design, I want to check the scope. Booking must never double-sell a room, but browsing availability can be a little stale. Can a hotel also block a room directly, say for maintenance, outside the guest booking flow? I will design search for speed and booking for correctness, treating a hotel's own block the same as a guest hold.
Weak answer
Guests search for a room, place a hold, and pay to confirm it. Once payment succeeds, the room is booked, so I will start on the reservation API and the inventory table.

Shows: Unclear questionsThe difference: The weak answer never asks whether a hotel can also block a room directly, such as for maintenance, which must respect the same no-double-booking guarantee.

Estimates

Strong answer
100,000 reservations a day is about 1 a second on average, so this is a light write load most of the time. The stated flash-sale peak of 20,000 a second is concurrent booking attempts for the same limited rooms, not confirmed bookings. So I will design for contention, not raw throughput.
Weak answer
The flash-sale peak of 20,000 a second means 20,000 confirmed bookings a second. So I will size the database to write that many successful reservations every second.

Shows: DepthThe difference: Most flash-sale attempts fail, since only a few rooms exist. 20,000 a second is concurrent attempts, not confirmed bookings, which the strong answer sizes for instead.

Core design

Strong answer
The API places a hold, then confirms it after payment. Inventory is a row per room type and date, holding a total and a reserved count. That way I can check one specific night, not one number for the whole room type.
Weak answer
I would keep one row per room type with a total rooms count and a reserved count, and check it before confirming a booking.

Shows: DepthThe difference: One row per room type cannot tell nights apart. It cannot track a stay from March 1 to 5 against a stay from March 3 to 7.

Deep dive

Strong answer
The hard part is two guests racing to book the last room. Reading the reserved count, checking it is under the total, then writing it back as two separate steps lets both holds pass. A single conditional update, raising the count only where it is still under the total, does the check and the write as one atomic step.
Weak answer
I would read the reserved count, check it is below the total rooms, and then write the new count back as a second step.

Shows: DepthThe difference: Two guests can both read the same count before either writes back, so both holds pass and the room is double-booked. One atomic update avoids that race.

Failures and trade-offs

Strong answer
If the confirm-booking call is retried after a timeout, a second confirm could double-charge the guest or create two bookings. An idempotency key tied to the hold stops that. I also expire an abandoned hold after 10 minutes, releasing the room back to inventory.
Weak answer
If the confirm call times out, I would retry it until it succeeds, so the guest is not stuck without a confirmed booking.

Shows: ScopeThe difference: Retrying without an idempotency key can create a second booking or charge. The strong answer ties the retry to the hold so a repeat is harmless.

We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.

10. Check your design with your own AI

Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.

The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.

See the prompt
You are a system design interviewer. Review my design for the interview problem below.

Problem: Design a Distributed Hotel & Ticket Reservation System
Design a booking system for hotel rooms and flash-sale tickets that many people use at once, and that never sells the same room twice.

What users must be able to do:
- View available rooms for given date ranges.
- Reserve room with 10-minute payment hold.
- Process payment and confirm booking; auto-release room if payment times out.

How well it must work:
- Zero overbooking guarantee (Strict Serializability / CP model).
- High availability for search browsing (AP model).
- Flash-sale resilience under 100,000 concurrent booking attempts.

Numbers to assume:
- 5,000 hotels, 1 Million rooms total, 100,000 reservations made daily.

Judge my design at the Mid level.
A passing answer at this level: A complete design with numbers: about 1 reservation a second on average, spiking to 20,000 a second of booking attempts in a flash sale. It explains the 10-minute hold and goes deep on one part, such as double booking.

For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each:
1. Requirements and scope
2. Estimates
3. Core design
4. Deep dive
5. Failures and trade-offs

Then ask me the two follow-up questions an interviewer would ask next.
Do not write a full model answer for me.

My design:
[Describe your parts, how one request moves through them, and why you chose each one.]