Skip to content

Core system concepts · Concept lesson

The request lifecycle

Follow one tap of a button from a phone to a server and back, and see where time is spent and where things go wrong.

Written for a first reading. Nothing is assumed, and each new word is explained where it appears.

Original educational architecture · Version 2026-11-12.1 · Examples use stated hypothetical assumptions, not a company's actual design.

What you will be able to explain

  • Name the stops a request passes between a user's device and the answer coming back.
  • Explain the difference between how long a request takes, how many a service can handle, and how long a caller will wait.
  • Say why a request that timed out may still have happened, and what to do about it.

What happens when you tap a button

You tap Save in an app. A moment later the screen says Saved. In between, a message left your phone, crossed the internet, was handled by several computers, and an answer came back the same way. That whole trip is called the request lifecycle.

It is worth learning because almost every question about a web service is a question about this trip. Why is it slow? Somewhere on the trip, time is being spent. Why did it fail? Somewhere on the trip, something broke. If you can name the stops, you know where to look.

Think of ordering in a restaurant. You tell the waiter, the waiter tells the kitchen, the kitchen may need something from the store room, and the plate comes back the same way. A delay at any stop makes your meal late, and from your table you cannot see which stop it was.

One request, there and back
1. Your device

The app or browser that sends the request and waits.

2. Network and front door

Finds the service, carries the message, and checks who is asking.

3. The service

The program that does the work you asked for.

4. Database or another service

Where the information is kept or fetched from.

  1. Your device → Network and front door: the request
  2. Network and front door → The service: passed to one server
  3. The service → Database or another service: read or save
  4. Database or another service → The service: result or failure
  5. The service → Network and front door: the response
  6. Network and front door → Your device: back to you

The stops along the way

Not every service has every stop, and some stops are skipped when a recent answer has been kept nearby. But this is the usual order. For each one, the table says what it does and what waiting there looks like.

The word dependency means anything the service needs in order to answer: a database, a store of saved answers called a cache, or another service.

StopWhat it doesHow it adds delay
Finding the address (DNS)Turns a name such as app.example.com into the number of a computerA slow or failed lookup, before anything is sent
Opening a connectionThe two computers agree to talk, and to do so privatelySeveral messages back and forth; skipped if a connection is already open
The front doorA load balancer or gateway checks who is asking and picks a serverRequests queue here when all servers are busy
The serviceChecks the request and does the workWaiting for a free worker, then the work itself
A dependencyReads or saves the informationWaiting for a free connection, then the query
The way backPacks the answer and sends it to your deviceA large answer on a slow network

Worked example: where 690 milliseconds went

Suppose a page should appear within 900 ms of a tap. We measure one request and find the times in the table.

Add them up: 35 + 45 + 110 + 420 + 80 = 690 ms. The page made its 900 ms target with 210 ms to spare.

Now look at where the time went. The largest part, 420 ms, was not work at all. It was the service waiting for a free database connection. The query itself took only 80 ms. Making the query faster would save little. Having a connection ready sooner would save a lot.

This is the main lesson. One total tells you a request was slow. Only the time at each stop tells you why.

StopTimeWhat was happening
Finding the address and connecting35 msSetting up
Reaching the service45 msTravelling
Inside the service110 msChecking the request, building the page
Waiting for a database connection420 msWaiting, not working
The database query80 msWorking

Three measures people mix up

Latency is how long one request takes. Because requests differ, it is reported as a spread, not one number. You will see p50, the time half of requests beat, and p99, the time 99 in 100 beat. The foundation lesson on percentiles explains these.

Throughput is how many requests a service finishes in a period, such as 200 a second. A service can be quick for each request and still have low throughput, like a fast cashier at a shop with one till.

A timeout is a choice made by the caller: how long it will wait. It is not a measurement of the service. If the app waits two seconds and the service needs three, the app reports a failure although the service was still working.

A deadline is a timeout that is passed along. The app says the answer is useless after 900 ms. Each stop is told how much of that is left, so no stop keeps working on a request the user has already given up on.

When something goes wrong on the way

A request can fail at any stop. It can fail before it reaches the service, while it queues, during the database call, or on the way back. The last case is the surprising one.

