What is a Backend, How Do They Work, and Why Do We Need Them?
Server fundamentals, the 6-hop request journey, shared state coordination, and browser sandbox boundaries.
Frontend displays and collects user interactions; Backend processes rules, secures credentials, and manages shared state. The separation exists because browsers are untrusted client environments.
1. What is a backend?
A backend is the server-side engine of an application that runs on remote cloud machines. It acts as the brain behind the scenes, managing data persistence, running business logic, verifying authentication, and communicating with databases and external APIs.
POST /api/auth/login HTTP/1.1
Content-Type: application/json
{
"email": "sachin@example.com",
"password": "••••••••"
}HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"token": "eyJhbGciOi...",
"user": {
"id": 42,
"name": "Sachin"
}
}2. How backends work?
A backend operates primarily on the Client-Server model over HTTP. The client dispatches an HTTP request across the network, the server parses the request headers and payload, runs the requested business rules, queries the database, and returns a structured response.
GET /api/users HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOi...
Accept: application/jsonHTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"users": [
"Sachin",
"Rahul",
"Aman"
]
}3. Why do we need backends?
Applications need a single, trusted central authority to coordinate shared data across millions of independent users. Without a central backend, different users would overwrite each other's data, leading to race conditions and corrupted states.
POST /api/posts/101/like HTTP/1.1
Host: api.instagram.com
Authorization: Bearer eyJhbGciOi...
Content-Type: application/json
{
"action": "like"
}HTTP/1.1 201 Created
Content-Type: application/json
{
"status": "success",
"liked": true,
"totalLikes": 1420
}4. How frontends work?
The frontend is the client-side interface running directly on the user's browser or mobile phone. It is responsible for rendering the user interface, handling clicks and keyboard input, and displaying server responses visually.
| Dimension | Frontend (Client) | Backend (Server) |
|---|---|---|
| Execution Location | Runs on user's device inside the browser sandbox | Runs privately on controlled cloud servers |
| Primary Responsibility | Rendering UI, capturing input, animations | Data persistence, security, business calculations |
| Code Visibility | Completely public (viewable in Chrome DevTools) | Completely private and protected by firewalls |
5. Why can't we write backend logic in frontends?
There are 5 fundamental reasons why client applications cannot replace servers:
1Security & Secrets Exposure
2Browser Sandbox & OS Isolation
3CORS (Cross-Origin Resource Sharing) Policies
4Database Connection Saturation & Pooling
5Computing Power & Device Heterogeneity
User initiates an action in the UI. The browser constructs the HTTP request in memory.
➔ Allocates a local TCP port (e.g. 52418) and sets headers (User-Agent, Accept, Cookies).
1. Request Anatomy Inspector
Intercepts your raw HTTP byte stream and echoes back every parsed header, query param, body field, and client IP.
2. Status Code Matrix
Returns realistic HTTP responses for standard status codes across 2xx, 3xx, 4xx, and 5xx families.