System designCrash course7 min read

Thinking in Systems: From One Server to Millions of Users

This lesson is for software engineers preparing for their first system design interviews, usually at mid level and above. Instead of starting with a list of components, it follows one web app as it grows from a single server to millions of users. At every step you will see what broke, what was added to fix it, and the question an interviewer asks about that choice. By the end you should be able to explain why each piece of a typical architecture exists, which is most of what a first system design round checks.

How the interview uses this

A system design interview gives you a vague prompt ("design a photo sharing app") and 45 to 60 minutes. The interviewer scores how you gather requirements, how you lay out a high-level design, how deep you go on the hard parts, how you weigh trade-offs, and how clearly you communicate. Each of those depends on knowing why a component is there. A candidate who says "I'll add a cache" scores less than one who says "reads outnumber writes about a hundred to one and the same profiles are read over and over, so a cache in front of the database takes most of that load."

Step 0: one request, one server

Start with the smallest version: a single machine running the web server, the application code and the database. Follow what happens when someone opens https://photos.example.com/u/maya:

  1. The browser asks DNS for the IP address of photos.example.com and caches the answer for the record's time to live.

  2. It opens a TCP connection to that IP, negotiates TLS, and sends an HTTP GET /u/maya.

  3. The application parses the request, runs a query such as SELECT * FROM users WHERE handle = 'maya', renders a response and sends it back.

browser --DNS--> IP
browser --HTTPS--> [ one server: web + app + database ]

This is the right first design for a prototype, and saying so in an interview is fine. It is simple to build, deploy and debug. What it lacks is any room to fail or grow: if that machine dies, the product is down, and every user competes for the same CPU, memory and disk.

Step 1: separate the database, then scale up

The first thing that usually hurts is contention between the application and the database on the same box. Moving the database to its own machine lets each tier be sized and tuned on its own: the application tier wants CPU, the database wants memory and fast disks.

The next move is vertical scaling: a bigger machine. It needs no code changes, and for many products it carries you surprisingly far. Its limits are real, though. There is a largest machine you can buy, the price per unit of capacity climbs near the top end, and one machine is still one point of failure.

Interviewer follow-up: "Why not just buy a bigger server?" A good answer names both limits, the ceiling and the single point of failure, and then says when it would still be the right call (early on, or for a database that is hard to split).

Step 2: many app servers behind a load balancer

To grow past one application server, run several and put a load balancer in front. DNS now points at the load balancer, which spreads requests across healthy servers and stops sending traffic to a server that fails its health check.

This only works if the app servers are stateless: any server can handle any request because nothing about the user lives in one server's memory. Session data moves to a shared store (a cache or the database) or into a signed token the client sends with each request. Once the servers are stateless, adding capacity is adding a machine, and losing a machine costs a share of capacity instead of an outage.

browser --> [load balancer] --> app 1 \
                            --> app 2  >--> [database]
                            --> app 3 /

Interviewer follow-up: "What happens to a logged-in user when the server they were on dies?" If sessions live in a shared store, nothing: the next request lands on another server and finds the session there. If you used sticky sessions instead, explain what they cost (uneven load, lost sessions on failure).

Step 3: read replicas for a read-heavy database

Now the database is the bottleneck. Most consumer products read far more than they write, so the common next step is leader-follower replication: one leader accepts writes and streams them to read replicas, and the application sends reads to the replicas.

The cost is replication lag. A replica may be a fraction of a second, or under heavy load several seconds, behind the leader. A user who edits their bio and immediately reloads the page may read from a replica that has not seen the edit yet. The usual fix is read-your-writes: send that user's own reads to the leader for a short window after they write, or read from a replica only once it has caught up to the user's last write.

Interviewer follow-up: "A user updates their profile and sees the old version. Why, and what would you do?" This question checks whether you know replicas are asynchronous by default.

Step 4: a cache for hot reads

Replicas multiply read capacity, but many reads are for the same few things: popular profiles, the home feed's top posts. An in-memory cache in front of the database answers those in well under a millisecond and keeps them off the database entirely. The usual pattern is cache-aside: the app checks the cache, and on a miss reads the database and writes the result into the cache with an expiry.

Caching trades freshness for speed. You now have to decide how stale a value may be, how to invalidate it when the data changes, and what happens when a popular key expires and thousands of requests miss at once. The caching deep dive covers those choices.

Step 5: a CDN for static and media files

Photos, video, scripts and stylesheets do not change per request and are large. Serving them from your app servers wastes bandwidth and puts users on the other side of the world a long round trip away. Store the files in object storage and put a content delivery network in front of it: edge servers close to users keep copies and serve them directly. The app servers now return small JSON or HTML responses, and the heavy bytes come from the edge.

Interviewer follow-up: "A user replaces their profile photo but still sees the old one." Cached copies at the edge live until they expire. Versioned file names (a new URL for every upload) avoid the problem entirely.

Step 6: queues for slow work

Some work does not need to finish before the user gets a response: resizing an uploaded photo into four sizes, sending notification emails, updating search indexes. Doing it inline makes requests slow and fragile, because one slow downstream call holds up the user. A message queue decouples it: the request handler writes a message and returns, and a pool of workers processes messages at their own pace.

Queues also absorb spikes. If uploads triple for an hour, the queue grows and the workers drain it later, instead of the whole site slowing down. The trade-offs are eventual completion (the thumbnail appears a few seconds later), the need for retries, and the need for idempotent workers, because most queues deliver a message at least once.

Interviewer follow-up: "What if a worker crashes halfway through a job?" The message becomes visible again and another worker retries it, so the job must be safe to run twice.

Step 7: sharding when one leader is not enough

Eventually writes or total data size outgrow a single leader, even a large one. Sharding (partitioning) splits the data across several independent databases, each owning a slice, for example by a hash of the user id. Each shard has its own leader and replicas, so write capacity grows with the number of shards.

Sharding is the most expensive step on this list. Queries that span shards become slow or impossible, joins move into the application, and choosing the wrong partition key creates hot shards. That is why it comes last: you shard when the numbers demand it, not by default. Scaling data covers partition keys and hot keys in depth.

The finished picture

browser --> DNS
browser --> CDN --> object storage (photos)
browser --> load balancer --> stateless app servers
app servers --> cache --> sharded databases (leader + replicas each)
app servers --> queue --> workers

Every box here exists because something specific broke. In an interview, that is the story to tell: start simple, find the bottleneck your numbers point to, and add the component that removes it, naming what it costs.

Mistakes that cost points

  • Starting at the finished picture. Drawing sharding and queues for a product with ten thousand users suggests you do not know what each piece is for. Size the problem first.

  • Adding components without a reason. Every box should answer "what problem does this solve here?" in one sentence tied to a number.

  • Ignoring what the fix costs. Replicas bring lag, caches bring staleness, queues bring retries and duplicates. Name the cost with the benefit.

  • Forgetting failure. For each component, be ready to say what happens when it goes down.

Practice it

Next, read the fundamentals (networking, APIs and estimation), then the core building blocks.

For a drill, take any app you use daily and narrate this lesson's seven steps for it out loud in ten minutes, naming the bottleneck at each step. Then try a real interview: Design a URL Shortener is a good first system design problem.

Practise this in a mock interview

Try what this lesson covers out loud: the AI interviewer asks one of these questions, follows up, and scores your answer.

Read next