Chapter 1
Client, Server, Request, and Response
Start with the smallest useful model of communication on the web.
A client is a program that asks for a service, while a server is a program that waits for requests and provides that service. A browser can be a client, but so can a mobile app or a command-line tool. The words describe roles in one interaction, not fixed kinds of machines. One program may be a server to a browser and a client when it calls another service.
This separation exists so users do not need to store every application's data and rules on their own devices. Step by step, the client opens a network connection, sends a request containing what it wants, and waits. The server reads the request, runs the relevant logic, and returns a response. The response carries a result or an error, after which the connection may close or be reused.
For example, a weather app requests the forecast for a city. Its request identifies the city and the desired operation. The server looks up forecast data and responds with structured values that the app renders. In practice, developers should identify the client and server at every boundary, record enough request context to diagnose failures, and design both success and error responses deliberately.
Client and server are temporary roles connected by a request-response contract.
How to apply this
- Draw the client, server, request, and response before discussing implementation details.
- Define what a successful response and each expected failure look like.
- Use a request identifier to connect client errors with server logs.
Situation
A note-taking app shows a spinner after Save, but the note never appears on another device.
Decision
Inspect the browser's outgoing request and incoming response first. This separates a client rendering problem from a server processing problem.