What a system is made of: clients, servers, APIs and databases
Before you can design a system, you need its vocabulary. Every app you use, from a to-do list to a bank, is built from the same few parts: something that asks (a client), something that answers (a server), an agreed way of asking (an API), and somewhere the data is kept (a database). This module explains each part from zero and shows one request moving through all of them.
1. The idea
Here is the same picture in technical words. Each term below is used in every later module, so it's worth being able to say each one in a sentence.
| Term | What it means | Example |
|---|---|---|
| Client | The program that starts a conversation by sending a request. | A web browser, a phone app, another server calling yours |
| Server | A program (and, loosely, the machine it runs on) that waits for requests and answers them. | The program behind api.example.com |
| Request and response | One question and its answer. On the web they're usually HTTP messages: a method and a path in, a status code and a body out. | GET /notes/7 → 200 OK with the note |
| API | Application programming interface: the list of requests a server accepts and what each returns. A contract between client and server. | "POST /notes creates a note and returns its ID" |
| Frontend and backend | The frontend is what runs on the user's device (pages, buttons). The backend is everything on your servers. | A React page (frontend) calling a Python API (backend) |
| Web server | A server that speaks HTTP to the outside world: serves files, terminates HTTPS, forwards other requests. | Nginx, Caddy, a CDN edge |
| Application server | Where your own code runs: the business logic ("is this user allowed?", "what's the total?"). | A Node.js, Java, Go or Python service |
| Database | A program that stores data safely on disk and finds it again quickly. | PostgreSQL, MySQL, MongoDB |
| Stateless | A server that keeps nothing about a user between requests; everything it needs arrives with the request or lives in a shared store. | Any of 10 identical app servers can answer you |
Put together, most applications have three tiers: a presentation tier (the client), a logic tier (application servers) and a data tier (databases). Almost every design in this course is these three tiers, plus parts added to make them faster, bigger or safer.
2. How it works
A web page usually arrives in two steps. First the browser fetches the page's files (HTML, JavaScript, images), which are the same for everyone and often come from a web server or a CDN. Then the JavaScript in that page asks the API for this user's data, which the application server builds from the database. Phone apps skip the first step: the app is already installed, so they only call the API.
One request, step by step
Here is what happens when you open note 7 in a notes app. Each step is one hop; press Play or use the arrow keys.
Stateful vs stateless servers
When one server isn't enough, you run several copies behind a load balancer (Module 08). That only works if any copy can answer any request. If a server keeps your login in its own memory, the next request may land on a different server that has never heard of you.
3. Try it yourself
Talk to an API
A notes app has a small REST API. Pick an action and the conditions, and see the exact request your client sends and the response the server returns.
Where should the login live?
Four requests from one user arrive through a load balancer that takes turns between the app servers. Choose where the server remembers that the user is signed in, how many servers there are, and whether one restarts halfway.
4. Trade-offs
Stateless vs stateful servers
Stateless servers can be added, removed or restarted freely, because nothing is lost. The price is a round trip to a shared store (or a larger request) to fetch the state each time. Keep state in servers only when you must, as with live chat connections (Module 19).
One server vs separate tiers
Running the code and the database on one machine is simplest and fine for a new product. Separating them lets each be sized, scaled and secured on its own, at the cost of a network hop and more machines to run.
Pages built on the server vs in the browser
Server-rendered pages show content faster on first load and are easy for search engines. Browser-rendered apps (single-page apps) feel smoother once loaded and reuse the same API as the phone apps. Many sites mix both.
Managed vs self-run databases
A cloud provider's managed database handles backups, patches and failover for a higher price per machine. Running your own gives control and lower raw cost, but your team does the 3 a.m. recovery.
5. In real systems
A typical web product today looks like this. Every row is a later module.
| Layer | Job | Common choices | Learn more |
|---|---|---|---|
| Client | Shows the interface, calls the API | Browser apps (React, Vue, plain HTML), iOS and Android apps | 01 |
| Edge | Finds the server, serves static files from nearby, blocks attacks | DNS, CDNs | 10 |
| Front door | HTTPS, routing, spreading load | Load balancers, reverse proxies (Nginx, Envoy), API gateways | 08 |
| Application servers | Your business logic, stateless | Node.js, Python, Java, Go, often in containers | 07 |
| Data | Keeping data safe and findable | Relational databases (PostgreSQL, MySQL), caches (Redis), file storage (object stores) | 11, 09 |
| Background work | Slow jobs users shouldn't wait for | Queues and workers | 18 |
Say it in the interview
- "What's an API?" The contract a server offers: which requests it accepts and what each returns. Clients depend only on that contract, so the server can change inside without breaking them.
- "Why stateless servers?" So any copy can serve any request: we can add servers for load, remove them, or lose one without users noticing. State goes to a database, a cache or a signed token.
- "Web server vs application server?" The web server handles HTTP itself (files, HTTPS, forwarding); the application server runs our code. Small apps combine them; large ones separate them.
- The browser talking directly to the database: nothing would check permissions.
- Sessions kept in one server's memory behind a load balancer.
- Using "server" for the machine, the program and the whole backend interchangeably without noticing.
6. Remember it
How this hook works: what "Ask, answer, keep" means
What the slogan means, phrase by phrase
- "Ask"
- The client sends a request through an API: it never reaches into the server's insides.
- "answer"
- The server runs the logic and replies, then forgets the request (stateless).
- "keep"
- Only the database is responsible for remembering, safely, on disk.
Why this picture fits: it separates the three responsibilities, and most beginner mistakes mix two of them (the client keeping secrets, the server keeping state).
The story → the concept
| Restaurant | System |
|---|---|
| Diner | Client |
| Menu | API |
| Waiter | Request and response (and the web server that carries them) |
| Kitchen | Application server |
| Pantry | Database |
Watch it on an example
- Ask: the phone app sends
POST /orderswith the items. - Answer: the app server checks stock and prices, then saves the order.
- Keep: the database stores the order; the app server keeps nothing, so any copy could have handled it.
The trap it saves you from
Putting memory in the wrong place: a total computed only in the browser (which a user can change), or a cart held in one server's memory.
7. Common mistakes
8. Design exercise (20 minutes)
- Draw three apps (10 min). For a to-do list, a photo-sharing app and a chat app, draw client, API, application server and database. Write the three most important API requests for each.
- Find the state (5 min). In each app, list what must be remembered between requests (sessions, uploaded photos, unread messages) and where you'd keep it.
- Break it (5 min). For each app, say what users see if the database is down, and if one of two application servers crashes.
9. Self-check quiz
A browser needs a user's orders. What should it talk to?
What does "stateless server" buy you?
A request arrives with no login. Which response fits?
What is an API?
Where should a site's images and JavaScript files be served from?
10. Go deeper
| Resource | Time | Why |
|---|---|---|
| Client-server overview (MDN) | 20 min | How a website's client and server divide the work, with examples. |
| An overview of HTTP and status codes (MDN) | 25 min | The messages clients and servers exchange. |
| The Twelve-Factor App: processes | 5 min | The classic short case for stateless processes. |
| Presentation, domain, data layering (Martin Fowler) | 10 min | Why applications are split into these three layers. |