Basics
Start with the product and the ideas it depends on. If these are clear, the design that follows will feel obvious rather than memorised.
1.1Product in plain words
Who uses it, what a normal day looks like, and why it is harder than it seems.
A platform where patients book appointments at clinics, practitioners manage their availability, and clinic admins configure services and hours. Popular slots open at 9 a.m. and are gone within seconds.
Who uses it
- Patients: book from the app, often for a specific practitioner.
- Practitioners: check their day on a partner app, sometimes without signal in treatment rooms.
- Clinic admins: set hours, services and prices on a web dashboard.
A day in the life
- At 8:59 she opens Dr Rao’s calendar; Thursday’s slots show as opening at 9:00.
- At 9:00:01 she taps 10:30; the app holds it for five minutes and shows a countdown.
- Another patient who tapped the same slot a moment later sees ‘Just taken, 11:00 is free’.
- She confirms and pays a deposit; the booking appears in both apps.
- Dr Rao’s partner app, which synced the day’s schedule earlier, shows the new patient.
Why it is hard
Exactly one person may get it, instantly and fairly.
Abandoned checkouts must release slots automatically.
A 10 a.m. appointment is 10 a.m. at the clinic, wherever the patient is.
Who visits which clinic is sensitive; clinical notes even more so.
Like a theatre box office that puts a ticket aside for five minutes while you get your wallet out. If you walk away, it goes back on sale.
1.2Key concepts
The building blocks this design uses. Each one appears again in the answer.
Thousands of patients try to take the same slot at 9 a.m. Exactly one may win, even when requests arrive in the same millisecond.
Book with an update that only succeeds if the slot is still free, or a unique constraint on the slot id. The database picks the winner atomically.
While the patient enters details, the slot is held for a few minutes, then released automatically if they give up.
Store times in UTC together with the clinic's IANA time zone, and display them in the clinic's local time. Otherwise daylight-saving changes move appointments.
Availability search reads a copy built for fast queries. It may be seconds behind; the final booking check always runs on the source of truth.
Appointment details are sensitive: encrypt them, limit who can see them, log every access and keep them out of notification text.
Learn them properly in the deep dives:
Question
Now read the question closely. Agree on what you are building, ask what is unclear, and work out the numbers before you draw anything.
2.1Brief and scope
The question exactly as the interviewer asks it, and what they want to learn from your answer.
Design a booking platform for 3,000 clinics: patients book slots in a mobile app, practitioners manage availability in a partner app, and admins configure clinics in a web dashboard. Popular slots open at 9 a.m. and sell out in seconds. Health data must be protected.
What it tests: Concurrency under contention, holds and expiry, time zones, notifications and health-data privacy.
The answer in one sentence. Slot rows with capacity, an atomic conditional update to place a short hold, confirmation as a second idempotent step, and audit on every change.
How to spend the 45 minutes
- Clarify~5 minAsk questions, agree on scope and write down assumptions.
- Estimate~5 minRough numbers for users, data and traffic, and what they imply.
- High-level design~11 minComponents, data flow and the key API on the board.
- Deep dive~16 minThe two or three hardest parts, with real mechanisms.
- Trade-offs and wrap-up~9 minDecisions, failure modes, and what you would do next.
2.2Clarify the problem
The first five minutes. Each answer removes a guess from your design.
| You ask | Interviewer answers |
|---|---|
| Can a slot hold more than one patient? | Most hold one; group sessions hold up to 20. |
| Payment at booking? | Optional deposit for some clinics. |
| Offline needs? | Practitioners must see today’s schedule without signal. |
| Regions and time zones? | Several cities across time zones; the clinic’s zone is authoritative. |
2.3Estimate the scale
Say the arithmetic out loud. What matters is the order of magnitude and what it forces you to do.
| Metric | Estimate | How |
|---|---|---|
| Clinics | 3,000 | |
| Bookable slots | ≈ 1.5M/week | 3,000 × 10 practitioners × 50 slots |
| Peak booking attempts | ≈ 2,000/s | 9 a.m. release spikes |
| Successful bookings | ≈ 200k/day |
Detailed answer
The design itself, from the big picture down to the code: components first, then one request end to end, then the parts interviewers push hardest on.
3.1Architecture
Three apps share one booking core. The core turns contention into a short hold, then a confirmation, with every transition recorded for audit.
- Slot model
- Availability rules (weekly hours, breaks, leave) generate concrete slot rows ahead of time. Each slot row has capacity, booked count and a version.
- Holds
- Booking starts by placing a hold that expires in five minutes, decrementing remaining capacity atomically. Confirming converts the hold; expiry releases it.
- Read path
- Search hits a Redis cache of slot counts, and every change updates it. It may be a second stale; the database write is the real arbiter.
- Partner app offline
- Practitioners sync today’s and tomorrow’s schedule into SQLite. Changes they make offline are proposals that the server validates.
- Audit and privacy
- The system logs every view and change of a patient record. Health details live in a separate, encrypted service with stricter access than the booking data.
3.2Key flow, step by step
Two patients tap the same last slot at 9:00:00.
- The database decides with a single conditional update, so no read-then-write race can occur.
- The loser gets an immediate, helpful answer: the next available slot, not just an error.
- Confirmation is a second, idempotent step; abandoning the screen lets the hold expire.
3.3Front end
Three front ends serve this product: the patient app, the partner app and the admin web dashboard. Each has a different job, but all must show availability honestly and react gracefully when someone else got there first.
Screen map
- Slot picker
- A horizontal date strip and a grid of time chips. Availability comes from a cached count that can be a second stale; the hold request is the real check.
- Hold + confirm
- A visible five-minute countdown based on the server’s expiry time, not the device clock. Leaving the screen keeps the hold until it expires.
- Partner app: my day
- The app syncs today and tomorrow into SQLite, so the schedule opens without signal. Edits are proposals the server validates.
- Admin: weekly hours
- A React drag-to-select weekly grid that edits availability rules, with a preview of generated slots and warnings for existing bookings.
Client layers
| Layer | Technology | Responsibility |
|---|---|---|
| Patient app | React Native or native | Search, slot picker, hold flow, my bookings |
| Partner app | Native with local DB | Offline day view, check-in, notes |
| Admin web | React + TanStack Query | Availability rules, services, reports |
| Real-time | WebSocket or polling for open slot screens | Mark slots taken while the user is looking |
| Time | Clinic IANA zone on every slot | Format in clinic time with the zone shown |
Every state the user can see
| State | What the user sees | How it works |
|---|---|---|
| Opening soon | Slots greyed with ‘Opens at 9:00’ | Server release time |
| Available | Time chip enabled | Remaining capacity above zero |
| Just taken | Chip shakes, next free slot highlighted | Hold returned zero rows |
| Held | Countdown ‘Held for 4:32’ | Hold expiry from server |
| Hold expired | ‘This slot was released’ with Try again | Countdown reached zero |
| Booked | Confirmation with add-to-calendar | Hold converted |
Code
Hold with a server-based countdown (React Native)
1function HoldTimer({ expiresAt, serverOffsetMs, onExpire }: Props) {2 const [left, setLeft] = useState(() => expiresAt - (Date.now() + serverOffsetMs));3 useEffect(() => {4 const t = setInterval(() => {5 const ms = expiresAt - (Date.now() + serverOffsetMs); // server time, not the phone's clock6 setLeft(ms);7 if (ms <= 0) { clearInterval(t); onExpire(); }8 }, 1000);9 return () => clearInterval(t);10 }, [expiresAt, serverOffsetMs]);11 const s = Math.max(0, Math.round(left / 1000));12 return <Text accessibilityLiveRegion="polite">Held for {Math.floor(s / 60)}:{String(s % 60).padStart(2, '0')}</Text>;13}14 15async function onTapSlot(slot: Slot) {16 const res = await api.hold(slot.id, { idempotencyKey: holdKey(slot.id) });17 if (res.status === 'taken') { haptics.warning(); showNext(res.nextFree); return; }18 navigation.navigate('Hold', { holdId: res.holdId, expiresAt: res.expiresAt });19}Admin availability editor data flow (React + TanStack Query)
1const rules = useQuery({ queryKey: ['rules', clinicId], queryFn: () => api.rules(clinicId) });2const save = useMutation({3 mutationFn: (next: Rules) => api.saveRules(clinicId, next, rules.data!.version), // optimistic concurrency4 onError: (e: ApiError) => { if (e.status === 409) toast('Someone else changed these hours. Reloading.'); },5 onSettled: () => queryClient.invalidateQueries({ queryKey: ['rules', clinicId] }),6});3.4Data model and APIs
The tables and contracts that make the design concrete.
Atomic hold
1UPDATE slot2 SET remaining = remaining - 1, version = version + 13 WHERE id = $1 AND remaining > 04RETURNING version;5 6INSERT INTO hold (id, slot_id, patient_id, expires_at)7VALUES ($2, $1, $3, now() + interval '5 minutes');Expiry sweeper
1WITH expired AS (2 DELETE FROM hold WHERE expires_at < now() AND confirmed = false3 RETURNING slot_id)4UPDATE slot s SET remaining = remaining + c.n5FROM (SELECT slot_id, count(*) n FROM expired GROUP BY slot_id) c6WHERE s.id = c.slot_id;3.5Tested code, explained
The core of this design as working code, with what each part does and why.
Holding a popular slot
At 9 am thousands of people want the same slot. One conditional update solves this without a lock service.
1data class Slot(val capacity: Int, var held: Int = 0, var booked: Int = 0)2data class Hold(val id: String, val slotId: String, val expiresAtMs: Long, var confirmed: Boolean = false)3 4/**5 * Each method stands for one conditional UPDATE, such as:6 * UPDATE slot SET held = held + 1 WHERE id = ? AND held + booked < capacity7 * The row is the lock, so there is nothing separate to forget to release.8 */9class SlotBooking(private val slots: Map<String, Slot>, private val holdMs: Long = 120_000) {10 private val holds = HashMap<String, Hold>()11 12 @Synchronized13 fun hold(requestId: String, slotId: String, nowMs: Long): Hold? {14 holds[requestId]?.let { return it } // a retry returns the same hold15 expire(nowMs)16 val slot = slots.getValue(slotId)17 if (slot.held + slot.booked >= slot.capacity) return null18 slot.held += 119 return Hold(requestId, slotId, nowMs + holdMs).also { holds[requestId] = it }20 }21 22 @Synchronized23 fun confirm(holdId: String, nowMs: Long): Boolean {24 expire(nowMs)25 val h = holds[holdId] ?: return false26 if (h.confirmed) return true // confirming twice is fine27 val slot = slots.getValue(h.slotId)28 slot.held -= 129 slot.booked += 130 h.confirmed = true31 return true32 }33 34 private fun expire(nowMs: Long) {35 val dead = holds.values.filter { !it.confirmed && it.expiresAtMs <= nowMs }36 for (h in dead) {37 slots.getValue(h.slotId).held -= 138 holds.remove(h.id)39 }40 }41}slot.held + slot.booked >= slot.capacity- The condition in the UPDATE. The database applies it atomically, so two people can't both take the last place.
holds[requestId]?.let { return it }- A retried hold returns the same hold, so a flaky network can't take two places.
expire(nowMs)- An abandoned hold frees its place automatically.
if (h.confirmed) return true- Confirming twice is fine, and books once.
Compiled and tested by npm run test:mobile.
3.6Hard parts, in depth
Where interviewers spend the second half of the round.
Why not a distributed lock
A lock service adds a network hop and a failure mode. A conditional update in the same database that stores the slot is atomic, fast and impossible to forget to release.
For extreme spikes, put a short queue in front of the hottest clinics so requests are applied in order, and return position-in-line feedback.
Time zones
Store slot times in UTC plus the clinic’s IANA zone. Render in the clinic’s zone, because a 10 a.m. appointment is 10 a.m. where the clinic is, even if the patient is travelling. Handle daylight-saving transitions when generating slots, not when displaying them.
Protecting health data
Keep booking data (who, when, which clinic) separate from clinical notes. Clinical notes require stricter roles and separate encryption keys, and audits cover every access. The patient app caches only what it needs and clears it on sign-out.
Q&A
The questions that come after the design, with model answers. Answer each one out loud before opening it.
4.1Follow-up questions
What the interviewer asks once the main design is on the board.
How do group sessions change the design?
How do you handle no-shows?
What would you log for compliance?
4.2Front-end follow-ups
Questions aimed at the client: rendering, state and devices.
Why base the countdown on server time?
How do you stop users seeing slots that are already gone?
4.3Incidents, probes and traps
Realistic production incidents and pointed probes, grouped by topic.
The product 1
ProbeWhy not let whoever pays first get the slot?
Requirements 1
TrapWhich clarifying question changes the data model?
Scale 1
Probe2,000 attempts a second on a few hot slots. What is the bottleneck?
Architecture 2
IncidentAt 9 a.m. database CPU hits 100% and bookings time out.
ProbeWhy keep clinical notes in a separate service?
The key flow 1
IncidentTwo patients ended up booked into the same single slot.
Front end 2
IncidentPatients travelling abroad arrive an hour late.
ProbeHow should the UI handle ‘just taken’?
Data and APIs 1
TrapWhy must the capacity decrement and hold insert share a transaction?
The hard parts 2
IncidentThe hold sweeper stopped after a deploy and slots vanished all afternoon.
ProbeHow do you build a fair waitlist?
Trade-offs 1
ProbeWhy not use a distributed lock such as Redlock?
Failures 2
IncidentEvery patient received each SMS reminder twice.
IncidentAn admin deleted availability that already had bookings.
Extra depth
What turns a good answer into a strong one: the decisions you rejected, how the system fails, and the signals of seniority.
5.1Trade-offs and decisions
Every choice has a cost. Naming it is what interviewers listen for.
Show detailsHide details
| Decision | Chosen | Rejected | Why |
|---|---|---|---|
| Contention control | Conditional update + hold TTL | Distributed lock | Atomic in one store; no lock to leak. |
| Search freshness | Redis counts, eventually consistent | Query DB per search | Search volume far exceeds bookings; the write path is still exact. |
| Offline practitioners | Read schedule offline, propose changes | Full offline editing | Avoids conflicts with patient bookings made meanwhile. |
| Notifications | Queue with retries and channels | Inline SMS call | Providers fail; reminders must not block booking. |
5.2Failure modes
What breaks in production, and how the design keeps working when it does.
Show detailsHide details
| What breaks | How the design copes |
|---|---|
| Hold sweeper stops | Expired holds keep slots unavailable; alert on hold age and run sweeper with leader election. |
| Practitioner deletes a slot with a booking | Server rejects; partner app shows the conflict and offers to reschedule the patient. |
| SMS provider down | Fail over to a second provider and push; mark reminder delivery state. |
| Thundering 9 a.m. spike | Pre-warm caches, rate-limit per user, queue per hot clinic. |
5.3Performance and accessibility
The client-side details that separate a demo from a product.
Performance
- Prefetch the next seven days of slot counts when a practitioner page opens.
- Keep the hold request tiny so it wins races on slow networks.
- The partner app’s day view reads only local data and opens in under a second.
Accessibility and localisation
- Time chips announce date, time and availability.
- The countdown is a polite live region, not a constantly interrupting announcement.
- All times show the clinic’s time zone when it differs from the device.
5.4Senior versus principal
The same design, answered at two levels. Use the rubric to score yourself.
A senior answer prevents double-booking with a transaction.
A principal answer explains holds and expiry, avoids distributed locks, handles 9 a.m. spikes, gets time zones right, separates health data and designs notifications as a reliable pipeline.
Score yourself
5.5Whiteboard
Draw the design here, in this order. It stays in this browser.
- Three apps feeding one booking core
- Slot row with capacity and version
- Hold → confirm state with TTL
- Race diagram: two patients, one conditional update
- Audit log and separate health-data store