Skip to content

First principles · 1 of 4

One request, end to end

Step 1 · The pattern

A request is a relay of hops

A first visit: the phone looks up the shop's name (30 ms), then opens a connection. That is a TCP handshake and a TLS handshake, one round trip each, before the request goes out: three round trips, 150 ms. Only then does the load balancer pass it to an app server, which works for 20 ms and reads the cache. About 203 ms in all. (All numbers are illustrative.)

  • the request
  • answered

In short

One request, end to end: how it works and how it breaks

A request is a relay of hops. A phone looks up the name, opens a connection (a TCP handshake, then a TLS handshake), sends the request, and only then does a server start working: a load balancer passes it to an app server, which reads from a cache or a database and answers. Each hop adds its own time, and on a first visit the network round trips cost more than the server's work. Returning visits reuse the cached name and the open connection, so most of that setup disappears. When one hop turns slow, such as a database query that takes 400 ms instead of 12, every request that touches it is slow, and adding app servers changes nothing because the time is not spent there. Time every hop, find the slowest, and fix that.

What this simulation simplifies

  • Each hop takes a fixed time here; in reality every hop varies, and the variation adds up too.
  • The response is shown returning in one move; on a real network it takes the second half of the last round trip.
  • One app server and one database stand in for fleets of each.

How this comes up in interviews

"What happens, step by step, when a user opens your app and taps Checkout? Where does the time go?"

Then they ask

  1. Which steps happen only on the first request?
  2. How would you find which hop makes checkouts slow?
  3. Why might adding servers not make it faster?

A strong answer covers

  • DNS lookup, TCP handshake, TLS handshake, then the request: several round trips before a server works.
  • Load balancer, app server, then cache or database, and the answer back.
  • Returning requests reuse cached names and open connections, so most setup disappears.
  • Use distributed tracing to time each hop and find the slowest.
  • Scaling the wrong tier does nothing when the time is spent somewhere else.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last reviewed: Engineering write-up

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.