
π System Design Interview Classics Β· Sequence
How seat booking avoids double-selling: seats are locked for a few minutes during payment, and released if payment fails or times out.
Drawing diagramβ¦
Seat booking sequence: the user picks a show and seats in the app. The booking service tries to lock the seats in Redis with a 10-minute expiry; if any seat is already locked it asks the user to choose again. It creates a pending booking in the database and sends the user to the payment gateway. On payment success the booking is confirmed, seats are marked sold and an e-ticket is sent. On failure or timeout the lock expires and seats become free.
sequenceDiagram
actor U as User
participant APP as App
participant BS as Booking Service
participant R as Redis Seat Locks
participant DB as Booking DB
participant PG as Payment Gateway
participant N as Notification Service
U->>APP: Choose show and seats
APP->>BS: Book seats A5, A6
BS->>R: Lock A5, A6 for 10 minutes
alt Seats free
R-->>BS: Locked
BS->>DB: Create pending booking
BS-->>APP: Go to payment
APP->>PG: Pay
alt Payment success
PG-->>BS: Success webhook
BS->>DB: Confirm booking, mark seats sold
BS->>N: Send e-ticket
N-->>U: E-ticket by SMS and email
else Failure or timeout
PG-->>BS: Failed
BS->>DB: Cancel booking
Note over R: Lock expires, seats free again
end
else Already locked
R-->>BS: A5 taken
BS-->>APP: Pick other seats
endThe classic interview design for a service like bit.ly: short code generation, fast redirects from a cache, and click analytics processed separately.
How a one-to-one chat message is delivered in a WhatsApp-style system, with sent, delivered and read ticks, and push notifications when the receiver is offline.
How posts reach followers' feeds: fan-out on write for normal users, fan-out on read for celebrities, and a ranked feed built from a cache.
The core of a ride-hailing app: drivers stream their locations, a geo index finds nearby drivers, and a matching service offers the trip to the best one.
How a token bucket rate limiter decides whether to let an API request through, using Redis so all servers share the same counts.
A notification system that sends email, SMS and push messages at scale: one API, a queue per channel, user preferences, and retries.