SysAlchemy
foundations~6 min

Client vs server

A client asks. A server answers. The same machine is often both at once, and which one it is depends entirely on which way the request is pointing.

Why this matters

Open the network tab in your browser and reload any site you like. Forty lines appear, maybe two hundred. Every one of them is something your browser asked for and something else answered. That is the whole relationship, repeated until the page is finished. It is worth being strict about, because the moment a page takes four seconds instead of four hundred milliseconds, the sentence 'the backend is slow' is not a diagnosis — it is a shrug. There is no such machine as 'the backend'. There is a specific process that received a specific request and took a specific amount of time, and finding it starts with naming who asked whom.

Mental model

The client is whoever starts a request and waits: a browser, a phone app, a script, another service. The server is whatever receives it, does the work, and sends something back. Nothing about the hardware decides this — the roles come from the direction of the arrow, and they flip freely.

Walk one real checkout, below. Notice what the middle row is doing: the web server is answering the browser and asking the payment API at the same moment, so inside a single request it is both. Notice too where the time went. Of the roughly 350 ms the user waited, the web server spent 300 holding the line open and doing nothing at all. When you can point at that row and name the pair of roles that owns it, you have somewhere to go. 'The backend is slow' has nowhere to go.

One diagram

40 ms300 ms — the web server waitsBrowserClientWeb server (server here, client below)App serverPayment APIApp server

One checkout, hop by hop

  1. 1Browser asks the web server for the page40 ms
  2. 2Web server asks the payment API to charge the cardand waits300 ms
  3. 3Payment API reads the card record from its database5 ms

Total~350 ms

One cloud labelled backend

The first diagram most people draw has a browser, an arrow, and a cloud with the word backend inside it. It cannot be debugged, because it hides the only question that matters: which hop spent the time? A cloud has no hops. Split it the moment you draw it, even if the split is a guess — two boxes you can argue about beat one box nobody can.

In this lesson

Client
Whoever starts a request and waits for the answer.
Server
Whoever receives a request, does the work, and replies.
Service
A server other services call, usually with one job and its own data.
Upstream
The thing you call and depend on. Your payment API is upstream of your web server.
Downstream
The thing that calls you. Confusingly, both words get used both ways — say which you mean.

Checks

Your phone app loads a profile. Which one is the client?
Your web server calls a payment API. During that call, the web server is…
A page takes 4 seconds. What is the most useful next sentence?

Every arrow has someone waiting at one end and someone working at the other. Name that pair before you name anything else — most debugging is just finding which pair owns the time.

All lessons