Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 50 ยท Software Design

Architecture Styles

Compare common software architecture styles: layered, client-server, event-driven, pipes and filters, monolith vs services and hexagonal, with trade-offs.

If design principles are about how to shape one module, architecture is about how the big pieces of a system fit together: what the main parts are, what each is responsible for, and how they communicate. Architecture is the set of decisions that are expensive to change later. Renaming a function takes a minute; moving from one big program to many cooperating services takes a year.

An architecture style (or pattern) is a named, proven way of arranging those pieces. Each style makes some qualities easy and others hard, so choosing one is always a trade-off. This lesson introduces the styles you will meet most often. None of them can be "run" as such; the runnable example at the end is a small JavaScript stand-in for one style, pipes and filters, to show how its parts connect.

Layered architecture

The most familiar style stacks the system into layers. Each layer has one role and may use only the layer directly below it.

A typical layered system

Presentation Screens, forms and API endpoints.
Business logic The rules that make the product what it is.
Data access Reading and writing storage.

Requests go down, results come back up. Layers never skip or look upward.

1 / 2

Layering applies separation of concerns directly. Its strengths are simplicity and familiarity: almost every developer knows how to find things in a layered codebase, and you can swap a layer (say the database) with limited impact. Its weaknesses: a simple change may touch every layer, and many layers can become pass-through code that only forwards calls ("sinkhole" layers). Strict layering also tends to put the database at the center of everything, because every layer ends up depending on it indirectly.

Client-server

In client-server, a client asks and a server answers. Web browsers and web servers, mobile apps and their back ends, and database clients and database servers all work this way. Many clients share one server, which makes data central and easier to protect and update. The costs: the server is a bottleneck and a single point of failure unless you replicate it, and every interaction crosses a network that can be slow or broken. Variations include three-tier (client, application server, database) and peer-to-peer, where each node is both client and server.

Event-driven architecture

In an event-driven system, components do not call each other. A component that notices something happens publishes an event ("OrderPlaced"), and any number of other components that care subscribe and react.

flowchart LR
    O["Orders service"] -->|"OrderPlaced"| B(("Event bus"))
    B --> I["Inventory"]
    B --> E["Email"]
    B --> A["Analytics"]

The orders service knows nothing about who reacts to its events. Adding a new reaction means adding a subscriber, not editing orders.

The producer is decoupled from its consumers: you can add a fourth subscriber without touching the first three, and slow work can happen later. The costs are real. The flow of control becomes hard to see (who reacts to this event?), ordering and duplicate delivery need thought, debugging means following messages across components, and results are only eventually consistent: for a moment, inventory may not yet reflect an order.

Pipes and filters

In pipes and filters, data flows through a chain. Each filter takes input, transforms it and passes output on through a pipe to the next filter. Filters do not know about each other, only about the shape of the data. The Unix command line is the classic example: cat log | grep error | sort | uniq -c. Compilers (lexer, parser, optimizer, code generator) and data pipelines follow the same idea.

Filters are easy to test alone, reorder, reuse and run in parallel. The style fits one-way transformations poorly: interactive programs, or work needing shared state or rich error handling across steps, are awkward in a pure pipeline. Choose filters with a common data format, or you will spend the savings on conversions.

Monolith vs services

A monolith is deployed as one unit: one codebase, one build, one process (or several identical copies). A service-based architecture splits the system into separately deployed services that talk over a network. Microservices is the fine-grained end of that spectrum, with each service owning its own data and being run by a small team.

Monolith Services
Deployment One thing to ship Many things to ship
Local development Simple Needs many parts running
Scaling Whole app at once Each service separately
Team independence Shared codebase, more coordination Teams can work and release independently
Failure One bug can take down all Partial failure, but also network failure modes
Data consistency One database, transactions Distributed data, eventual consistency
Operational burden Low High: monitoring, versioning, tracing

Beginners often assume services are "more modern, therefore better." In practice, many successful systems begin as a well-structured monolith whose modules have clear boundaries and are split out only when team size or scaling needs justify the operational cost. A badly structured monolith turned into services becomes a "distributed monolith": all the pain of a network, none of the independence.

Hexagonal architecture (ports and adapters)

Hexagonal architecture, also called ports and adapters, puts the business logic in the middle and surrounds it with replaceable edges. The core defines ports, interfaces describing what it needs ("save an order", "send a notification") and what it offers ("place an order"). Adapters plug into those ports: a web controller, a command-line tool or a test is a driving adapter that calls in; a SQL repository or an email gateway is a driven adapter that the core calls out to.

The dependency rule is the point: the core depends on nothing outside itself. Adapters depend on the core, never the reverse. That makes the business rules testable with fake adapters, and lets you swap a database or a web framework without rewriting the rules. Related styles, such as "clean architecture" and "onion architecture", share the same direction of dependencies. The cost is extra interfaces and mapping code, which is wasteful for a tiny application.

A pipe-and-filter stand-in

Real pipelines run in separate processes or tools. This stand-in is plain JavaScript that models the idea: each filter is a function from one list to another, and pipeline chains them. Because filters only agree on the data shape (a list of log lines in, a list out), you can reorder or reuse them freely.

JS A pipe and filter chain

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Nothing in onlyErrors knows that countEach exists. Reusing errorTexts shows the payoff, and adding a new step (say, dropDuplicates) means writing one function and inserting it. This is a stand-in: a real pipeline would also deal with streaming, back-pressure and failures between steps.

Comparing styles by quality

Because styles optimize different qualities (see software qualities), a small scoring model can make the trade-off visible. The numbers below are illustrative opinions, not measurements; change them to match your own context and see the ranking move.

JS Rank styles against what your project values

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The tool does not "decide" architecture. Its value is making you state what matters and noticing that no style wins everywhere. In real projects you would also consider team skills, existing systems, budget and deadlines, and you would record the choice and its reasons, which is the subject of the next lesson on architecture decisions.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. In a strict layered architecture, which direction may dependencies go?

    Requests flow down through adjacent layers; upward or skipping calls break the layering.
  2. 2. What is the main risk of an event-driven architecture?

    Decoupling is the benefit; the price is tracing who reacts to what and tolerating a delay before all parts agree.
  3. 3. Why do many teams start with a well-structured monolith?

    A modular monolith is cheap to run and can be split later along its existing boundaries.
  4. 4. In hexagonal architecture, which way does the dependency rule point?

    The core defines ports; adapters implement them. This keeps rules testable and infrastructure replaceable.
  5. 5. Which style best fits a one-way chain of transformations such as a compiler?

    Each stage transforms data and passes it on, which is exactly the pipes and filters shape.

Summary

  • Architecture is the set of big structural decisions that are costly to change.
  • Layered systems separate concerns by stacking layers; simple, but changes can cut through every layer.
  • Client-server centralizes data and logic; event-driven decouples producers from consumers at the cost of traceability.
  • Pipes and filters chain independent transformations over a shared data format.
  • Monolith versus services trades simplicity for independent deployment and scaling; many systems should start modular and split later.
  • Hexagonal architecture keeps the business core free of infrastructure through ports and adapters.
  • Every style is a trade-off; choose by the qualities your project values.

Next: Architecture Decisions and Documentation.