The idea: one order, three ways to split the work

An architecture style is a rule for how the parts of a system may talk to each other. The canvas runs the same small shop three times. Each time the same order arrives: BOOK × 2 at 12.00, so 24.00. Only the style changes:

  • Layered (left): parts are stacked in layers, and a layer only calls the layer under it.
  • Pipe-and-filter (top right): parts are filters in a row, joined by pipes, and data only flows forward.
  • Event-driven (bottom right): parts publish events to a broker, and other parts react to them.

Blue boxes are calls and data, green boxes are answers, purple boxes are events and red boxes are errors. After a request, green parts did work and grey parts only passed the call on. Each panel's status line counts the messages.

Three small diagrams side by side. Layered: five stacked boxes, Presentation, Business, Services, Persistence, Database, with arrows down and answers back up. Pipe-and-filter: orders in, Parse, Validate, Price, Format, invoices in a row with one-way arrows. Event-driven: Order service publishes to a broker, which delivers to Payment, Inventory and Email
Layers call down and answer up; filters push data one way; event-driven parts never call each other, only the broker.

Layers, closed and open

The classic layered (n-tier) style has four or five layers. Each has one kind of job:

LayerOn the canvasJob
PresentationOrderControllerread HTTP, write HTTP answers
BusinessOrderServicebusiness rules (1 ≤ qty ≤ 5)
Services (shared)PricingServicework several business parts reuse
PersistenceOrderRepositoryturn objects into rows and SQL
DatabaseMariaDB ordersstore the rows

A closed layer can't be skipped: a call must pass through it to reach the layers below. That is layers of isolation: Presentation knows nothing about SQL, so you can change the database code without touching the controller. The cost is the trip. One order goes down five layers and the answer comes back up the same way: 10 messages (Demo 1: one order, five layers).

An open layer may be skipped. Here the Services layer is a natural one to open: Business calls it only when it needs a price, and otherwise calls Persistence directly. Open layers save hops, but now Business depends on two layers below it, so changes spread further.

The architecture sinkhole

A plain read (GET /orders/1) has no business rule and nothing to price. With Services closed, Business and Services only forward the call: 10 messages, of which 4 go through layers that do nothing (Demo 2: a read sinks through). Mark Richards calls this the architecture sinkhole anti-pattern. A few such requests are normal. His rule of thumb: if more than about 20 % of requests are sinkholes, open some layers or rethink the split. The layered panel counts "sinkhole requests k of n".

Open the Services layer and the read skips it: 8 messages, one pass-through layer left (Demo 3: open the services layer). Take the Services layer down to see the other side of the choice: closed, even a read fails with 503; open, the read still works.

Two columns of five layers. Left, Services closed: the read GET /orders/1 passes through Business and Services, both grey pass-through, 10 messages. Right, Services open: Business calls Persistence directly, Services is skipped, 8 messages
The same read: a closed Services layer adds two pass-through hops; opening it removes them.

Pipe-and-filter

A filter reads records from its input pipe, does one job and writes the result to its output pipe. A pipe only carries data; it has no logic. The source and the sink are the two ends. The order line BOOK,2 becomes fields, is checked, gets the price 24.00 and turns into the invoice line INV-1: 5 hops, 4 filters doing real work, and no answer ever travels back (Demo 4: order as a pipeline).

Filters know nothing about each other, so you can reorder them, reuse them and add new ones. Compilers, ETL jobs, media processing and Unix shell pipelines (How the Shell Runs ls | grep foo) work this way. The weak spot is interaction: "view order" has no path in a pipeline, because nothing answers.

Event-driven, broker topology

In the broker topology there is no central controller. The Order service saves the order, publishes OrderPlaced to the broker and answers 202 Accepted at once. Payment and Inventory receive the event and work in parallel. Payment then publishes a new event, PaymentDone, which Email receives. The work is a chain of events: 7 messages, 2 events, 3 deliveries, and the client had its answer at message 3 (Demo 5: order as events).

The other topology, the mediator, puts an orchestrator in the middle that sends commands to each step in order. It is easier to follow and to handle errors in, but the mediator becomes a central part every flow depends on. How the broker hands out events is shown in Observer vs Publish–Subscribe and Kafka.

