Majid Al-RaimiDesigning systems with mental models

COE 558Lecture 01Part 02

Designing systems with mental models

Ad-hoc versus structured design, and the four questions that turn a lamp in a browser into a system: system, components, relationships, layers.

Concepts
6
Slides
8-21
Reading
36 min
Understood
0/6 concepts

Why this part matters

Every exam question about where a service should run, and every research project architecture, starts the same way: someone draws a system as boxes, arrows and layers. This part gives you a four-question checklist for drawing that picture, the vocabulary to name each arrow precisely (protocol versus interface, safe versus idempotent), and the idea the whole course is built on: the server layer can live in the cloud, in the fog or at the edge.

One running story carries the part. You want to switch a lamp on from Chrome and see how much energy it has used. Each concept adds one layer of precision to that story, until the lamp becomes a small but complete system whose server could run anywhere on the continuum.

By the end you can

  1. Explain why design reasons through a mental model, and why ad-hoc design fails to scale or integrate.
  2. Decompose a system with the four design questions into client, server and device, and justify offloading.
  3. Define a relationship as protocol plus interface and keep lower-level relationships out of scope on purpose.
  4. Specify interactions as request and reply pairs and compute energy in kWh without confusing power and energy.
  5. Map interactions onto HTTP and justify GET as safe and PUT as idempotent, including retry behavior.
  6. Distinguish the server component from the server layer and connect the layer to cloud, fog and edge.

Design starts with a mental model, not a part

Before you wire anything for a lamp you want to control from a browser, you already carry a picture in your head: the browser talks to something, and that something talks to the lamp. That picture is a mental model, and the first claim of this part is that good design starts there, not with code and not with hardware.

The claim is really about order. You do not jump from the problem straight to a solution; you first build a simplified representation of how the system works, and then derive the solution from it. The tool for building that representation is system thinking: describe the problem as parts, the connections between them, and the levels they sit on. A system seen this way is made of components, each one box with a job, and layers, each one a grouping of things that sit at the same level of abstraction.

ProblemMental modelSolution\text{Problem} \rightarrow \text{Mental model} \rightarrow \text{Solution}
Design reasons through a model

The problem: a lamp, a browser, and a mysterious arrow

Now make it concrete. Draw Chrome on one side, a light bulb on the other, and one double-headed arrow between them. The browser is the client you already know. The lamp is the device. The arrow is where everything interesting hides. A browser tab cannot switch mains power; it can only send and receive messages over a network. So something must sit between the tab and the bulb, receive those messages, and turn them into electricity flowing or not flowing. The rest of this part is an answer to one question: what is inside that arrow?

The tempting answer: ad hoc

The first answer most people give is a part: "use a sensor", "buy a smart plug", "write a script". That is ad-hoc design, a component chosen before anyone has asked what the system actually is. The phrase comes from Latin ad (to) and hoc (this): for this specific purpose, a sense recorded in English from 1879. An ad-hoc design answers the immediate situation without previous planning.

For one lamp in one room, that can work. Now scale it: 50 lamps, a phone app next to the browser, a monthly energy report. With no named components and no agreed interfaces, each addition is another one-off wire or script, and nothing fits together. Ad-hoc designs may work for small isolated tasks, but they fail to scale or to integrate with larger systems.

The better answer: structured design

Structured design takes the same lamp but fixes the order of work: questions first, components second, code last. Design becomes a process, not a random walk. Notice what comes out of that process. It is not a sensor, a script or a board: it is a system, a named set of parts with defined connections. Named parts are what let a phone app or a second lamp plug in later without rework, and that is why structured design holds up under complexity, scalability and integration.

Problem

Control a lamp over the Web

Structured process

Answer the four design questions in order

System

Client, server and device with defined relationships

Structured design turns a problem into a system
AspectAd hocStructured
PlanningNoneUp front
Works forOne small taskGrowing systems
Adding a featureReworkPlug into a named interface
IntegrationHardDefined by relationships
Ad hoc versus structured, for the lamp

