Clients and Servers
Definition
Client
- In plain English
- A client is a program that asks another program for something over a network.
- Think of it like
- It is like a diner ordering from a waiter.
Server
- In plain English
- A server is a program that waits for requests and sends back responses.
- Think of it like
- It is like the kitchen that receives orders and sends out plates.
Network
- In plain English
- A network connects devices so their programs can exchange messages.
- Think of it like
- It is like roads connecting houses so deliveries can travel between them.
Why it exists
Your thermostat and phone need the same heating schedule. Separate copies drift apart when you change only one. A central server gives both devices one place to read and update it.
Update shared rules on the server instead of updating every device. Keep that server available and its data correct.
How it works
Request and response
- In plain English
- A request is a message asking for something, and a response is the message that answers it.
- Think of it like
- It is like a question and its reply in a text conversation.
- Build a request
The client describes what it needs.
- Cross the network
The message travels to the server.
- Do the work
The server checks the request and reads stored data if needed.
- Return a response
The result travels back to the client.
The browser requests data from the server, which queries the database. The database returns rows, and the server answers the browser.
Peer-to-peer
- In plain English
- Peer-to-peer means devices exchange data directly rather than through a central data server.
- Think of it like
- It is like friends passing notes around a table instead of through the teacher.
| Pattern | Who holds data | Failure risk | Typical use |
|---|---|---|---|
| Client-server | A central service holds shared data | A lone server can stop everyone | Shared schedules |
| Peer-to-peer | Participating devices hold data | Transfers between working devices continue | Direct file transfer |
Examples
Share a heating schedule
A thermostat reports temperature every 60 seconds; your phone reads it and sets a schedule.
The thermostat reports temperature every 60 seconds. Your phone reads the latest value and sets a schedule. Both are clients of the home server, even though they ask for different work.
The thermostat and phone app each connect to the same home server.
The insight
The server is the meeting point that both clients trust.
Choose an offline audio guide
You tap exhibit 42 on a handheld guide to hear its audio.
Thin and thick clients
- In plain English
- A thin client relies on the server for most work, while a thick client does more on the device itself.
- Think of it like
- It is like ordering takeaway versus cooking with a meal kit at home.
A thin guide downloads exhibit 42's track when you tap it. An offline guide stores every track in advance. You gain offline playback but must store and update those tracks.
The insight
You choose how much work lives on the client.
A server that is also a client
Fans ask a scoreboard service for game results.
Your browser asks the scoreboard service for scores. That service asks the game statistics server for fresh results. The middle program is a server in the first conversation and a client in the second.
The fan browser asks the scoreboard server for scores. The scoreboard server asks the game statistics server.
The insight
Roles describe a conversation, not a machine.
Trade-offs
Pros
- Keep one shared version of the data.
- Update shared rules in one place.
- Keep clients focused.
Cons
- One busy server slows everyone down.
- Network failure can block clients.
Use when
- Many clients share data.
- Central control and access checks matter.
Avoid when
- A task is entirely local.
- A direct local transfer is enough.
Quick check
Takeaways
- Client asks, server answers.
- Server is a role.
- A central server keeps shared data together but risks slowing everyone down.