Design · lesson 2 of 10
Ideas in this lesson
AClient and serverone asks, the other answers
BLayerseach part talks only to the one below
CMonolith and servicesone program, or several that talk over a network
DQuality attributesfrom lesson 3.6

Architecture

Last updated

An architecture is the big shape of a system: what the main parts are and how they connect. A few shapes come up again and again, and each makes some things easy and others hard. In this lesson you'll follow one text message through Pila's parts, meet clients and servers, layers, monoliths and services, and see why the right shape depends on the qualities the system needs.

By the end of this lesson you can

  • Describe client and server, layers, a monolith and services
  • Trace one request through a system's parts
  • Explain why quality attributes, not fashion, should drive the architecture

Follow one text message

Before naming shapes, look at one. Here is Pila's architecture, as one text from Lola Remy passes through it. It's drawn as a UML sequence diagram, which lesson 4.4 explains: each part is a column, and time runs down the page. Walk through it.

Lola Remy:SMS gateway:Web server:Queue rules:Database:Screentext “PILA”POST /v1/ticketstake_number(phone)save(ticket 38)saved38201, reply text“You are no. 38”GET /v1/queue/nownow serving 31

Press Walk through it to follow the messages in time order, one stop at a time.

  1. Lola Remy texts PILA to the SMS gateway, without waiting.
  2. The gateway calls Pila’s web server (POST /v1/tickets), which calls the queue rules: take_number(phone).
  3. The queue rules save ticket 38 in the database, which replies.
  4. Replies go back up: 38 to the web server, 201 and the reply text to the gateway, and a text to Lola Remy.
  5. Separately, the waiting-room screen asks the web server who’s being served (GET /v1/queue/now), and gets the answer.
One text message traced through Pila. A UML sequence diagram: each part is a lifeline, a box (or a stick figure for a person) with a dashed line below it, and time runs down the page. A solid arrow with a filled head is a call whose sender waits for the answer; an open head means the sender doesn’t wait; a dashed arrow is a reply.

Five parts, each with one job. Lola Remy sees none of them.

Clients, servers and layers

Two shapes are already in that picture.

Client and server. A client asks; a server answers. The waiting-room screen is a client of Pila's web server; so is the SMS gateway, when it passes on a text. Pila is itself a client of the gateway when it sends a reply. Most systems you use are clients and servers, talking over a network.

Layers. Inside Pila's server, the code is arranged in layers, each using only the one below:

Pila’s layers
LayerIts jobKnows nothing about
Web (top)Turn requests into calls, and results into repliesThe queue rules’ details
Queue rulesWho gets which number, the limit, the priority laneWeb requests, or how data is stored
Storage (bottom)Save and load tickets in the databaseWhy the rules want them

Layers keep a change in one place. If the centre's closing time changes, only the queue rules change. If the database changes, only storage changes.

One program, or several?

A monolith is a system built and run as one program, even if its code is in tidy layers and modules. A services architecture (often called microservices when the services are small) splits it into several programs that talk over the network: a queue service, an SMS service, a reporting service, each deployed on its own.

Martin Fowler and James Lewis describe services as a way to let many teams change and release parts independently. The price is high: network calls that can fail or be slow, data split across services, and many more things to deploy, monitor and keep in step. Fowler's advice, "MonolithFirst", is that most systems that succeeded with services started as a monolith and split later, once the boundaries were understood.

0 of 5 placed right

  1. Two developers build and run everything

  2. Testing the whole flow from text to reply on a laptop

  3. Fifty teams each releasing their own part daily without waiting for each other

  4. One part needs a hundred times the computing power of the rest

  5. Finding out why a reply was slow

A third shape, event-driven, has parts announce what happened ("number 38 was called") so any interested part can react without being asked. It suits systems where many parts must react to the same events. Pila might use it one day to add vaccination reminders without touching the queue.

Qualities drive the shape

Why is Pila a small monolith in layers? Not because monoliths are better. Bass, Clements and Kazman's Software Architecture in Practice argues that an architecture is chosen to meet quality attributes: the non-functional requirements of lesson 3.6.

  • Performance (300 texts an hour): easily met by one program and one database.
  • Reliability (up on 99.5% of mornings): fewer moving parts means fewer things to fail.
  • Maintainability (two developers): one codebase they can hold in their heads.
  • Cost: one small server, within the barangay's budget.

A national queue system for every health centre would weigh those differently, and might rightly be split. The same reasoning, different requirements, a different shape.

Spot the trap: ten services for two people

Spot the trapMarco

Marco has been reading about how a famous streaming company built its system. He draws Pila as ten microservices: tickets, texts, screen, staff, reports, and five more.

What happens if…

Check what you learned

The waiting-room screen asks Pila’s web server who’s being served. Which is the client?
What does splitting a system into services cost?
What should decide a system’s architecture?

Sources

Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.

All sources for Simple Software Development