Part 3 · The Building Blocks

Anatomy of a Request: From Browser to Database

A system-design diagram looks like a wall of boxes. Follow one request — “show me my order history” — through DNS, CDN, load balancer, gateway, app servers, cache, database and queues, and learn why each box exists.

Lesson 118 min readbeginner#architecture#dns

On this page

  1. The Problem
  2. The Core Idea
  3. How It Works
  4. Trade-offs
  5. In the Real World
  6. Interview Questions
  7. Key Takeaways
  8. Further Reading

The Problem

When you open a system-design diagram for the first time, it can look like a wall of boxes: DNS, CDN, load balancer, API gateway, app servers, cache, database, queue, object storage. What do they all do? Why are they in that order? Do you need all of them?

In Part 1 we followed a request across the network. In this post we follow it through a system, the set of building blocks a real company runs. Think of it as a map. Every other post in this series zooms into one box on it.

A building block is one part of the system that does one job. A request is a message from a user's phone or browser asking the system to do something. A response is the answer the system sends back.

The Core Idea

Think of ordering food at a big restaurant chain.

  1. You look up the restaurant's number. (DNS)
  2. For simple things like a cold drink or packaged snacks, the counter near the door serves you straight away. (CDN)
  3. For a real meal, a host decides which waiter serves you, so no waiter gets overloaded. (Load balancer)
  4. A manager at the door checks your booking and makes sure you're allowed in. (API gateway)
  5. The waiter takes your order and coordinates everything. (App server)
  6. For popular dishes, the kitchen keeps some ready on the counter. (Cache)
  7. Anything else comes from the main kitchen and storeroom. (Database)
  8. Big items like a wedding cake are kept in a separate warehouse. (Object storage)
  9. Things that don't need to happen right now, like washing dishes or sending you a feedback SMS, go on a to-do board for later. (Message queue)

Each role exists to solve a specific problem: speed, load, safety or reliability. Small restaurants skip most of them. Big chains need all of them.

Here is each block in one line.

  • DNS (Domain Name System) is a service that turns a name like api.shop.com into an IP address (the number address of a server).
  • CDN (content delivery network) is a group of servers around the world that keep copies of files, so users download them from a server close by.
  • Load balancer is a server that receives requests and shares them between several app servers.
  • API gateway is a server at the front door of your backend. It checks who you are, limits how many requests you can send (rate limiting) and sends each request to the right service.
  • App server is a server that runs your business code. It is stateless when it keeps no user data between requests, so any copy of it can answer any request.
  • Cache is a fast store (often in memory) that keeps copies of data you read often. Redis is a popular in-memory store used for this.
  • Database is the main place where data is stored for the long term.
  • Object storage is a service for big files such as images and videos (for example Amazon S3).
  • Message queue is a list of jobs waiting to be done. One part of the system adds a job. Another part, called a worker, takes it later and does it. Kafka and SQS are two popular queues.

How It Works

Here's the full map of a typical large web application:

Diagram
                        ┌───────────────┐
  User's browser/app ──►│      DNS      │  "Where is api.shop.com?"
          │             └───────────────┘
          │
          ├──── static files (JS, CSS, images) ────►  ┌──────────┐
          │                                           │   CDN    │──► Object storage
          │                                           └──────────┘   (images, videos)
          ▼
   ┌───────────────┐
   │ Load balancer │  spreads traffic, removes dead servers
   └───────┬───────┘
           ▼
   ┌───────────────┐
   │  API gateway  │  auth, rate limits, routing
   └───────┬───────┘
           ▼
   ┌──────────────────────────────┐
   │  App servers (stateless)     │  business logic
   │  [app 1] [app 2] [app 3]     │
   └───┬───────────┬──────────┬───┘
       │           │          │
       ▼           ▼          ▼
   ┌───────┐  ┌──────────┐  ┌────────────┐     ┌────────────┐
   │ Cache │  │ Database │  │   Queue    │ ──► │  Workers   │  emails, resizing,
   │(Redis)│  │ + replicas│ │(Kafka/SQS) │     │            │  notifications
   └───────┘  └──────────┘  └────────────┘     └────────────┘
                                                     │
                                                     ▼
                                              ┌─────────────┐
                                              │ Search index│
                                              └─────────────┘
step 1 / 11
Phone
DNS
Load balancer
Gateway
App
Redis
Database
  1. api.shop.com?
    often answered from cache
  2. nearest region's IP
  3. GET /orders
    TLS, reused connection
  4. pick a healthy server
  5. token OK, under rate limit → order service
  6. orders:user:42?
  7. miss
  8. SELECT … WHERE user_id = 42 ORDER BY created_at DESC LIMIT 20
  9. 20 rows
    uses an index, maybe a read replica
  10. SET orders:user:42 (TTL 60 s)
  11. 200 OK + JSON
    thumbnails are CDN URLs
