Backend Foundations

Lesson 1 of 4

What Is a Backend?

"The backend is where the promises your product makes are either kept or quietly broken." — an engineer who has been paged at 3 a.m.

Open any app you love. Tap a button and a message appears on someone else's screen a continent away. Refresh and your data is exactly where you left it. Pay, and money moves. None of that lives in the app on your phone — the phone is a beautiful window. The machinery behind the glass, the part that remembers, decides, charges, and coordinates millions of these windows at once, is the backend. This volume is about building it.

You have spent seven volumes becoming dangerous: you can program, you know the frontend (React), and you know the data layer (SQL). What sits between them — receiving requests, enforcing rules, talking to the database, and returning answers — is the server side. It is where correctness, security, and scale are won or lost, and it is one of the most reliably in-demand skills in the industry.

The big question

When you tap a button in an app and something happens "on the server," what actually is that server — and why do we put logic there at all instead of just doing everything on the user's device?

Frontend, backend, and the line between them

Software that runs on many people's devices splits, almost inevitably, into two halves:

  • The frontend (client) runs on the user's device — the browser, the phone. It renders the interface, handles interaction, and is fundamentally untrusted: the user controls it and can inspect or tamper with anything in it.
  • The backend (server) runs on machines you control. It holds the shared source of truth, enforces the rules, and does the work that must be trusted, coordinated, or kept secret.

Why not do everything on the client? Because a program that runs on the user's device cannot be trusted with anything that matters:

Concern Why it can't live only on the client Where it belongs
Shared truth Every user has their own device; there's no shared state between them The backend, backed by a database
Trust & security Users can edit client code, forge requests, read anything it holds The backend validates and authorizes every request
Secrets API keys, DB passwords shipped to a browser are public The backend holds secrets; the client never sees them
Coordination Two users buying the last ticket must be reconciled The backend serializes and decides
Heavy/central work Sending email, charging cards, running reports The backend, near the data and the integrations

The rule of thumb every backend engineer internalizes: never trust the client. The frontend is a convenience for the user; the backend is the authority. A price, a permission, a balance — if it matters, the server checks it, no matter what the client claims.

Analogy A restaurant. The frontend is the dining room — menus, tables, the friendly interface where you place your order. The backend is the kitchen and the till: where the food is actually made, the recipe is kept secret, the inventory is tracked, and the money is counted. You can ask for anything at your table, but the kitchen decides what it will actually make — and it will not hand you the cash drawer because you asked nicely.

A backend is a function from request to response

Strip away the frameworks and a backend is astonishingly simple at its core: it is a program that waits for requests and returns responses. A request comes in ("get me user 42"), the server does some work (look it up, check you're allowed to see it), and it returns a response (the user's data, or an error). That's it. Everything else — routing, auth, databases, caching — is structure around that one loop.

Because it's just a function, we can run the essence of it right here. The block below models an HTTP request as a plain object and a handler as a function that returns a response. Click Run:

JavaScript — Try it Yourself
Loading editor…
Console
Runs automatically. Edit the code to see it change.

Three requests, three responses: a 200 with the user, a 404 for someone who doesn't exist, a 405 for a method we don't allow. A real server adds a network listener, a router to pick the right handler, middleware, a real database instead of a Map, and thousands of concurrent connections — but the beating heart is exactly what you just ran: map each request to the right response. Hold onto this mental model; the entire volume is elaborations on it.

In production That tiny handler ignores everything that makes backends hard — and instructive. What happens when 10,000 requests arrive at once? When the database is slow? When the caller isn't who they claim to be? When the same "charge card" request arrives twice because the client retried? Each of those questions is a chapter in this volume. The core stays simple; the engineering is in handling reality gracefully.

What a backend is responsible for

Across almost every system, the backend owns a recognizable set of jobs:

  • Expose an API — a well-defined contract of endpoints the frontend (and other services) call. Most of Part II and III.
  • Authenticate & authorize — know who is calling and what they're allowed to do. Part IV.
  • Validate input — never trust the request body; check it before acting. Part II.
  • Talk to data — read and write the database, cache hot data, store files. Part V, building on Databases (Volume 7).
  • Run business logic — the actual rules: can this order ship, is this transfer allowed, what's the total.
  • Integrate — call other services: payment providers, email, third-party APIs.
  • Do it reliably, at scale, securely — under load, under failure, under attack. Parts VI and VII.

Where "backend" came from Early web pages were static files a server simply handed over. As sites needed to remember things and do things — log you in, take an order — servers began running programs to generate responses dynamically (CGI scripts, then application servers). The split into "front" (what the user sees) and "back" (the engine behind it) hardened into the vocabulary. Today the backend is often not one program but many services talking over the network — but the concept is the same one the earliest dynamic web servers pioneered.

