The journey of a web request
Overview
Almost every system design diagram is a variation of one picture: users on one side, data on the other, and a few layers in between. If you understand the path of a single request through those layers, you can reason about nearly any design. This lesson walks that path step by step.
The big picture
Let’s follow a user opening https://shop.example/products/42.
Step 1: DNS finds the address
Computers talk to IP addresses such as 203.0.113.7, not names. The Domain Name System (DNS) is the internet’s phone book: it turns shop.example into an IP address.
The lookup goes through several caches. The browser remembers recent answers, so does the operating system and so does the resolver run by your internet provider. Only when all of them miss does the resolver ask the authoritative DNS servers for the domain. Each answer carries a TTL (time to live) that says how long it may be cached.
DNS is also a design tool:
- Return different IPs to users in different regions to send them to the nearest data centre.
- Change the record to move traffic away from a failed region (with a short TTL, the change spreads quickly).
Step 2: a connection, then the request
With the IP address, the browser opens a TCP connection and, for HTTPS, performs a TLS handshake to set up encryption. That costs a few round trips, which is why browsers and servers keep connections open and reuse them. Then the browser sends the actual HTTP request: GET /products/42.
You will meet TCP, TLS and HTTP properly in the networking lesson.
The CDN shortcut
A product page needs the HTML or JSON for the product, but also images, fonts, CSS and JavaScript. Those static files are the same for every user, so they are served by a content delivery network (CDN): a set of servers spread around the world that keep copies of your files close to users.
A user in Mumbai gets the product photo from a CDN server in Mumbai, not from your data centre in Virginia. That is faster for the user and removes most of the bytes from your own servers.
Step 3: the load balancer picks a server
One server cannot handle millions of users, so you run several identical app servers and put a load balancer in front. The load balancer:
- receives every request on one public address,
- picks a server, for example in turn (round robin) or the one with the fewest active connections,
- checks servers regularly and stops sending traffic to any that fail a health check.
Because any server may get any request, the servers should be stateless: they keep no user-specific data in memory between requests. Sessions and carts live in a shared store instead. A later lesson covers this in depth.
Step 4: the app server and the cache
The app server runs your code: it checks who the user is, validates input and decides what data it needs. Reading from a database on every request is slow and expensive, so the server first asks a cache, usually an in-memory store such as Redis or Memcached.
- Cache hit: the product is in the cache; the answer comes back in about a millisecond.
- Cache miss: the server reads the product from the database, stores a copy in the cache for next time, and returns it.
For a popular product, thousands of requests can be answered from one cached copy.
Step 5: the database
The database is the source of truth: the durable place where the product, the user and the order really live. It is usually the hardest part to scale, because it holds state that must not be lost or corrupted. Much of weeks 3 and 5 is about scaling databases safely.
The response travels back
The database returns rows, the app server turns them into JSON or HTML, the load balancer passes the response back over the open connection, and the browser renders the page while fetching static files from the CDN. All of this typically takes from tens to a few hundred milliseconds.
Where this picture goes next
Real systems add more layers to the same backbone:
- an API gateway that handles authentication and rate limits before requests reach the servers (week 2),
- queues that let slow work, such as sending emails, happen in the background (week 4),
- object storage for user uploads such as photos and videos (week 4),
- search indexes, analytics pipelines and monitoring (week 6).
When you face a new design problem, start by drawing this backbone, then ask which parts the problem stresses.
Recap
A request finds its server through DNS, connects with TCP and TLS, reaches a load balancer that picks a healthy app server, and that server answers from a cache or the database. Static files skip all of this and come from a CDN. Each layer exists to make the system faster, more scalable or more reliable, and each one is a place where you will make trade-offs.
Trace a search request
A user types 'running shoes' into the search box of an online shop and presses Enter. Using the components from this lesson, list each step the request takes, from the browser until the results appear. Say which component does the work at each step and where a cache could save time.
1. Browser:
2.
3.
4.
5.
6.
Where a cache helps:1. Browser: builds GET /search?q=running+shoes. If it already knows the shop's IP
address (cached DNS) it skips step 2.
2. DNS: resolves shop.example to the IP address of the load balancer.
3. TCP + TLS: the browser opens a secure connection to that address (often reused
if one is already open).
4. Load balancer: picks a healthy app server and forwards the request.
5. App server: checks the cache for "search:running shoes". On a hit it returns
the cached results. On a miss it queries the search index or database.
6. Database / search index: returns matching products; the app server stores them
in the cache with a short expiry (for example 60 seconds) and returns JSON.
7. Browser: renders the page. Product images load separately from the CDN.
Where a cache helps:
- Browser and DNS caches skip the lookup.
- The CDN serves the images, CSS and JavaScript without touching the servers.
- A server-side cache (Redis) answers popular searches without hitting the database.Summary
- DNS turns a name like shop.example into an IP address; the answer is cached at several levels.
- A CDN serves static files (images, CSS, JS) from locations close to the user, so they never reach your servers.
- A load balancer spreads requests across several identical app servers and skips unhealthy ones.
- App servers run your code; keeping them stateless lets you add or remove them freely.
- A cache answers repeated reads in about a millisecond; the database is the slower but durable source of truth.