Episode 1 — Fundamentals / 1.2 — Client Server Architecture

1.2 Client-Server Architecture — Quick Revision

Compact cheat sheet. Print-friendly.

How to use this material (instructions)

  1. Skim top-to-bottom in one pass before interviews or exams.
  2. If a row feels fuzzy — reopen the matching lesson: README.md1.2.a1.2.g.
  3. Drills1.2-Exercise-Questions.md.
  4. Polished answers1.2-Interview-Questions.md.

1.2.a Client-Server Model

Core Concept

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

┌──────────┐       Request (HTTP)      ┌──────────┐
│  Client  │ ────────────────────────> │  Server  │
│ (Browser)│ <──────────────────────── │ (Nginx)  │
└──────────┘       Response (HTML)     └──────────┘

Tiered Architectures

TierDescriptionExample
1-TierUI, Logic, and Data on one machine.MS Access, SQLite local app.
2-TierClient (UI/Logic) + Database Server.Legacy desktop ERP apps.
3-TierClient (UI) + App Server (Logic) + DB.Standard modern web app.
N-TierMultiple layers (Cache, LB, Microservices).Enterprise scale (Netflix, Amazon).

Client-Server vs P2P

FeatureClient-ServerPeer-to-Peer (P2P)
RoleDefined (Client vs Server)Symmetric (Nodes are "servents")
ControlCentralizedDecentralized
ScalabilityVertical (bigger server)Horizontal (more peers)
ExampleWeb browsing, EmailBitTorrent, Blockchain

1.2.b Client vs Server

The Client (Frontend)

  • Browser Internals:
    • Rendering Engine: Converts HTML/CSS to pixels (Blink/Chrome, WebKit/Safari, Gecko/Firefox).
    • JS Engine: Executes JavaScript (V8/Chrome, SpiderMonkey/Firefox, JavaScriptCore/Safari).
  • Types:
    • Thin: Minimal local processing; server does the heavy lifting (VDI, terminal).
    • Thick: Significant local processing (Gaming PC, Video Editor).
    • Hybrid: Modern web apps (React/Vue) where logic is shared.

The Server (Backend)

  • Web Server: Handles HTTP, static files, reverse proxy (Nginx, Apache).
  • App Server: Runs business logic, connects to DB (Node.js, Gunicorn, Tomcat).
  • Forms:
    • Physical: Bare metal hardware.
    • Virtual (VM): Software-emulated hardware (EC2).
    • Container: OS-level virtualization (Docker).
    • Serverless: Event-driven functions (AWS Lambda).

1.2.c HTTP (HyperText Transfer Protocol)

Evolution

VersionKey Features
0.9One-line protocol; GET only; no headers.
1.0Added headers, status codes, POST method.
1.1Persistent connections (Keep-Alive), Host header, Pipelining.
2.0Binary, Multiplexing (one TCP conn), Header compression (HPACK).
3.0QUIC (UDP-based), eliminates Head-of-Line (HOL) blocking.

Methods, Safety, and Idempotency

MethodSafe?Idempotent?Purpose
GETYesYesRetrieve resource.
POSTNoNoCreate resource / Submit data.
PUTNoYesReplace resource.
PATCHNoNoPartial update.
DELETENoYesRemove resource.
HEADYesYesGET without body (headers only).
OPTIONSYesYesCheck allowed methods (CORS).

Status Codes

RangeCategoryExamples
1xxInformational101 Switching Protocols
2xxSuccess200 OK, 201 Created, 204 No Content
3xxRedirection301 Permanent, 302 Found, 304 Not Modified
4xxClient Error400 Bad Request, 401 Unauth, 403 Forbidden, 404 Not Found
5xxServer Error500 Internal Error, 502 Bad Gateway, 503 Service Unavail

Key Concepts

  • CORS: Browser security mechanism using OPTIONS preflight to allow cross-origin requests.
  • Cookies: HttpOnly (prevents JS access), Secure (HTTPS only), SameSite (CSRF protection).
  • TLS: Encryption layer for HTTPS (Handshake: Cipher negotiation + Cert validation).

1.2.d What Happens When You Visit a Website

