Skip to the workspace
Pebellslearn by building
Architecture  ›  Lesson

Client/Server and Layered

Layered 14 minClient/server splits a system into clients that ask and a server that answers, and a layered design stacks the server's code so each layer only depends on the one beneath it.

software architect / Client/Server and Layered

Explore each scene at your own pace.

01 · The rule

The rule

Client/Server and Layered

When a DabbaGo customer taps "Order", her phone does not cook anything or charge anyone. It sends a request to DabbaGo's server and waits for an answer. Inside that server, the request passes through a stack of code: one part reads the request, another applies the 10:30 am cut-off, another saves to the database. These two ideas, client/server and layers, are the oldest and most common architectural styles, and most systems still start with them.

The rule

Clients ask, the server decides; each layer talks only to the one below.

Client/server splits a system in two:

  • Clients: phones, browsers, the kitchen tablet. They show things and send requests. There are many of them, and they cannot be trusted with rules or secrets, because users control them.
  • Server: the shared, trusted side. It holds the data and enforces the rules for every client. The customer app, rider app and kitchen tablet all ask the same server.

That is why the cut-off check belongs on the server. A check only in the phone app could be bypassed by anyone who sends the request another way.

Layered architecture organises the server's code into horizontal layers:

Presentation   receives requests, returns responses (API handlers, pages)
Business       rules: cut-off time, kitchen capacity, pricing
Data access    reads and writes the database
Database

Each layer depends only on the layer directly beneath it. Presentation never writes SQL; data access never decides prices. The payoff: you can change the database with changes only in the data layer, or add a new API alongside the web pages without touching the rules.

Layers have costs too. A simple read may pass through every layer doing nothing but handing data down, sometimes called the sinkhole problem. And layers split code by technical role, so one business feature, such as "skip tomorrow's tiffin", is spread across all three. For small and medium apps, the clarity is usually worth it.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.