# Client-Server Architecture

> A distributed structure that partitions tasks between providers (servers) and requesters (clients).

Subject: Internet | Lesson 7 of 35 | 3 min read
Interactive lesson: https://codewithanimation.in/internet/client-server-architecture
Previous: [DNS Resolution Process](https://codewithanimation.in/internet/dns-resolution-process.md) | Next: [HTTP Request Anatomy](https://codewithanimation.in/internet/http-request-anatomy.md)

## What it is

**Client-Server Architecture** is a distributed application structure that partitions tasks between providers of a resource (servers) and service requesters (clients). In standard HTTP, the lifecycle is strictly one-way initiation: the Client always initiates the request, and the Server processes it and serves a response back.

## Why it matters

It enforces a **Separation of Concerns**. Front-end developers focus on the user interface, accessibility, and client-side logic. Back-end developers focus on business logic, database management, and security boundaries. Because the client environment (the browser) is inherently untrusted, all sensitive operations must be strictly enforced on the server.

## How it works

A client opens a TCP/IP connection to the server using its IP address and port. It sends an HTTP Request message. The server receives and parses this request, executes any necessary backend logic, and sends back an HTTP Response message containing a status code and the requested payload.

## Common mistake: Common mistake

Believing that the server can easily 'push' or spontaneously send updates to the client whenever data changes. In standard HTTP, the server is purely reactive; the client *must* initiate a request.

## Tip: Pro tip

Use the **Restaurant Analogy**. The Customer (Client) looks at the menu and orders. The Waiter (Network) carries the order. The Kitchen (Server) prepares the food and gives it back. The kitchen cannot randomly force a customer to eat a dish they never ordered!

## Try it: Try it

Tap the **Send Request** button on the Client phone to initiate communication. Try tapping the Server to see if it can start the conversation itself!

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/internet/client-server-architecture

## Check yourself

### Question 1

Who initiates the communication in a standard HTTP Client-Server architecture?

- A. The Client.
- B. The Server.
- C. Both can initiate equally.
- D. The Network Router.

Correct answer: A

The defining characteristic of standard HTTP in the client-server model is that the client (e.g., your web browser) must always be the one to open the connection and send the initial request.

- Why not B: The server patiently waits for requests; it is reactive and does not initiate standard HTTP connections to the client.
- Why not C: In standard HTTP, communication strictly follows a one-way initiation rule: the client asks, the server answers.
- Why not D: Routers simply forward network traffic; they do not originate HTTP requests for web content.

### Question 2

Why is the separation of concerns important in the Client-Server model?

- A. It allows the client to handle the UI while the server handles storage and security.
- B. It ensures both the client and server share the exact same code base.
- C. It forces the client to handle all security and database access.
- D. It means the server manages all the browser's UI state.

Correct answer: A

Separating concerns means the client specializes in presentation (UI) and user interaction, while the server specializes in business logic, persistent data storage, and security.

- Why not B: It actually allows them to have completely different codebases and even use entirely different programming languages.
- Why not C: Database access and core security rules must be handled by the server to prevent malicious tampering by users.
- Why not D: The server usually doesn't care about the browser's temporary UI state (like dropdowns being open); the client handles that.

### Question 3

Which of the following best describes the 'stateless' nature of standard HTTP?

- A. The server treats each request as independent and doesn't inherently remember previous requests.
- B. The client cannot store any local state or variables.
- C. The server maintains a constant, unbroken connection to remember the user.
- D. The server must reboot after every request to clear its memory.

Correct answer: A

'Stateless' means that every HTTP request contains all the information the server needs to fulfill it. The server doesn't keep track of previous requests on its own.

- Why not B: The client can absolutely store state using JavaScript variables or localStorage. It is the network protocol itself that is stateless.
- Why not C: While keep-alive connections exist, HTTP itself doesn't inherently use the connection to 'remember' users-each request is fundamentally separate.
- Why not D: The server doesn't reboot; it simply doesn't carry context from one request directly into the next without external mechanisms like cookies or session IDs.

## Remember this

- The Client always initiates the communication.
- The Server is reactive and waits for requests.
- Standard HTTP is stateless; each request is an independent transaction.
- Security boundaries are strictly enforced on the Server.