“Show me my order history” — one request through the building blocks. The cache decides whether the database is touched at all. · sequence · step through

Now let's follow one request: "Show me my order history" on a shopping app.

Step 1: DNS. The app looks up api.shop.com. DNS in system design is more than a phone book, as we'll see below. It can send you to the nearest data centre (a building full of servers).

Step 2: CDN for static files. The page's JavaScript, CSS, logos and product images come from a CDN server near you. It might be in your own city, so these load in a few milliseconds and never touch the company's main servers.

Step 3: Load balancer. The API request (GET /orders) reaches a load balancer, which picks a healthy app server. If one server has crashed, the load balancer simply stops sending traffic to it. It does this with health checks: small test requests that show if a server is alive.

Step 4: API gateway. It checks your login token (a small secret that proves who you are), makes sure you're not sending too many requests, and routes /orders to the order service.

Step 5: App server. The code runs: "get orders for user 42, newest first, 20 per page".

Step 6: Cache check. "Do we already have user 42's recent orders in Redis?" If yes (a cache hit), we reply in about 1 ms. If not (a cache miss), we go to the database.

Step 7: Database. The query runs, ideally using an index (post 5). An index is a sorted lookup list that lets the database find rows without reading the whole table. Reads might go to a read replica (a copy of the database that only answers reads) so the main database isn't overloaded. The result is stored in the cache for next time.

Step 8: Response. JSON (a simple text format for data) goes back through the gateway and load balancer to your phone. Product thumbnails in the response are CDN URLs pointing at object storage.

Step 9: Async work (for writes). Async means "not at the same time": the work happens later, and the user does not wait for it. If you had placed an order instead, the app would save it, reply quickly with "Order placed!", and put a message on a queue. Workers then send the confirmation email, update the search index, notify the warehouse and so on, without making you wait.

Where the time goes: a latency budget

A latency budget is a plan for how many milliseconds (ms) each step may use. Suppose the target is "order history loads in under 300 ms". A rough budget:

HopTypical time
DNS (usually cached)0–50 ms
TCP + TLS (usually reused)0–100 ms
Network to the nearest region20–80 ms
Load balancer + gateway1–5 ms
App code5–20 ms
Cache hit / database query1 ms / 5–50 ms
Response back20–80 ms

TCP is the protocol that opens a reliable connection. TLS is the layer that encrypts it. Both need a few round trips to set up, so apps reuse the connection. The biggest items are usually network distance and database queries, not your code. That's why CDNs, regions close to users, connection reuse and caching matter so much.

0–50 ms
DNS
usually cached
0–100 ms
TCP + TLS
usually reused
20–80 ms
to the nearest region
each way
5–20 ms
app code
1 / 5–50 ms
cache hit / DB query
Where the ~300 ms budget goes. Your code is rarely the biggest line. · numbers

Synchronous vs asynchronous paths

Synchronous — the user waits
  • •Check the password
  • •Save the order
  • •Charge the card
Use whenAnything the user must know succeeded before they move on
Asynchronous — workers do it later
  • •Confirmation email and invoice
  • •Resize uploaded images
  • •Update search, recommendations, analytics
  • +Faster responses; survives a flaky email provider
Use whenAnything that can arrive “a moment later”
The question to ask of every feature: what must the user wait for? · compare

A key design question for every feature is what the user must wait for, and what can happen later:

  • Must be synchronous (user waits):
    • checking a password,
    • saving the order,
    • charging the card (the user needs to know it worked).
  • Can be asynchronous (done later by workers):
    • confirmation emails,
    • generating invoices,
    • updating recommendations,
    • resizing uploaded images,
    • analytics.

Moving work to the async path makes responses faster and keeps the main flow working even if, say, the email provider is down.

DNS as a system-design tool

In post 1, DNS turned names into IP addresses. In system design, DNS is also a traffic director. A region is a part of the world where a cloud provider has data centres, such as Mumbai or Frankfurt:

  • Geo-based routing (GeoDNS): users in India get the IP of the Mumbai servers; users in Germany get Frankfurt.
  • Latency-based routing: send each user to whichever region answers them fastest.
  • Weighted routing: send 95% of traffic to the old version and 5% to a new version, for safe testing. This is called a canary release: you show a new version to a few users first, to catch problems early.
  • Failover routing: if health checks show the main region is down, answer with the backup region's IP.

The limitation: caching. DNS answers are cached by browsers, operating systems and internet providers, sometimes for longer than the TTL you set. TTL (time to live) is the number of seconds an answer may be kept before it must be asked for again. So DNS failover isn't instant. Some users keep going to the dead region for minutes. That's why DNS is often combined with other techniques.

Anycast is another approach. The same IP address is announced from many locations worldwide, and internet routing naturally delivers each user to the nearest one. BGP (Border Gateway Protocol, from post 1) is the system that routers use to tell each other which IP addresses they can reach. Cloudflare and Google's public DNS (8.8.8.8) work this way. There's no DNS trickery; the network itself finds the closest site.

