Book Deep Read · Fundamentals of Software Architecture · Chapter 10

Layered Architecture: The Cheapest Default Shape, and Its Sinkhole

Fundamentals of Software Architecture · Ch 10 · Mark Richards & Neal Ford · 2020

中文 →

What is this chapter about?

The expense form on your company intranet, a university course-registration site, the order back-office of a small online shop: the software behind them almost always has the same shape, one layer stacked on another. On top is the screen you see; below it are the rules ("can this expense be approved?"); below that, a layer that fetches and saves data; at the bottom, the database. This chapter is about that most common, cheapest shape: why everyone reaches for it, and when it starts holding you back.

An analogy: an office building with one trade per floor

Picture a building. The ground floor is reception and only greets visitors. The second floor is the business department and only makes decisions. The third floor is the records room and only opens filing cabinets. A visitor's request has to be passed up one floor at a time; reception may not barge into the records room. The upside: clean division of labor. If the records room buys new cabinets, reception never needs to know. The downside: even if the visitor only asks "what's my file number?", reception still hands it to the business floor, which does nothing and passes it straight up. The more floors, the more wasted trips.

Why the old world was hard

Many teams never think about "shape" at first. They just start coding: screens query the database directly, rules are scattered everywhere, and it all ends up in a tangle. Layering is the most natural first cleanup: sort code by the kind of job it does. Screens with screens, rules with rules, data access with data access. It also matches how companies already split people (front-end team, back-end team, database team), so almost nobody has to be taught it.

The core mechanism: a gate, and the occasional side door

The real point of layering isn't how many layers you have. It's the gate: each layer may only call the one directly below it, with no skipping. That way, as long as the hand-off between two layers stays the same, one layer can change its insides and nobody else notices. That's the new filing cabinets again: reception doesn't feel a thing. Sometimes you deliberately open a side door. Small shared helpers that everyone uses, like "stamp it" or "write it in the log", can live on their own floor, and the business floor is allowed to walk past it straight to the records room instead of getting an extra stamp on every errand.

Watch out for wasted trips. If most requests are simply handed along at every floor with no rule applied anywhere, the book has a name for it: a sinkhole. Water flows from top to bottom and nothing filters it on the way. A few such requests are fine. If most requests look like that, the building itself is the wrong design for you.

What it buys you / how to choose

Layering fits best when the system is small and simple, the budget and schedule are tight, or you don't yet know what you'll end up needing. It's cheap, easy to understand, and you can start today. But it ships as one block: change one word and the whole program is redeployed; to handle more traffic you can only copy the whole thing; if memory blows up in one corner, everything goes down together. There is also a quieter cost: the code for one business area (say, "customers") is chopped up across every layer, so changing one feature means touching every layer.

One sentence to remember

Layering is one trade per floor. The gates keep floors from disturbing each other; the price is that requests climb floor by floor, business features get sliced apart, and the whole building moves as one. When most requests are just making wasted trips, it's time for a different shape.

Want closed vs open layers and layers of isolation, the sinkhole 80/20 rule, technical vs domain partitioning, the book's star ratings and a selection table? → Switch to Deep Read