The life of a request, end to end

Beginner · 5 min

Follow one Taskboard click from the browser through DNS, TLS, the API and Postgres and back, and see which hop to blame when something breaks.

Before thisWhat a full-stack developer does

ByteByteGo · 5 min

The life of a request, end to end

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by ByteByteGoReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A request passes through the same hops every time: the browser, a name lookup, a connection, the server, the database, and back.
  • Each hop can fail in its own recognisable way, so the symptom tells you where to look first.
  • The browser's Network tab shows the boundary between client and server, which is the first place to look for any bug.
  • A 4xx status means the request was wrong, a 5xx means the server failed, and no status at all means the request never arrived.
  • A timing breakdown per hop shows where the delay is, so you fix the slow hop instead of guessing.

One click, many hops

The last lesson drew the chain behind a single click. Here it is again with the real hop names, using Taskboard’s “mark task done” button. The person clicks. The page runs this:

await fetch("/api/tasks/42", {
  method: "PATCH",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ status: "done" }),
});

A lot has to go right before that call returns. The video below walks through the network side of it. This lesson adds what the video does not: which hop to blame when the click does not do what it should.

The hops

  1. The browser builds the request. URL, method, headers, body. If the URL is relative, it is resolved against the current page. A bug here means the request is wrong or never sent.
  2. A name lookup. taskboard.example becomes an IP address through DNS. In local development you skip this, because localhost is already an address.
  3. A connection. TCP, then for https a TLS handshake. Slow on the first request, reused after.
  4. The server receives it. A web server or platform edge accepts the connection and hands the request to your API process. Often a reverse proxy sits first. You will build that in deploying the three tiers.
  5. Your handler runs. Routing, parsing, validation, authentication, then the actual work.
  6. The database answers. A query goes out over a pooled connection and comes back as rows.
  7. The response travels back. A status line, headers, a body. The browser hands it to your fetch call, and your component updates.

If you want the protocol detail for hops 2 to 4 and 7, the frontend roadmap has it: how the internet and the web work and HTTP messages, status codes and headers. The server-side handler is covered in web frameworks and the request-response cycle.

Seeing the boundary

The single most useful debugging tool for a full-stack developer is the browser’s Network tab. It shows what actually left the browser and what actually came back, with no interpretation from your code in between. That makes it a referee between your two halves.

I ran a tiny Taskboard API (Hono 4.13.20 on Node 26.13.1) and sent it a bad request in-process to see the shape of a failure the Network tab would show you:

201 { id: 1, projectId: 1, title: 'Write docs', status: 'todo' }
422 { errors: [ { path: 'title', message: 'Give the task a title' } ] }

Two requests, two answers. The second one has a status, a body, and a field name. Read in the Network tab, that tells you instantly the bug is that the client sent a blank title, not that the server is broken.

Symptoms and where to look

What you see The request… Look at
Nothing happens, no entry in Network never left the browser the event handler, the code building the request
Red entry, “failed” or CORS error never completed the URL, the server being up, CORS (cross-origin setups)
4xx status arrived, and was rejected the request body, headers, or the cookie or token
5xx status arrived, and the server failed the server logs for that request
200, but the screen is wrong succeeded the response body against what the component expects
200, but slow succeeded slowly the timing breakdown: wait time is the server, content download is size

The last row is the one people skip. A 200 with the wrong data is a seam bug: the server is right by its own rules and the client reads the response by different rules.

Timing: finding the slow hop

The Network tab splits a request’s time into phases: queueing, DNS lookup, connection, waiting for the first byte, and content download. “Waiting” is your server and everything behind it. Download is the size of the response. A 3-second request with 2.9 seconds of waiting is a server problem; the same 3 seconds with 2.9 seconds of download is a payload problem. The fix is different, and you can tell the difference without touching code.

On the server side, the same idea becomes a log line per request with its duration, and later observability across layers adds one id that follows a request from the browser to the database.

A request is not the whole story

A page load is several requests. The first brings HTML, and then scripts, styles, data, images and fonts follow. How many of those the server makes up for you, and how many the browser makes after the page arrives, is the question the next lesson is about: single-page apps, server rendering, and meta-frameworks.

What the video covers

ByteByteGo’s “What happens when you type a URL into your browser?” is a five-minute animated overview published in June 2022. Its description is mostly links to the channel’s books and newsletter. The title promises the standard walk from the address bar to a rendered page, and I could not read a transcript to say how much each hop gets. Treat it as the network-side picture. The server-side half, from your handler to the database, is what this lesson and the following ones fill in. ForrestKnight’s web app architecture video is linked as a wider view of how the pieces are arranged.

Where this fits

You can now name each hop and say what failure at it looks like. Taskboard can be built several ways, and the main difference is who does the rendering. Next: SPA, SSR and meta-framework architectures.

Check yourself

  1. 01A click does nothing and the Network tab shows no request. Which side holds the bug?

    The client. The request was never sent, so look at the event handler or the code that builds the request before looking at the server.

  2. 02The Network tab shows a 500 response with an error body. Where do you look next?

    At the server logs for that request. The request arrived and the server failed while handling it.

  3. 03What is the difference between a 401 and a 500?

    A 401 means the server understood the request and says the caller is not authenticated, so it is a client-side problem. A 500 means the server failed on its own.

  4. 04Why is a request slow even though the database query takes 5 ms?

    The delay may be elsewhere, such as the DNS lookup, the TLS handshake, a slow handler, or the response size, and the timing breakdown shows which one.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark