How many stoves does a wedding caterer need? You can't say until you ask: 500 guests or 5,000? Do they arrive a few at a time or all at once at 11:00? Those answers decide how many stoves, how many pots and how many people in the kitchen. The recipe is the same; the scale is different.
System design works the same way. You plan the parts of a system (servers, databases, caches, queues) and how they connect, so that the system meets its needs at a given scale. The order is the same as with the catering: ask about the needs, work out the numbers, then draw the boxes.
Five steps of a design
- Requirements: what the system must do, and how well.
- Estimates: how many requests per second, how much data per year, how much bandwidth.
- High-level design: boxes and arrows. Load balancer, application servers, database, cache.
- Deep dive: take apart the one or two most critical parts.
- Bottlenecks and trade-offs: where the system breaks first, and what you give up to prevent it.
There is no single "right" design. There are designs that fit the needs and the numbers, with the trade-offs stated openly.
TicketTune's requirements
Requirements come in two kinds. Functional requirements are what the system does. Non-functional requirements are how well it does it.
| Functional | Non-functional |
|---|---|
| Users see the list and details of concerts | The concert page opens in under 500 ms for 95% of requests |
| Users order at most 4 tickets per order | 99.9% uptime per month |
| Users pay for an order | A paid order must never be lost |
| A PDF e-ticket is emailed after payment | It keeps working during the 10:00 ticket war |
Beginners usually write only the left column. Yet the right column decides the architecture: the same app for 100 people and for 1 million people looks very different.
Scalability, availability, reliability
These three words often get mixed up:
- Scalability: able to handle growing load. There are two ways. Vertical scaling (scale up): replace the machine with a bigger one, more CPU and RAM. Horizontal scaling (scale out): add machines. Vertical is easy but has a ceiling; horizontal is nearly limitless but needs a load balancer and brings the problems of distributed systems.
- Availability: the percentage of time the system can be used. High availability means the system keeps operating even when a component fails, with minimal downtime. The way to get it is redundancy: two servers, automatic failover, and no single point of failure (one part whose death takes everything down).
- Reliability: working correctly, consistently. A system can be fast and scalable but not reliable, for example if it often sells the same seat to two people.
Availability is written as a "number of nines":
| Target | Downtime per year | Downtime per month (30 days) |
|---|---|---|
| 99% | 3.65 days | 7.2 hours |
| 99.9% | 8.76 hours | 43.2 minutes |
| 99.99% | 52.6 minutes | 4.3 minutes |
The availability promised to customers is written in an SLA (Service Level Agreement): a formal contract between a service provider and its customers, with compensation if it's broken. The team's internal target is the SLO (Service Level Objective), and the number actually measured is the SLI (Service Level Indicator). The SLO is usually stricter than the SLA to leave a safety margin.
Estimating: requests per second
A back-of-the-envelope estimate is a rough calculation on the "back of an envelope": round numbers, good enough to know the order of magnitude. The most common measure of load is QPS (queries per second), the number of requests per second. TicketTune has 1 million daily active users, each making 20 requests on average. Before you look at the table, take a guess: is that about 23, 231 or 2,315 requests per second? TicketTune's numbers (an example model):
| Step | Calculation | Result |
|---|---|---|
| Requests per day | 1,000,000 users × 20 requests | 20,000,000 |
| Average QPS | 20,000,000 ÷ 86,400 seconds | ≈ 231 |
| Busy-hour QPS | 231 × 3 | ≈ 694 |
| Ticket-war QPS | 231 × 50 | ≈ 11,574 |
So the average is about 231 requests per second. The quick trick: 1 day = 86,400 seconds, round it to 100,000, so 20,000,000 ÷ 100,000 = 200. It's 14% off, but the order of magnitude is the same, and that's what matters.
Look at the last row. If one application server handles 500 QPS, 2 servers are enough on a normal day, but the ticket war needs 11,574 ÷ 500 = 23.1, rounded up to 24 servers. Design for the peak, not the average.
Estimating storage and bandwidth
Say 5% of daily users buy: 50,000 orders a day. Each order stores 1 KB of data in the database and one 100 KB PDF e-ticket. Each response to the browser is 20 KB on average. In estimates, 1 KB = 1,000 bytes, 1 MB = 1,000 KB and 1 GB = 1,000 MB.
// TicketTune estimate (an example model)
const dau = 1000000; // daily active users
const requestPerUser = 20;
const secondsPerDay = 86400;
const qps = (dau * requestPerUser) / secondsPerDay;
console.log("Average QPS:", Math.round(qps)); // 231
const ordersPerDay = dau * 0.05; // orders per day: 5% buy
const kbPerOrder = 1 + 100; // 1 KB of data + a 100 KB e-ticket
const gbPerYear = (ordersPerDay * kbPerOrder * 365) / 1000000;
console.log("Storage per year:", Math.round(gbPerYear), "GB"); // 1843
const mbPerSecond = (qps * 20) / 1000; // 20 KB responses
console.log("Bandwidth:", mbPerSecond.toFixed(1), "MB/s =", Math.round(mbPerSecond * 8), "Mbps"); // 4.6 MB/s = 37 Mbps
qpsis requests per day divided by seconds per day: 231.gbPerYear: 50,000 orders × 101 KB × 365 days = 1,843,250,000 KB. Divided by 1,000,000 (KB to GB) that's 1,843 GB, about 1.8 TB a year.mbPerSecond: 231 requests × 20 KB = 4,630 KB per second, which is 4.6 MB/s. Network speeds are usually written in bits, and 1 byte = 8 bits, so it's about 37 Mbps.
These numbers lead straight to a design decision: the database only holds 18 GB a year (1 KB × 50,000 × 365); the rest is e-tickets. So the PDFs go to object storage, not the database.
🤔 Trade-offs, not right answers
Every choice pays for something. One more nine of availability means standby servers, a second region and a multiplied bill. When the network between servers breaks, the system has to choose: keep answering with data that may be old, or refuse in favour of data that is surely correct. TicketTune may show a seat count a few seconds late on the concert page, but must never sell the same seat twice. This choice is covered in the CAP Theorem lesson.
⚠️ Why do first designs often miss?
- Drawing the architecture straight away. Without requirements and numbers, every decision is just taste.
- Designing for the average. TicketTune's ticket war is 50 times its average. Servers sized for 231 QPS fall over at 11,574.
- Mixing up bytes and bits. MB/s (megabytes) and Mbps (megabits) differ by a factor of 8.
- Over-engineering. Microservices and ten databases for an app with 100 users. Start simple, and split when the numbers demand it.
TL;DR: System design is planning components and how they connect so the needs are met at a given scale. Start with requirements: functional (what it does) and non-functional (how well: latency, availability, durability). Scalability = handling growing load (vertical: a bigger machine, horizontal: more machines). High availability = keeps running even when a component fails, through redundancy. Reliability = works correctly, consistently. SLA = Service Level Agreement, the availability promised to customers; 99.9% means at most 43.2 minutes of downtime a month. Then estimate: QPS = requests per day ÷ 86,400 (TicketTune: 231, ticket-war peak 11,574), storage = data per day × 365 (1.8 TB a year), bandwidth = QPS × response size (4.6 MB/s). Design for the peak and name the trade-offs.
⚡ Requirements first, boxes later
Meaning: Functional requirements are what the system does (order at most 4 tickets). Non-functional ones are how well it does it (the page opens in under 500 ms, 99.9% uptime). It's the second kind that decides the architecture.
⚡ High availability
Guess first: the uptime target is 99.9%. How many minutes a month may the system be down?
Only 43.2 minutes. One more nine (99.99%) leaves just 4.3 minutes.
Meaning: High availability means the system keeps operating even when a component fails, with minimal downtime. The way to get it is redundancy: two servers, automatic failover, and no single point of failure.
⚡ Work out the QPS
Write:
const dau = 1000000; // daily active users
const requestPerUser = 20;
const secondsPerDay = 86400;
const qps = (dau * requestPerUser) / secondsPerDay;
console.log("Average QPS:", Math.round(qps)); // 231
Meaning: QPS = requests per day ÷ 86,400 seconds. For TicketTune that's about 231 requests per second.
⚡ Design for the peak
Meaning: The ticket war is 50 times the average: 231 × 50 = 11,574 QPS. If one server handles 500 QPS, you need 23.1, rounded up to 24 servers. Servers sized for 231 QPS fall over.