The Request Lifecycle

  1. URL Parsing: Browser breaks down scheme, host, port, path.
  2. HSTS Check: Force HTTPS if domain is in HSTS list.
  3. Cache Check: Check Service Worker, Memory, or Disk cache.
  4. DNS Resolution: (See 1.1.e) Resolve hostname to IP.
  5. TCP/TLS Handshake: (See 1.1.b) Establish secure connection.
  6. HTTP Request: Browser sends request headers and body.
  7. Server Processing: LB -> Web Server -> App Server -> Database.
  8. HTTP Response: Server sends status, headers, and payload.

The Rendering Pipeline (Critical Path)

HTML ──> DOM Tree ──┐
                    ├──> Render Tree ──> Layout ──> Paint ──> Composite
CSS  ──> CSSOM Tree ┘
  • DOMContentLoaded: HTML parsed, scripts executed (mostly).
  • Load Event: All resources (images, styles) finished loading.

1.2.e Frontend vs Backend

Technology Stack

LayerTechnologies
FrontendHTML5, CSS3, JavaScript (ES6+), React, Vue, Tailwind.
BackendNode.js, Python (Django/FastAPI), Go, Java (Spring), Ruby.
DatabaseSQL (PostgreSQL, MySQL), NoSQL (MongoDB, Redis).
APIREST, GraphQL, WebSockets, gRPC.

Modern Rendering Landscape

  • SSR (Server-Side): HTML generated per request (Better SEO, slower TTFB).
  • SSG (Static): HTML generated at build time (Fastest, cheap hosting).
  • ISR (Incremental): Background re-generation of static pages (Best of both).

1.2.f Static vs Dynamic

FeatureStaticDynamic
ContentSame for everyonePersonalized / Real-time
DatabaseNot requiredRequired
SpeedExtremely fast (CDN)Slower (Server processing)
CostLow (Blob storage)Higher (Compute + DB)
RenderingSSGSSR / CSR

1.2.g Web Hosting

7 Types of Hosting

  1. Shared: Multiple sites on one server (Cheap, noisy neighbor).
  2. VPS: Sliced physical server via Hypervisor (Dedicated resources).
  3. Dedicated: Entire physical machine (Maximum control/cost).
  4. Cloud: Distributed resources (AWS, GCP, Azure) — Pay-as-you-go.
  5. Managed: Provider handles updates/security (WP Engine).
  6. Colocation: You own hardware, they provide space/power/cooling.
  7. Serverless: No server management; scales to zero (Vercel, Netlify, Lambda).

Master workflow — The Server Stack

  1. Load Balancer: Receives traffic; distributes to healthy nodes.
  2. Web Server (Nginx): Terminates TLS; serves static assets; forwards to App.
  3. App Server (Node.js): Executes business logic; queries Database.
  4. Database (Postgres): Persists data; returns results to App.
  5. Cache (Redis): (Optional) Stores frequent queries to offload DB.
  6. Response: App -> Web Server -> LB -> Client.

One-liner definitions (20+ terms)

TermOne-liner
ClientDevice or software that initiates requests to a server.
ServerComputer or program that provides services/resources to clients.
ProtocolSet of rules for data exchange (e.g., HTTP, FTP).
StatelessEach request is independent; server doesn't "remember" previous ones.
StatefulServer maintains context/session between requests.
IdempotencyMaking the same request multiple times has the same effect as once.
Safe MethodHTTP method that does not modify server state (e.g., GET).
PayloadThe actual data transmitted in an HTTP request/response body.
HeaderMetadata sent with HTTP requests/responses (e.g., Content-Type).
MIME TypeLabel indicating the nature/format of a file (e.g., text/html).
User-AgentHeader identifying the client software (browser/version).
Reverse ProxyServer that sits in front of app servers to handle security/load.
APIInterface allowing two software components to communicate.
RESTArchitectural style using standard HTTP methods and URIs.
JSONLightweight data-interchange format used in most modern APIs.
DOMTree representation of HTML used by browsers to render pages.
CSSOMTree representation of CSS styles associated with the DOM.
TTFBTime To First Byte — measure of server responsiveness.
FCPFirst Contentful Paint — when the first bit of UI appears.
HydrationProcess of attaching JS event listeners to server-rendered HTML.
UptimePercentage of time a hosting service is operational (e.g., 99.9%).
BandwidthAmount of data that can be transferred over a period.
DomainHuman-readable address (google.com) mapped to an IP.

End of 1.2 quick revision.