SD Client Server Architecture

Client-server architecture is the backbone of almost every application on the internet. It is a model where one program (the client) requests something, and another program (the server) provides it. Every time a browser loads a webpage, a mobile app fetches news, or a game connects to a matchmaking service — client-server architecture is at work.

Think of it like a restaurant. The customer (client) places an order. The kitchen (server) prepares the food and sends it back. The customer and the kitchen never work on the same task at the same time — they communicate through a waiter (the network).

What Is a Client?

A client is any program or device that initiates a request. Clients do not store or process most of the data — they ask for it, display it, and let the user interact with it.

Examples of clients:

  • A web browser (Chrome, Firefox) loading a website
  • A mobile app (Instagram) fetching the latest posts
  • A desktop application (Slack) sending a chat message
  • A smart TV app streaming a movie

What Is a Server?

A server is a program (or machine) that listens for client requests and responds to them. Servers handle the heavy work — processing business logic, querying databases, and returning results.

Examples of servers:

  • A web server (Apache, Nginx) serving HTML pages
  • An API server processing user login requests
  • A database server storing product information
  • A file server storing images or videos

How Client-Server Communication Works

The client and server communicate over a network using a defined protocol — most commonly HTTP or HTTPS. The process follows a clear request-response cycle:

+-----------+                              +-----------+
|           |   1. Request (HTTP GET)      |           |
|  Client   | ---------------------------> |  Server   |
| (Browser) |                              |           |
|           |   2. Response (HTML/JSON)    |           |
|           | <--------------------------- |           |
+-----------+                              +-----------+
  1. The client sends a request with a specific action (GET, POST, PUT, DELETE).
  2. The server receives the request and processes it.
  3. The server sends back a response, which includes a status code and data.
  4. The client reads the response and renders or uses the data.

Types of Client-Server Architecture

1-Tier Architecture

Everything runs on one machine. The client, server, and database are all on the same system. This works for small desktop apps but fails for multi-user or internet-scale applications.

+-------------------------------------+
|  Client + Server + Database = ONE   |
|         Local Machine               |
+-------------------------------------+

Example: Microsoft Access database used by a single desktop user.

2-Tier Architecture

The client communicates directly with the database server. There is no middle layer. This is fast for small teams but exposes the database directly to the client, which is a security risk.

+----------+          +----------+
|  Client  | -------> | Database |
|  (App)   |          |  Server  |
+----------+          +----------+

Example: A company's internal inventory tool where a desktop app queries an SQL server directly.

3-Tier Architecture

This is the most common architecture for web applications. It separates the system into three layers: presentation (client), logic (application server), and data (database server).

+----------+     HTTP     +----------+     SQL      +----------+
|          |              |  App /   |              |          |
|  Client  | -----------> |  Logic   | -----------> | Database |
| Browser  |              |  Server  |              |  Server  |
+----------+              +----------+              +----------+
 (Tier 1: UI)          (Tier 2: Business Logic)   (Tier 3: Data)

Example: An e-commerce website where the browser displays products, the app server handles cart logic, and MySQL stores orders.

N-Tier Architecture

Large-scale systems add more layers — caching layers, message queue layers, microservice layers. This is common in enterprise and cloud applications.

Client → Load Balancer → App Servers → Cache → Database
                                    → Message Queue → Worker Servers

Peer-to-Peer Architecture vs Client-Server

In peer-to-peer (P2P) architecture, every node acts as both client and server. There is no central server.

FeatureClient-ServerPeer-to-Peer
ControlCentralized (server controls)Decentralized
ScalabilityScales with more serversScales with more peers
SecurityEasier to secureHarder to control
ExampleYouTube, GmailBitTorrent, Blockchain

Stateless vs Stateful Servers

Stateless Server

A stateless server does not remember anything about previous requests. Every request carries all the information the server needs to process it. This makes scaling easy because any server can handle any request.

Request 1: { userId: 42, action: "viewCart" }  → Server A
Request 2: { userId: 42, action: "checkout" }  → Server B  (no issue!)

Example: REST APIs are designed to be stateless. Each API call contains the auth token and all data needed.

Stateful Server

A stateful server remembers the client's previous interactions. The same client must always talk to the same server, which complicates scaling and failover.

Request 1: "Login"  → Server A  (stores session here)
Request 2: "Pay"    → Must go to Server A  (session only lives there)

Example: Traditional session-based login systems where sessions are stored in server memory.

How Servers Handle Multiple Clients

A single server must handle thousands of simultaneous connections. Two main approaches exist:

Thread-Based Model

The server creates a new thread (a separate process) for each client connection. This is simple but consumes significant memory when thousands of clients connect.

Event-Driven (Non-Blocking) Model

The server uses a single thread with an event loop to handle all connections. While waiting for a database response for one client, the server continues processing other clients. Node.js works this way.

ModelBest ForMemory UsageExample
Thread-BasedCPU-intensive tasksHigh (1 thread per client)Apache HTTP Server
Event-DrivenI/O-intensive tasksLow (shared event loop)Node.js, Nginx

Common Protocols Used in Client-Server Communication

  • HTTP/HTTPS – Web browsers and REST APIs use this. Request-response model.
  • WebSockets – Enables real-time, two-way communication. Used in chat apps and live dashboards.
  • gRPC – High-performance communication used between microservices.
  • FTP – File transfer between client and server.
  • SMTP/IMAP – Email sending and receiving protocols.

Advantages and Disadvantages of Client-Server Architecture

AdvantagesDisadvantages
Centralized data managementServer becomes a single point of failure
Easy to secure and control accessHigh server load under heavy traffic
Scales by adding more serversRequires network for every interaction
Updates deploy in one place (server)Server maintenance causes downtime

Summary

Client-server architecture defines how two sides of a software system communicate. The client requests, the server responds. Modern applications almost always follow the 3-tier model where the UI, business logic, and data storage stay separate. Stateless servers are preferred at scale because any server can handle any request. Understanding this architecture is the first step to understanding how large systems are built and scaled.

Leave a Comment