Courses System design · Part 1 · Lesson 1
A Method for Any Design Question
A system design question is usually one sentence: “Design a URL shortener” or “Build a chat app”. There is no single right answer. What is judged is how you reach an answer: what you ask, what you assume, and where you give up one thing to get another.
This lesson gives a method in seven steps. At each step, we do that step on one example: a doctor appointment service, where patients search for doctors and book a time.
Step 1: Make the requirements clear
Before any diagram, ask what exactly the system does. There are two kinds of requirements:
- Functional requirements: what the system does. For our example: search doctors by specialty and city, see free times, book a time, cancel a booking.
- Non-functional requirements: how well it must work. How fast, how available, for how many users. For our example: search must answer in under half a second, and two people must never book the same time.
That last requirement is the most important sentence of the whole design, because it shapes the other decisions most. Look for that sentence in every question.
One more thing belongs in this step: say what is out of scope. For example, “We do not design online payment or video visits for now.” This saves time for the parts that matter.
Step 2: Estimate the numbers
Numbers tell you how big a system you need. They do not have to be exact; the order of magnitude must be right. Let us assume:
- 200,000 bookings are made per day.
- Each booking is about 1 KB of data.
- Each person searches or views a page about 20 times before booking.
Now we calculate. A day has about 86,400 seconds:
- Writes: 200,000 ÷ 86,400 ≈ 2.3 bookings per second.
- Reads: 2.3 × 20 ≈ 46 requests per second.
- Busy hour: mornings may be 5 times the average, so about 12 writes and 230 reads per second.
- Storage: 200,000 × 1 KB = 200 MB per day, about 73 GB per year.
The result: this system is not big. One ordinary database handles this many writes easily. So there is no need for complex structures, and that is an important result by itself. In the next lesson you learn to do these calculations quickly.
Step 3: Write the API
Write the few main calls, only the ones that cover the requirements of step 1:
GET /doctors?specialty=heart&city=yazd search doctors
GET /doctors/{id}/slots?date=2026-11-10 free times on one day
POST /appointments {slotId, patientId} book a time
DELETE /appointments/{id} cancel a booking
This short list keeps the rest of the design focused on these few jobs.
Step 4: Define the data model
What is stored, and which questions are asked most often?
- Doctor: id, name, specialty, city.
- Slot: id, doctor, start, end.
- Appointment: id, slot, patient, status.
The most frequent question is “free slots of doctor X on day Y”. So we need an index on the doctor and date columns.
Step 5: Draw the high-level picture
Now put the parts together:
- The user sends a request.
- A load balancer gives it to one of several app servers.
- For a search, the app server looks in a cache first, because the doctor list changes rarely.
- Bookings are written to a relational database.
- The reminder SMS goes through a message queue, so a booking does not wait for the SMS service.
Step 6: Go deep on the hardest part
Every design has one part with the most risk. Here it is the key requirement of step 1: two people click the same free time at the same moment. What happens?
If the first server reads “this slot is free”, and before it writes, the second server reads the same thing, both save a booking. A simple and strong fix is to let the database stop it: we put a unique constraint on the slot column of the appointments table. The second write fails, and we tell the second user “this time was just taken”.
In practice this is one line in the table definition. But if you do not say it in an interview, the design has a serious flaw.
Step 7: Name the trade-offs
No design is free. Say what you chose and what you gave up:
- The cache makes search fast, but a doctor who was just added may appear in results a few minutes late.
- Sending SMS through a queue is asynchronous: if the SMS service fails, messages arrive late, but booking keeps working.
- One main database is simple, but if it fails, booking stops. The next step is to add replication.
How to split the time in an interview
For a 45-minute interview, this split usually works:
| Step | Time |
|---|---|
| Requirements and numbers | 8 to 10 minutes |
| API and data model | 5 minutes |
| High-level picture | 10 minutes |
| Deep dive | 15 minutes |
| Trade-offs and summary | 5 minutes |
Common mistakes
- Jumping to a solution. Drawing Kafka and Redis before you know how many requests the system gets per day. Our example showed that sometimes the right answer is “one ordinary database”.
- Thinking silently. The interviewer can only judge what you say out loud.
- Not naming the costs. Saying “this way is faster” without saying what it costs is half an answer.
Summary
Seven steps: requirements, numbers, API, data model, high-level picture, deep dive, trade-offs. We repeat this order in every case study of the course.