GeoDNSAnycast
HowDNS returns different IPs per locationOne IP, announced from many places
Failover speedLimited by DNS cachingFast (routing updates)
ComplexityEasy with managed DNSNeeds your own network and BGP
Used byMost companies via Route 53, Cloudflare DNS, etc.CDNs, DNS providers, large platforms

DNS is also a single point of failure (one part that, if it breaks, stops everything). If your DNS provider goes down, nobody can find you. Large companies often use two DNS providers.

GeoDNS
  • •DNS answers with a different IP per location
  • +Easy with managed DNS (Route 53, Cloudflare)
  • −Failover limited by DNS caching — minutes
Use whenMost companies
Anycast
  • •One IP, announced via BGP from many places
  • +The network itself picks the closest site
  • +Fast failover through routing updates
  • −Needs your own network and BGP
Use whenCDNs, DNS providers, large platforms
Two ways to send users to the nearest site. · compare

Do you need all of these boxes?

No. A good rule is to add components when a real problem appears:

StageTypical setup
Side projectOne server + one database
Growing startup+ CDN, + load balancer with 2–3 app servers, + managed database with backups
Busy product+ Redis cache, + read replicas, + queue and workers, + object storage
Large scale+ API gateway, + search cluster, + multiple regions, + sharded databases

Every box adds cost, latency and things that can break. Simple is a feature (post 6).

Trade-offs

  • More layers bring better scale, security and resilience, but also more hops, more latency and more operational work.
  • Caching and CDNs make things fast, but add the risk of showing stale data (old data that is no longer correct).
  • Async processing makes responses fast and resilient, but results appear "a bit later", which the user experience must handle ("Your invoice will be emailed shortly").
  • GeoDNS and multiple regions mean lower latency and survive regional outages, but data must be kept in sync across regions. That's much harder (Part 4).

In the Real World

Netflix splits the work cleanly. The app talks to Netflix's backend (running in AWS) for browsing, search and recommendations. But the actual video comes from Open Connect, Netflix's own CDN, whose servers sit inside internet providers' networks close to viewers. That's the "static content goes to the CDN" idea at enormous scale.

E-commerce order placement. When you place an order on a big shopping site, you get "Order confirmed" within a second or two. The confirmation email, the warehouse notification, loyalty points and recommendation updates usually happen moments later through queues and workers. That's the synchronous/asynchronous split described above.

Cloudflare uses anycast so that the same IP addresses are served from data centres in hundreds of cities. A user in Chennai and a user in Chicago connecting to the same IP reach different, nearby machines.

AWS Route 53 is a managed DNS service (Amazon runs it for you) that offers weighted, latency-based, geolocation and failover routing. Many companies use it to shift traffic between regions or to roll out new versions gradually.

Interview Questions

Q1Walk me through the components a request passes in a typical large web app.

DNS resolves the name (often to the nearest region). Static assets come from a CDN. API calls hit a load balancer, then an API gateway for auth, rate limits and routing, then stateless app servers. Those read from a cache first and fall back to the database (often a read replica). Slow side-effects go onto a queue for workers.

Q2What would you make asynchronous in an order-placement flow?

Keep saving the order and charging the card synchronous, because the user must know they worked. Push the confirmation email, invoice generation, warehouse notification, loyalty points, search and recommendation updates onto a queue, so the response is fast and survives a failing email provider.

Q3Why isn't DNS failover instant?

DNS answers are cached by browsers, operating systems and resolvers — sometimes for longer than the TTL you set — so some clients keep using the dead IP for minutes. It's combined with low TTLs, health-checked load balancers and anycast for faster recovery.

Q4How would you start the architecture for a brand-new product?

With the fewest boxes that meet the requirements: one or two app servers, a managed database with backups, and a CDN for static files. Add a cache, replicas, queues, search and extra regions only when a measured problem calls for them. Every box adds latency, cost and failure modes.

Key Takeaways

  • A large system is a chain of building blocks: DNS → CDN → load balancer → API gateway → app servers → cache / database / object storage, with queues and workers on the side.
  • Most latency comes from network distance and database work. CDNs, nearby regions and caches attack those.
  • Decide what the user must wait for (synchronous) and what can happen later (asynchronous, via queues).
  • DNS also directs traffic: by geography, latency, weight or health. Anycast routes users to the nearest site at the network level.
  • Add components only when needed. Each one adds cost, latency and failure points.

Further Reading

  • The System Design Primer on GitHub (section "System design topics: start here" and its overview diagram)
  • System Design Interview: An Insider's Guide by Alex Xu (chapter 1)
  • The "what-happens-when" project on GitHub
  • AWS Route 53 documentation on routing policies
  • Cloudflare Learning Center articles on DNS and anycast

Published by Jainik · Last updated · How these lessons are made

Keep learning

Related series