How it works · 6 of 49 Foundation

What is layered (n-tier) architecture?

And the layer that only passes things on

Layered (n-tier): Layered architecture stacks the code in floors (presentation, domain rules, data access) and lets each floor call only the one below, so you can think about one floor at a time; the price is that every request, and every new field, travels through every floor, even the floors that add nothing.

Loading the animation…

Say it like this Layers let you think about one floor at a time, but every request and every new field travels through all of them, so open a floor only for reads that need no rules.

Under the hood — for builders
The source, in its words
Martin Fowler, "Presentation Domain Data Layering" (martinfowler.com, 26 Aug 2015): the three layers are "presentation (UI), domain logic (aka business logic), and data access". The biggest gain is that layering lets him "reduce the scope of my attention"; the others are swapping an implementation and seams for testing. The catch: a UX change often needs a domain change, which "necessitates a change to the data layer". He calls splitting development teams by layer an antipattern: "Developers don't have to be full-stack but teams should be."
This card's app, floor by floor
Each layer owns one kind of work; a new field crosses all four. Closed layers (each calls only the one below) are the default; an open layer is one the floor above may skip.
Run here: what a pass-through layer costs
The same hotel app in Python, 200,000 reads of one booking, median of five runs. Going through the rules layer, which only copies the record and passes it on, against letting reads skip it:
So what: the sinkhole costs code, not speed
In one process a pass-through layer costs about 60 ns: nothing a user notices. Its cost is the extra code every change must touch and the rules it can be used to skip. When each layer is a separate server (a true n-tier deployment), every floor adds a network round trip instead, which is module C's subject.
Measure it
Share of requests where a layer only forwards (a high share means that layer is a sinkhole) · files touched per new field · calls that skip a layer, and whether any of them write.
Watch out
Open a layer for reads only, and write the exception down. Never let writes skip the domain layer. Above one team's size, split the app by domain first, each part layered inside (Fowler).
Sources
Fowler, "Presentation Domain Data Layering", martinfowler.com, 26 Aug 2015, read in session · toy hotel app, Python, run for this card 18 Nov 2026.

What happens in the layered (n-tier) animation, step by step?

  1. Layered: the code is stacked in floors, and each floor hands work only to the one below. A booking is checked, ruled on, then saved.
  2. Now a slip that only reads. The managers' floor applies no rule; it just marks it "passed on". Every floor is still a stop.
  3. Your turn: which floor may reads skip? Tap it.
  4. But a write slipped through the same gap. Nobody checked the 3-night rule, and a 9-night booking was saved.
  5. Layers keep a request easy to follow, but one new field still means an edit on every floor.
  6. The rules floor still knows what sits in the basement. Next: keep the core ignorant of the database.

What everyday example explains layered (n-tier)?

A hotel's back office. A guest's slip goes from reception to the duty manager to the records clerk, each initialling it, even when the guest only asked "where's the lift?". Letting easy questions skip the manager saves a stop; letting room bookings skip the manager means nobody checks the rules.

Why should a team care about layered (n-tier)?

When a framework hands you controller–service–repository folders, decide which reads may go straight to data access and write it down; never let writes skip the rules; and once a layer grows past one team, split by domain first, then layer inside each part.