open atlas
↑ Back to track
Backend Architecture BE · 01 · 01

The journey of a request: seven stops from socket to response

Every HTTP request makes the same trip — accept, parse, route, middleware, handle, serialize, drain. Knowing the map tells you where latency, failure, and security each hide.

BE Junior ◷ 10 min
Level
FoundationsJuniorMiddleSenior
Already know this unit? Take a 1-minute quick check →

A user clicks “Save”. 180 ms later they see a green checkmark. In those 180 ms the request crossed a load balancer, sat in a kernel queue, was parsed byte by byte, matched against a route table, walked a stack of middleware, ran your handler, was serialized to JSON, and streamed back out — passing through seven distinct stages, each with its own failure mode. Most engineers can name the handler. Few can name the other six.

The seven stops

Strip away the framework and every server-side request follows one shape. The names differ between Express, Spring, Go’s net/http, and Rails, but the stages do not:

  1. Accept — the kernel completes the TCP handshake and hands your process a connected socket.
  2. Parse — bytes off the socket are turned into a request line, headers, and a body.
  3. Route — the method and path are matched to one handler.
  4. Middleware — cross-cutting layers run in order: auth, logging, body parsing, rate limiting.
  5. Handle — your business logic runs, usually waiting on a database or another service.
  6. Serialize — the result becomes bytes: JSON, HTML, a stream.
  7. Drain — the response is written to the socket, which may be slower than your handler, and the connection is kept alive or closed.

Together these seven stops form a chain: skip or misconfigure any one of them and you get a failure that looks mysterious until you know the map. The next ten minutes will make that map automatic.

Before stop 1, a reverse proxy (nginx, Envoy, a cloud load balancer) usually terminates TLS, picks a backend, and may buffer the whole request. That proxy is its own lifecycle — it has the same seven stops on the other side.

Where each problem hides

The reason the map matters is that each class of bug lives at a specific stop. Debugging blind means checking all seven; debugging with the map means going straight to one.

SymptomThe stop to suspect
Connections refused under loadAccept — the kernel accept queue overflowed
431 / 400 on large cookiesParse — header buffer exceeded
Wrong handler runsRoute — overlapping path patterns
Auth bypass on one endpointMiddleware — ordering: handler ran before the auth layer
p50 fast, p99 terribleHandle — a slow downstream dependency
High CPU on big responsesSerialize — JSON.stringify on a huge object
Memory climbs with slow clientsDrain — backpressure ignored, response buffered in RAM

Latency is cumulative, not located

A request’s total time is the sum of every stop, plus the time it spends waiting in queues between them. A handler that runs in 5 ms can still produce a 200 ms response if the accept queue was deep, the body was buffered by the proxy, and the client read the response slowly. This is why “the code is fast” and “the endpoint is slow” are both true at once — they describe different stops.

The senior skill is not memorizing the seven names. It is forming the reflex: given this symptom, which stop? When you see a p99 spike or a connection flood, your first question should be “which stop is this?” — not “what does the code do?” The rest of this unit walks each stop in production detail.

Quiz

A service has a 3 ms handler but users report 250 ms responses under load. Which stops are the most likely culprits?

Quiz

Why does a reverse proxy in front of your app server matter to the request lifecycle?

Order the steps

Put the seven stops of a request in the order they happen:

  1. 1 Accept — kernel hands the process a connected socket
  2. 2 Parse — bytes become request line, headers, body
  3. 3 Route — method + path matched to a handler
  4. 4 Middleware — auth, logging, body parsing run in order
  5. 5 Handle — business logic runs, waits on dependencies
  6. 6 Serialize — result becomes bytes
  7. 7 Drain — response written to socket, connection kept or closed
Recall before you leave
  1. 01
    Name the seven stops of the request lifecycle in order, and one thing that can go wrong at each.
  2. 02
    Why can a service have a 3 ms handler but a 250 ms response time?
  3. 03
    What does a reverse proxy add in front of the seven stops, and why does it have its own lifecycle?
Recap

Every server-side HTTP request follows the same seven stops: accept (kernel hands over the socket), parse (bytes become a request), route (path to handler), middleware (cross-cutting layers in order), handle (business logic), serialize (result to bytes), and drain (write to socket, keep-alive or close). A reverse proxy in front adds its own copy of this lifecycle. Total latency is the sum across stops plus queueing, which is why a fast handler can still yield a slow endpoint. Each class of bug lives at one specific stop — the value of the map is the reflex of jumping straight to the right one. Now when you see a service that is “slow but the code is fine,” your first move is to name the stop, not read the handler. The next lesson zooms into the first two stops: how the kernel accepts a connection and how raw bytes become a parsed request.

Practice

Start at the top. Tasks go easiest → hardest: recall a fact, apply it to a case, then a senior-level stretch. Open one, attempt it, then reveal.

recallapplystretch0 of 5 done
Connected lessons
appears again in188

Something unclear?

Ask a question about this lesson. Questions are anonymous and go straight to the author to make the lesson better.

Apply this

Put this lesson to work on a real build.

shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.