Guide

How a request travels

Client and server

The client is the side that asks, like a browser or a phone app. The server is a computer that waits for requests and sends back responses. The client always speaks first; a server only answers. A server can also be a client, when it asks a database for data.

DNS

Computers find each other by IP address, a number like 203.0.113.5. People type names like example.com. DNS (the Domain Name System) turns the name into the IP address. The answer is cached until its TTL ends, so the next visit skips the lookup.

HTTP

Client and server talk in HTTP. A request has a method (GET to read, POST to send new data) and a path, like /cart. A response has a status code and a body:

  • 200: OK, here it is
  • 404: Not found
  • 500: The server failed

Codes in the 400s mean the request was wrong; the 500s mean the server failed.

Round trips

A round trip is a message going out and the answer coming back.

  • Read from memory: about 100 ns (nanoseconds)
  • Read from an SSD: about 0.1 ms
  • Round trip inside one data center: about 0.5 ms
  • Round trip to another continent: 100 ms or more

Requests sent one after another add up. Fewer round trips and nearby servers make apps faster.

Requests stand alone

HTTP has no memory: each request stands alone. So the browser sends a cookie with a session id on every request. A stateless server keeps no user data in its own memory between requests. It looks the session up in a shared store, so any server can answer.

Remember

  • The client asks; the server answers.
  • DNS turns a name into an IP address.
  • 4xx means the request was wrong; 5xx means the server failed.
  • Round trips add up; to another continent each is 100 ms or more.
  • Keep no user data in server memory; use a shared store.