Where the backend runs

The frontend runs on the user's device; the backend runs somewhere you control — historically a physical server in a rack, today almost always a cloud machine or managed platform (AWS, GCP, Azure, or a PaaS like Render/Railway/Vercel functions). One backend process typically serves many users at once, which is why so much of backend engineering is about concurrency (handling many requests without them interfering) and scale (adding more machines as traffic grows). We'll meet the Node runtime and its single-threaded event loop — the surprising way one process juggles thousands of simultaneous requests — in the chapter after next.

Common Mistakes

  • Trusting the client. Putting the price, the permission check, or the "isAdmin" flag in the frontend and believing it. The client is untrusted; the server must re-check everything that matters.
  • Leaking secrets to the browser. Shipping an API key or database credential in frontend code — it's visible to anyone who opens dev tools. Secrets live only on the backend.
  • Putting business logic only in the UI. If two clients (web + mobile) hit the same API, logic in one client isn't enforced for the other. Rules belong on the server, behind the API.
  • Thinking of the backend as "just CRUD." Reading and writing rows is the easy 20%; auth, validation, concurrency, failure handling, and scale are the 80% that make it engineering.

Think about it A shopping app shows a "$0.00" price because of a frontend bug, and a user clicks "Buy." Should the order go through for free? Now imagine a malicious user who edits the request to send price: 0. What single principle protects you in both cases — the innocent bug and the deliberate attack? (Answer: the server computes and trusts its own price from the database, never the client's. Write that on a sticky note; it's the soul of backend engineering.)

Interview Corner — the same idea at three levels. Answer yours; recognise the one above it.
Warm-up
What's the difference between frontend and backend?
Model answer — The frontend runs on the user's device and renders the UI (untrusted, per-user); the backend runs on servers you control, holds the shared source of truth, enforces rules and security, and exposes an API the frontend calls.
Intermediate
Why can't we just do everything on the client?
Model answer — Because the client is untrusted and isolated: it can be tampered with, it can't hold secrets, and every device has its own state with no shared truth. Anything requiring trust, secrecy, coordination, or shared data must run on the server, which validates and authorizes each request.
Advanced
At its core, what is a web server?
Model answer — A long-running program that listens for network connections, parses each incoming HTTP request, routes it to a handler that does work (auth, validation, data access, business logic), and writes back an HTTP response — concurrently, for many clients at once. Everything else (frameworks, middleware, ORMs) is structure around that request→response loop.
Company lens — how the same topic gets asked
micro1the AI screen often starts backend rounds with fundamentals — client vs server, "why not do it on the frontend," what an API is — before having you design or code an endpoint.
Googleexpects you to reason about the request path and where trust boundaries sit, not just name technologies.
Metaproduct-engineering interviews frequently span both sides — expect "the client sends X, what does the server do with it?" and a focus on not trusting client input.
Amazonbackends show up in system design and via "Dive Deep" / "Ownership" — expect follow-ups on what happens when the request fails, retries, or arrives twice.

Hands-on Extend the tiny backend below. Add support for POST (create a user) that (1) rejects a non-POST with the right status, (2) validates that req.body.name is a non-empty string — returning 400 if not — and (3) on success adds the user to the Map with a new id and returns 201 with the created user. Notice how much of "building a backend" is really checking the request before you act on it.

JavaScript — Try it Yourself
Loading editor…
Console
Runs automatically. Edit the code to see it change.

Summary

  • The backend is the server-side program that holds the shared source of truth, enforces rules and security, and exposes an API the frontend and other services call.
  • The frontend is untrusted (it runs on the user's device); the backend is the authority. The golden rule: never trust the client — re-validate and re-authorize everything that matters.
  • Logic lives on the server because of shared truth, security, secrets, coordination, and central work — none of which a per-device client can provide.
  • At its core a backend is a simple loop: map each request to a response. Everything else is structure around that.
  • Backend responsibilities: expose an API, authenticate/authorize, validate input, talk to data, run business logic, integrate, and do it all reliably, at scale, and securely — the map of this volume.

Next, we'll zoom in on the language every backend speaks — HTTP: its methods, status codes, and headers — so that "map a request to a response" becomes concrete and precise.

Editorial reflection There's a quiet weight to backend work that the frontend rarely carries. When your server is wrong, it's wrong for everyone, at once, invisibly — a bad deploy can corrupt a million records before anyone notices. That responsibility is also the craft's dignity: you are the keeper of the promises the product makes. Learn to build backends that are correct under load, honest under failure, and safe under attack, and you become the engineer a team trusts with the things that must not break.

Q&A · 0

Enrol to ask questions and join the discussion.

No questions yet — be the first to ask.