Suppose you tap Pay. The service takes the payment and saves it. Then the answer is lost on the way back, and your app shows an error. From where you sit, it failed. In fact, it happened.

So a timeout tells you only that no answer arrived in time. It does not tell you whether the work was done. Trying again is safe for looking something up. For a change, such as a payment or a booking, trying again could do it twice.

Services guard against this in two ways. One is to let the app ask what happened before it tries again. The other is for the app to send a unique ticket number with the request, called an idempotency key. If the service sees the same ticket twice, it does the work once and gives the same answer both times.

Retries also need limits. If every stop tries three more times when the stop behind it is slow, one tap can turn into dozens of requests, all landing on the part that is already struggling.

  • Ask first: could doing this twice cause harm?
  • Retry a small number of times, and wait a little longer each time.
  • Stop retrying once the user's deadline has passed.
  • Show the user an honest message: not “failed” when the truth is “we are not sure yet”.

Requests that do not wait for the answer

So far the app asks and waits. That suits short work. Some work is too long to wait for, such as turning a video into several sizes.

For long work, the service can accept the job, hand back a job number at once, and do the work afterwards. The app checks later, or is told when it is done. The request is quick, but now someone must keep track of each job and say clearly when one fails.

For live updates, such as a chat, the app and the service keep a connection open and send messages both ways as they happen. That avoids asking again and again, but the open connection can drop, so the app must be able to reconnect and catch up.

Neither shape is better. Each moves the difficulty somewhere else. Choose by what the user needs: an answer now, or an answer when it is ready.

How engineers find the slow stop

The first tool is a request ID: a unique label given to each request when it arrives and written into every log line about it. With it, you can pull out everything that happened to one request across many computers.

The second is a trace. Each stop records when it started and finished its part, under the same ID. Laid end to end, these make a picture like the table in the worked example, for a real request.

The third is to count. For each kind of request, a service records how many arrived, how many failed and how long they took. A sudden change in any of the three says where to start looking.

When a user says the app is slow, an engineer finds a trace of a slow request and reads the stops. In an interview, describing that habit is worth more than guessing a cause.

Going further

These points go beyond a first reading. Come back to them after the later lessons.

When steps run side by side, the user waits for the slowest one, not for the sum. Adding up the times of parallel steps overstates the delay.

Stopping work the user no longer wants takes effort. When an app gives up, the database query it caused usually carries on unless the service cancels it.

A success code does not prove a useful answer. A reply can say OK and carry an empty page. Decide what “done” means for the user, and measure that.

Work handed to a queue often drops out of the trace. If the request ID is not passed along with the job, the picture looks complete while part of the story is missing.

Terms in plain language

Request
A message from one program asking another to do something or send something back.
Response
The answer to a request: the result, or a clear error.
Latency
How long something takes, from a stated start to a stated finish. Usually given in milliseconds (ms); 1,000 ms is one second.
Timeout
How long a caller is willing to wait before it gives up on an answer.
Trace
A record of one request's journey, with the time spent at each stop.

Preparing practice controls…

Check your understanding

These checks explain concepts. They do not measure architecture seniority or update readiness.

1. An app gives up waiting while saving, and the server may already have saved the change. What is the safest conclusion?
2. A request took 690 ms. Which fact tells you most about how to make it faster?

Design independently

A customer says that saving their profile sometimes shows a spinner for several seconds and then an error. Describe the stops the save request passes through, how you would find which stop is slow, and what the app should show the customer. Say what you need to know before letting the app try again by itself.

Hints, not a solution
  • The error means no answer came back in time. Does that mean the profile was not saved?
  • Compare a slow save with a quick one, stop by stop.
  • Saving the same profile twice is harmless. Would that be true of every kind of request?

0 / 20,000 characters · Not saved

Your learning notes

Sign in to save

Marking a lesson read and reviewing an exercise are separate actions. Neither implies mastery. Saved work is account-owned; saves are explicit and do not queue offline.

References and boundaries

Primary documentation supports the mechanisms described. It does not certify these hypothetical architectures, prices or sizing assumptions. Review platform-specific behavior before implementation.

RFC 9110: HTTP Semantics

The standard that defines web requests, responses and status codes, including which requests are safe to repeat.

RFC 9293: Transmission Control Protocol

The standard for the connections that carry most web requests.

Back to curriculum