Quick check

What is the main weakness of an ad-hoc design?

The structured process in this lecture is not mysterious. It is four questions, asked in a fixed order, and their highlighted words are the whole vocabulary of system thinking.

The order is forced by dependency. You cannot name relationships before you have components to relate, and you cannot group things into layers before you know what the things are. Treat the list as a reusable checklist: your research project architecture section must answer exactly these questions, and so must any exam answer that asks you to design or critique a system. This concept answers the first two for the lamp; the rest of the part answers the other two.

Recall

What four questions turn a design problem into a system?

What is the system, what are its components, what is the relationship between the components, and what are the layers.

Question one: what is a system?

For the lamp, the boundary is the room plus the network, the parts are the browser and the lamp, and the things that happen between them are "switch on" and "how much energy have you used?". Generalize that and you get the definition: a system is an environment in which interactions occur between components. Three ingredients, each one necessary. The environment draws the boundary. The components are the boxes inside it. Each interaction is an arrow.

System=environment+components+interactions\text{System} = \text{environment} + \text{components} + \text{interactions}
System ingredients

Question two: what are the components?

The lamp is decomposed in two refinement steps, and each step adds one idea. First, separate software from thing: browser and bulb become Application and Device, where the application is everything that is software and the device is the physical lamp. Second, split the application in two. The client is the user-facing interface, the part you touch. The server processes client requests and communicates with the device. That second component is the answer to the mystery of the arrow: it is the thing that sits between the tab and the bulb.

Client
browser

User-facing interface

Server

Processes requests, talks to the device

Device

The lamp

The lamp system decomposed into three components
A click travels client, server, device, and the lamp lights

Read the visual left to right: the click starts at the client, the server relays it, and only when the path reaches the device does the lamp glow. No box can be skipped.

Why split the application: offloading

Why not let the browser do everything? Because a browser tab is a poor place to keep things. It is not running while the tab is closed, so it cannot record energy readings around the clock, and a phone and a laptop would each hold their own copy of the lamp state. The server is always on and shared, so it can do both.

That is offloading: the client hands functions it cannot or should not perform to the server, because the server has the processing and storage. The server hosts those functions as services, such as "set the lamp state" and "read energy use", and the client simply calls them. Deciding what to offload, and to where, is exactly what the task mapping later in the lecture varies: a task can run on the device, at the edge, in the fog or in the cloud.

Recall

Define a system in one sentence, then name the three lamp components.

An environment in which interactions occur between components. The lamp system has a client, a server and a device.

A relationship is a protocol plus an interface

Question three asks what connects the components. Start concrete: between client and server the lamp needs at least two exchanges, "set the state" and "read the energy".

Each exchange is one interaction, and the relationship is the whole set of them. In set notation, an interaction d is an element of a relationship R. That framing is useful because it tells you how to specify a relationship: list its interactions, and then say what every one of them has in common.

dRd \in R
An interaction is an element of a relationship

What they have in common splits into two halves. The protocol is the grammar both sides agree on: message format, order and meaning. For the Web that is HTTP, with its message format, methods, headers and status codes. The interface is the list of operations the server offers: the endpoints, each a method plus a path, that a client may call. Neither half is enough on its own. A shared language with nothing to ask for is useless, and a menu of operations nobody can phrase is equally useless.

Relationship=Protocol+Interface\text{Relationship} = \text{Protocol} + \text{Interface}
The two halves of a relationship
PartQuestion it answersLamp example
ProtocolHow do we talk?HTTP
InterfaceWhat can I ask for?/lamp/state and /lamp/energy
Protocol and interface for the lamp (paths are illustrative)

The relationship we deliberately ignore

There is a second arrow in the lamp system, between server and device, and the lecture is blunt about it: it is not our concern. That is a design decision, not laziness. You may assume the server runs on a microcontroller board wired to the lamp. Inside that board, the program calls a hardware library; the library switches a pin; the pin drives a relay; the relay switches the lamp. That chain is a separate, lower-level relationship with its own protocol and its own interface.

