SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
  • Client-Server
  • Monolithic Architecture
  • Microservices
  • Serverless
  • Event-Driven Architecture
  • Peer-to-Peer (P2P)
  • Hexagonal Architecture
  • CQRS
  • Event Sourcing
  • Domain-Driven Design (DDD)
  • Layered (N-Tier) Architecture
  • Containers and Docker
  • Kubernetes Basics
  • Clean Architecture and Modular Monolith
  • Multi-Tenancy
  • Cloud Basics: Regions, Zones and Edge
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Architecture/Architectural Patterns

Client-Server

One side asks, the other side answers: the oldest and most common shape of a networked app.

⏱ 12 min readBeginnerMust KnowHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Client-server is the most basic way to build networked software. A client asks for something, and a server does the work and sends back an answer.

  • The client is the program that starts the conversation: a browser, a phone app, or even another service.
  • The server is a program that waits for requests, runs the logic, and talks to the data.
  • They speak a shared language (a protocol) such as HTTP, over a network.
  • Almost every other pattern in this part (microservices, serverless, gateways) is built on top of this idea.

02Concept: What is it?

In the client-server model, the work is split in two roles. The server holds the shared things: the data, the rules and the secrets. The client shows the result to the user and collects what the user wants to do. The client sends a request, and the server sends back a response.

One server usually serves many clients at the same time. That is the whole point: instead of every phone keeping its own copy of all the data, there is one place that is kept correct and shared by everyone.

The roles are about who does what in one conversation, not about the type of machine. A web server can be a client when it calls a payment service. A laptop can be a server for a small test. It is common to have a chain: browser → web server → database server.

Request and response
📱Clientphone app
→↓1. request
🖥️Serverruns the logic
→↓2. read / write
🗄️Database
↑3. response goes back to the client
Clients always start the conversation. The server only answers.
🧠Stateless makes it scale
A server that does not remember anything about a client between requests (it is stateless) is easy to copy. Any copy can answer any request, so you can add more servers when more clients arrive.

03Real-Life Example

🍵The Restaurant
You sit at a table (client) and read the menu. You do not walk into the kitchen. You tell the waiter your order (request). The kitchen (server) cooks the food using the ingredients (data) it keeps in the store room. The waiter brings the dish back (response). One kitchen serves many tables at the same time. If too many tables order together, dishes arrive late. If the kitchen closes, every table is stuck, so busy restaurants have more than one kitchen.
Restaurant
Client-server
A guest at a table
A client (browser or app)
The order said to the waiter
A request
The kitchen
The server that does the work
The store room
The database
The dish brought back
The response
The menu with fixed items
The API (what you are allowed to ask)
Many tables, one kitchen
Many clients, one service
A second kitchen for busy nights
More servers behind a load balancer
One server, many clients
💻Browser
📱Phone app
⌚Watch
→↓requests
🖥️Serverone shared brain

04Why Do We Need It?

🎯One source of truth
Data lives in one place, so every user sees the same, correct thing.
🔐Security
Secrets, passwords and rules stay on the server, where users cannot change them.
🪶Light clients
A cheap phone can use a very powerful service, because the heavy work happens on the server.
🔧Update once
Fix a bug in the server and every user gets the fix, without installing anything.
📈Scale each side
Add servers when there are more users. Clients scale for free: each user brings their own device.
🧩Clear split
Front-end and back-end teams can work apart, as long as they agree on the API.
Keep the shared data and the rules in one trusted place (the server), and let many light clients ask it for what they need.

05Where Do We Use It?

🌐The web
A browser asks a web server for a page, using HTTP or HTTPS.
📱Mobile apps
The app shows the screen. A back-end API holds accounts, feeds and payments.
✉️Email
Your mail app talks to a mail server (IMAP, SMTP) to read and send messages.
🗄️Databases
Your app is the client and the database is the server. It speaks the database protocol.
🎮Online games
The game client draws things. A game server decides what really happened, to stop cheating.
🔎DNS lookups
Your computer is a client asking a DNS server for the address of a name.

06Types / Parts / How It Works

Common shapes (tiers)

From 2-tier to n-tier
2-tier
🖥️ClientUI + logic
↓
🗄️Database
3-tier
📱ClientUI only
↓
🖥️App serverlogic
↓
🗄️Database
n-tier
📱Client
↓
⚖️Load balancer
↓
🖥️App
🖥️App
↓
⚡Cache
🗄️Database
Client Logic Data
Adding a tier adds a layer that can be scaled, secured and changed on its own.

Thin client or thick client

StyleWhere the work happensExampleGood and bad
Thin clientMostly on the server. The client only shows pages.A classic website, a remote desktopEasy to update and secure. Needs a connection for every action.
Thick (fat) clientA lot happens on the client, which keeps its own data.A desktop game, an offline-first appFast and works offline. Harder to update and to keep in sync.
Rich web app (SPA)The browser runs a lot of code and calls an API for data.Gmail, Google MapsSmooth feel. Big first download, and more client code to manage.

Talking style

StyleHow it worksUsed for
Request / responseThe client asks and waits for one answerWeb pages, REST APIs
Long polling / SSE / WebSocketThe connection stays open so the server can push newsChat, live scores, notifications
StreamingThe server sends a long flow of dataVideo, large downloads
VisualizerMany clients, a few servers: load, speed and a crashAdd clients until the servers get busy. Then add servers or make them stronger, and crash one to see why a single server is risky.
Number of servers
Failure
Clients: green = got an answer, red = failed (first 40 of 100 drawn)
↕20 requests per second
🖥️Server 1100 req/s
How busy the servers are20 of 100 req/s
Load
20
requests per second
Capacity
100
requests per second
Reply time
25 ms
what a client feels
Failed
0%
of requests
Healthy: 20 requests per second on a capacity of 100. Every client gets a quick answer (25 ms).