What a change touches

Press Show Impact. The yellow boxes are the parts you would edit (Demo 6: what a change touches):

ChangeLayeredPipe-and-filterEvent-driven
add a field (a gift note)5 layers (4 if Services is open)2 filters: Parse, Format3 services: Order, Payment, Email
add a step (a fraud check)1 layer: Business0 edited, 1 new filter0 edited, 1 new subscriber

Layers are cut by technical job, so a change that is about one business feature (a new field) crosses all of them. A change inside one job (a new rule) stays in one layer. Filters and event consumers only touch the data they use, and a new step is a new part, not an edit. Note the Payment service in the event row: Email reads PaymentDone, so Payment must copy the gift note into it. Event chains carry data along.

What a failure stops

Use Down / Up in Options, then send a request (Demo 7: one part down in each):

DownWhat happens
Database (layered)the call chain is synchronous, so the error climbs through every layer: 9 messages, 503, no row
Price filterthe record waits in the pipe before Price (1 waiting); Parse and Validate keep working; bring Price up and it drains
Email servicethe client still gets 202, the charge and the stock are done; PaymentDone waits in the broker until Email is back
Brokerthe publish fails, the order is rolled back, 503: every part depends on the broker
Three rows. Layered: Database down, red error arrows climb through Persistence, Services, Business and Presentation to the client. Pipe-and-filter: Price down, one record waits in the pipe before it, the filters before it still work. Event-driven: Email down, the PaymentDone event waits in the broker while the client already has 202
A synchronous chain fails as a whole; a pipe or a broker queue turns a dead part into waiting work.

Choosing a style

  • Layered: simple, familiar, cheap to start; good for request/answer business apps. Watch for sinkholes and for features that cut across every layer. To protect the business core from the database, invert the bottom dependency: Hexagonal Architecture.
  • Pipe-and-filter: data processing in steps, batch jobs, streams. Poor for interactive requests.
  • Event-driven: many independent reactions to the same fact, high load, parts that may be slow or down. Harder to follow, test and debug; the client gets "accepted", not "done".

Real systems mix them: a layered service that publishes events, or a UI layer built with MVC or MVVM. Whether the parts run in one process or many is a separate choice: Monolith vs Microservices.

What the page leaves out

Transactions across layers, the transactional outbox that makes "save and publish" atomic (Transactional Outbox and Inbox), duplicate and out-of-order events, the mediator topology in action, back-pressure when a pipe fills up, parallel and branching pipelines, layers that run on separate machines (tiers), and the cost of mapping data between layers.

On the mind map

Open the Software Design mind mapSoftware DesignPrinciples: keep each change localPrinciplesDesign patterns: named fixes for common designsDesign patternsArchitecture: the shape of a whole appArchitectureEnterprise app patterns: logic, SQL, locks, money (PoEAA)Enterprise app patternsGit storage: content named by its hashGit storageGit branches & merging: pointers to commits, then mergeGit branches & mergingTesting: check code in isolationTestingHexagonal architectureHexagonal architecturedomain in the middle, adapters at portsLayered vs Pipes vs EventsClosed layers add hops; queues absorb faultsUML Sequence DiagramUML Sequence DiagramTime runs down; one arrow per callUML class diagramUML class diagramA field is a line; diamond = whole and partsState and activity diagramsState and activity diagramsExits inside out, entries outside inVirtual DOM diffingVirtual DOM diffingdiff new tree vs old, patch only changesMVC vs MVVMMVC vs MVVMController routes input; view-model bindsOpen the Software Design mind mapSoftware Designthe shape of a whole appArchitectureHexagonal architectureHexagonal architecturedomain in the middle, adapters at portsLayered vs Pipes vs EventsClosed layers add hops; queues absorb faultsUML Sequence DiagramUML Sequence DiagramTime runs down; one arrow per callUML class diagramUML class diagramA field is a line; diamond = whole and partsState and activity diagramsState and activity diagramsExits inside out, entries outside inVirtual DOM diffingVirtual DOM diffingdiff new tree vs old, patch only changesMVC vs MVVMMVC vs MVVMController routes input; view-model binds
This page on the Software Design mind map · 38 pages in 7 branches · open it to see the whole map and test yourself in recall mode.