The web client never sees any of it. It sees only the interface the server exposes. This is the payoff of defining a relationship by protocol and interface: each side can ignore the other side's internals, which is abstraction doing its job. Swap the relay for a smart bulb and the client does not change at all.

Quick check

The lamp server offers GET /lamp/energy. In system-thinking terms, what is that endpoint?

A relationship is a set of interactions, so the next step in specifying the lamp is to write that set down. It has two members, and each is a pair: a request from the client and a reply from the server. The client always speaks first.

InteractionRequest carriesReply
Set_on_offThe target state (on or off)ok
read_energy_usageNothing extraAn energy value in kWh
The two lamp interactions
Requests go out, replies come back, and the energy reading arrives

In the visual, each interaction is a request drawn toward the server followed by a reply drawn back to the client, and the meter inside the server fills once the kilowatt-hour reply lands. The device sits behind the server, never talking to the client directly, exactly as the previous concept required.

One design detail matters more than it looks. Set_on_off should carry the value you want (on, or off), not mean "toggle". If the network drops the reply and the client sends the request again, a toggle flips the lamp back, while "set on" twice still leaves it on. Hold on to that thought: the next concept gives the property a name and shows that HTTP builds it into its methods.

What the energy reply actually means

The read interaction returns energy, and that is where many students slip. A watt measures power, which is a rate: how fast energy is being used. A watt-hour measures energy: power kept up for a length of time. A kilowatt-hour is 1 kW (1,000 W) used for one hour, and the usual appliance formula is wattage times hours, divided by 1000.

E=P×tE = P \times t
Energy is power times time

Worked example

Energy of the lamp

  1. Power

    100 W
  2. Time

    10 h
  3. Multiply

    100 W × 10 h = 1,000 Wh
  4. Convert

    1,000 Wh ÷ 1000 = 1 kWh
  5. Result

    read_energy_usage returns 1 kWh.

Quick check

A 60 W lamp stays on for 5 h. What should read_energy_usage return?

Recall

A 2 kW heater runs for 3 h. What energy, in what unit?

6 kWh, which is energy. Not 6 kW, which would be power.

So far the interactions are abstract. On the Web they become concrete: set becomes HTTP PUT, and read becomes HTTP GET. The arrows carrying them are the protocol, HTTP, and the set and read operations exposed on the server edge are the interface, a Web API. The formula from earlier now has a real instance.

Protocol lines seat into interface sockets on the server wall

In the visual, the PUT and GET lines are the protocol, and the two sockets they seat into, set and read, are the interface. Only when both halves meet does the relationship work.

The actual messages

Here is what the two interactions could look like on the wire. Host and paths are illustrative.

Set: PUT request and response

Request line
PUT /lamp/state HTTP/1.1
Host
lamp.example.com
Content-Type
application/json
Body
{"on": true}
Response status
HTTP/1.1 204 No Content

Read: GET request and response

Request line
GET /lamp/energy HTTP/1.1
Host
lamp.example.com
Response status
HTTP/1.1 200 OK
Body
{"kWh": 1.0}

The 204 No Content reply is the HTTP form of the abstract ok: RFC 9110 defines it as the server having fulfilled the request with no additional content to send.

Why GET fits read: safe

RFC 9110 calls a method safe when its semantics are essentially read-only: the client does not request, and does not expect, any state change on the server. Reading energy changes nothing, so GET is the natural fit. RFC 9205 adds a practical reason: implementations can and do retry GET requests that fail, so GET handling should not change application state.

Why PUT fits set: idempotent

Recall the toggle problem from the interaction list. HTTP has a name for the property that solves it. A method is idempotent when the intended effect of several identical requests is the same as the effect of one. PUT, DELETE and the safe methods are idempotent. PUT asks for the target resource to be created or replaced with the state enclosed in the request, so sending {"on": true} twice still leaves the lamp on.