A simplified model. Each client sends one request every 5 seconds. Reply time grows as a server gets busy (about 20 ms / (1 − busy share)). Real systems also depend on the work each request does.

07How to Use It / Steps / Implementation

Designing a client-server system

  1. 1
    List what the client does
    Show screens, collect input, check simple things (like an empty field) for a quick response. Nothing more.
  2. 2
    Keep rules on the server
    Anything about security, money or correctness must be checked on the server. A client can always be changed or faked.
  3. 3
    Agree on the contract
    Define the API: paths, inputs, outputs and errors. A clear contract lets both sides change on their own.
  4. 4
    Choose how they talk
    Plain request/response (HTTP, REST) first. Add WebSockets or SSE only when the server must push data.
  5. 5
    Make the server stateless
    Keep the session in a token or a shared store, so any server can answer any request.
  6. 6
    Plan for many clients
    Put several servers behind a load balancer, add caching, and set timeouts and rate limits.
  7. 7
    Handle a bad network
    Clients should retry safely (see Idempotency), show friendly errors and not freeze when the server is slow.
💡Never trust the client
Hiding a button in the app is not security. Anyone can send the request by hand. The server must check who is asking and what they are allowed to do, every time.

08Key Terms to Know

TermMeaning in easy words
ClientThe program that starts a request (browser, app, or another service)
ServerThe program that waits for requests and sends back responses
RequestA message from the client asking for data or an action
ResponseThe server's reply, with a status and often some data
ProtocolThe agreed rules for the messages, such as HTTP
APIThe list of things a client is allowed to ask the server to do
StatelessThe server does not remember a client between two requests
TierOne layer of the system, such as client, app server or database
Thin clientA client that does very little itself and relies on the server
Round tripOne request going to the server and the response coming back
PortA number that tells the machine which program should get the message

09Pros, Cons and Trade-offs

✅ Pros
  • Simple to understand and well supported everywhere
  • Central data and rules are easy to keep correct and secure
  • Clients can be light and cheap
  • Servers can be updated without touching users' devices
  • Can scale the server side with copies and caches
⚠️ Cons
  • The server is a single point of failure unless you copy it
  • Many clients can overload the server
  • Every action needs the network, so speed depends on latency
  • The server side costs money to run and keep safe
  • Offline use needs extra work

Trade-offs

ChoiceWe gainWe lose
More work on the serverControl, security and easy updatesServer cost and more load per user
More work on the clientA fast, offline-friendly feelHarder updates and less trust in the data
Stateless serversEasy to copy and replaceState must live in a token or shared store
Chatty API (many small calls)Simple, flexible endpointsMany round trips, slower on weak networks
Big combined API callsFewer round tripsLarger replies and less flexibility
One serverSimple and cheapNo safety if it fails and a hard limit on load

10Common Problems and Mistakes

Common mistakes

  1. Trusting the client. Checks only in the app can be bypassed. Always check again on the server.
  2. One server only. When it fails or gets busy, everyone is affected.
  3. Storing user state on one server. Then users must always return to the same machine, and scaling gets hard.
  4. No timeouts. A slow server makes clients wait forever and pile up.
  5. Blind retries. Many clients retrying at once can finish off a struggling server.
  6. A chatty API. Ten calls to draw one screen is slow on a mobile network.
  7. Breaking the contract. Changing the API without versions breaks old app versions that are still installed.

Things to watch

🔥Overload
More requests than the server can answer. Add servers, cache and limit traffic.
🐢Latency
Far-away clients feel slow. Use a CDN and servers in more regions.
📶Bad networks
Phones go offline and switch networks. Expect failures and retry carefully.
🧓Old clients
Old app versions stay alive for years. Keep the API backward compatible.

11Real-World Examples

🛒Online shops
The browser shows products. The server holds stock, prices and orders.
🎬Video streaming
The app asks servers (and a CDN) for the next chunk of video.
🏦Banking apps
The app is only a window. Balances and rules live on secured servers.
💬Chat apps
Clients send messages to servers, which store them and push them to the other person.
🗺️Maps
The client draws map tiles that the server sends, and asks for routes.
🧑‍💻Git hosting
Your git command is a client that pushes and pulls from a server.
Mini case: a shop at busy time
👥Thousands of clients
→↓
⚖️Load balancer
→↓
🖥️Servers x 6added for the sale
→↓
🗄️Database
The clients did not change. The servers behind the load balancer did.

12Related Topics to Read Next

What is an API?→

The contract that defines what a client can ask a server.

HTTP / HTTPS→

The most common protocol between clients and servers.

What are Load Balancers?→

Share many clients across many servers.

Scalability→

How a client-server system grows with its users.

Monolithic Architecture→

A common way to build the server side as one program.

Peer-to-Peer (P2P)→

The opposite idea: no central server, everyone is both.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: a client sends requests, a server holds the data and rules and replies.
  • ✔Roles: per conversation. A server can be a client of another service.
  • ✔Tiers: client → app server → database. More tiers mean more places to scale and secure.
  • ✔Stateless: keep no session in the server, so any copy can answer.
  • ✔Never trust the client: validate and authorise on the server every time.
  • ✔Scale: load balancer + many servers + cache + replicas.
  • ✔Risks: single point of failure, overload, high latency, old app versions.
  • ✔One line: “Many light clients ask one trusted service, and the service answers.”
← Previous
File Storage (NFS)
Next →
Monolithic Architecture