Two roles: the client asks, the server answers
A client is a program that starts a conversation by requesting a service or data. A web browser, a phone app and an email program are common clients. A server is a program that waits for requests and responds to them.
The word server also describes the computer that runs the server program. In a data centre, many such computers sit in server racks, which are standard frames that hold machines, power and network cabling. One physical machine can run several server programs, and one server program can be spread over many machines.
How a request travels and gets answered
The client opens a connection to the server's address and port number. It then sends a request in an agreed format, called a protocol. On the web the protocol is usually HTTP, and a request names a resource and an action such as GET to read or POST to send data.
The server reads the request, does the work, and returns a response. The work may include reading files or querying a database. The response carries a status code, such as 200 for success or 404 for a missing resource, followed by the data. The connection then closes or stays open for the next request, depending on the protocol and settings.
Worked example: loading a page with three requests
A browser loads a page that needs one HTML file, one image and one stylesheet. It sends 3 requests. Suppose the server takes 20 ms to answer each one, and the requests are handled one after another. The total server time is 20 + 20 + 20 = 60 ms.
If the server handles the 3 requests in parallel, the server time is about 20 ms, because the work overlaps. Now suppose 100 clients each send 3 requests, giving 100 x 3 = 300 requests. At 20 ms each in sequence, the last client would wait about 300 x 20 = 6000 ms, which is 6 seconds. This is why servers handle many requests at once and why busy services add more machines.
Common misconceptions
Client and server are roles, not types of hardware. A laptop can run a server program, and a large machine can act as a client when it requests data from another service. The same program can be a server to one party and a client to another, as when a web server queries a database server.
Another mistake is to think the server holds all the logic. Clients often validate input and draw the interface, while the server keeps shared data and enforces rules. A server also cannot be trusted to be reachable, so clients usually handle timeouts and errors.
Where client-server design shows up
Websites, email, online games, file storage and banking apps commonly use this model. Databases are often run as servers, with applications connecting as clients. Cloud services are client-server systems in which the servers sit in large data centres.
The main alternative is peer-to-peer design, where each participant acts as both client and server. Many real systems mix the two. The model is popular because it centralises data and control, though the server becomes a point of failure unless it is duplicated.
Key terms
- Client
- A program that sends requests to a server to obtain a service or data.
- Server
- A program, or the machine running it, that waits for requests and returns responses.
- Protocol
- An agreed set of rules for the format and order of messages, such as HTTP.
- Request
- A message from a client asking the server to do something or return something.
- Response
- The message a server sends back, including a status code and usually data.
- Port
- A number that identifies which service on a machine a connection is meant for.
- Server rack
- A standard frame in a data centre that holds server machines, power and network cables.