This matters on real links. RFC 9110 says an idempotent request can be repeated automatically if the connection fails before the client reads the response, while a client should not automatically retry a non-idempotent request unless it knows the request is actually idempotent, or that the original request was never applied. Edge devices often sit on flaky wireless links, so this choice decides whether a retry is harmless or a bug.

MethodInteractionSafeIdempotentChanges lamp
GETReadYesYesNo
PUTSetNoYesYes
POSTNone (for contrast)NoNoDepends
HTTP methods for the lamp

Quick check

The client sends PUT /lamp/state with on true, and the connection drops before any reply. What should it do?

Recall

Why is PUT a better fit than a toggle for setting the lamp?

PUT carries the target state and is idempotent (RFC 9110 section 9.2.2), so a client can retry after a dropped connection and the lamp ends in the same state. A toggle would flip twice.

Recall

Relationship equals what? Give the lamp example of each part.

Protocol plus interface. Protocol: HTTP. Interface: the Web API endpoints for setting the state and reading the energy.

Question four asks for the layers. For this system the answer is a single layer, the one where processing and storage happen: the server layer. Answering it forces you to notice that the word "server" has been doing two jobs.

The server component is the program, for example the Python or C code that answers requests for the lamp state. The server layer is that program together with everything it needs to run: the processor executing it, the network carrying requests, the memory holding the current state, and the disk keeping energy history. The component is what you write; the layer is what you must provision.

Server component=Program\text{Server component} = \text{Program}
Server layer=Program+Processor+Network+Memory+Disk\text{Server layer} = \text{Program} + \text{Processor} + \text{Network} + \text{Memory} + \text{Disk}

What each part of the server layer does for the lamp

Program
Handles the HTTP requests
Processor
Runs the program
Network
Carries requests and replies
Memory
Holds the current lamp state
Disk
Stores the energy history
Lifting the lid: the program sits on processor, network, memory and disk

The visual starts with just the program lit, which is the component. The resources rise beneath it and the outline closes around all five: that outline is the layer.

The modern names for the server layer

Now the question the whole course answers: what do we call this layer today? Cloud, fog or edge, depending on where it is placed. Close the lamp story with that in mind. If the program runs on a board next to the lamp, the layer sits on the device side of the continuum (mist, or edge on a nearby gateway). If it runs in a distant data center, it is the cloud.

The standard definitions line up with the layer you just built. NIST defines cloud computing as on-demand network access to a shared pool of configurable computing resources, such as networks, servers, storage, applications and services, that can be rapidly provisioned and released: the same resources as the server layer, pooled at scale. NIST also describes fog computing as a layered model for access to a shared continuum of scalable computing resources, built from fog nodes that sit between smart end devices and centralized cloud services. Cloud, fog and edge together form the edge-to-cloud (E2C) continuum that the rest of the lecture studies.

Quick check

Besides the server program, what does the server layer contain?

Recall

How is the server component different from the server layer?

The component is the program. The layer is the program plus processor, network, memory and disk, and today it is called cloud, fog or edge depending on where it runs.

Recap

If you remember nothing else

  • A mental model built with system thinking sits between the problem and the solution.
  • Ad-hoc design is for one immediate situation; structured design handles complexity, scale and integration.
  • The four questions, in order: system, components, relationships, layers.
  • A system is an environment where components interact. The lamp system is client, server and device.
  • The client offloads processing and storage to the server, which hosts services.
  • A relationship is the set of interactions (d ∈ R), defined by a protocol plus an interface.
  • GET is safe and idempotent; PUT changes state but is idempotent, so it can be retried after a failure.
  • 100 W for 10 h is 1,000 Wh = 1 kWh (energy), not 1,000 W (power).
  • Server component = program. Server layer = program, processor, network, memory, disk, today called cloud, fog or edge.

Sources