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
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
- Explain why design reasons through a mental model, and why ad-hoc design fails to scale or integrate.
- Decompose a system with the four design questions into client, server and device, and justify offloading.
- Define a relationship as protocol plus interface and keep lower-level relationships out of scope on purpose.
- Specify interactions as request and reply pairs and compute energy in kWh without confusing power and energy.
- Map interactions onto HTTP and justify GET as safe and PUT as idempotent, including retry behavior.
- Distinguish the server component from the server layer and connect the layer to cloud, fog and edge.
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.
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.
Control a lamp over the Web
Answer the four design questions in order
Client, server and device with defined relationships
| Aspect | Ad hoc | Structured |
|---|---|---|
| Planning | None | Up front |
| Works for | One small task | Growing systems |
| Adding a feature | Rework | Plug into a named interface |
| Integration | Hard | Defined by relationships |
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?
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.
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.
User-facing interface
Processes requests, talks to the device
The lamp
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.
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.
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.
| Part | Question it answers | Lamp example |
|---|---|---|
| Protocol | How do we talk? | HTTP |
| Interface | What can I ask for? | /lamp/state and /lamp/energy |
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.
| Interaction | Request carries | Reply |
|---|---|---|
| Set_on_off | The target state (on or off) | ok |
| read_energy_usage | Nothing extra | An energy value in kWh |
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.
Worked example
Energy of the lamp
Power
100 WTime
10 hMultiply
100 W × 10 h = 1,000 WhConvert
1,000 Wh ÷ 1000 = 1 kWhResult
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?
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.
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.
| Method | Interaction | Safe | Idempotent | Changes lamp |
|---|---|---|---|---|
| GET | Read | Yes | Yes | No |
| PUT | Set | No | Yes | Yes |
| POST | None (for contrast) | No | No | Depends |
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?
Recall
Relationship equals what? Give the lamp example of each part.
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.
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
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?
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
- RFC 9110: HTTP Semantics (STD 97, June 2022)RFCIETFSections 9.2.1 safe methods, 9.2.2 idempotent methods, 9.3.4 PUT, 15.3.5 204 No Content(opens in a new tab)
- RFC 9205: Building Protocols with HTTP (BCP 56, June 2022)RFCIETFGET handling should not change application state because GET requests are retried(opens in a new tab)
- PUT request methodDocsMDN Web Docs (Mozilla)PUT is idempotent but not safe(opens in a new tab)
- IdempotentDocsMDN Web Docs (Mozilla)(opens in a new tab)
- Mental models and human reasoning (Johnson-Laird, 2010)PaperProceedings of the National Academy of SciencesModels mirror the structure of what they represent and represent only what is true(opens in a new tab)
- ad hocArticleOnline Etymology DictionaryLatin for this specific purpose; the sense 'appointed for some particular purpose' is recorded from 1879(opens in a new tab)
- Glossary: Kilowatt, KilowatthourDocsU.S. Energy Information Administration(opens in a new tab)
- Energy Series: Estimating Appliance and Home Electronic Energy UseArticleVirginia Cooperative Extension, Virginia TechWattage times hours divided by 1000 gives kWh(opens in a new tab)
- SP 800-145: The NIST Definition of Cloud Computing (Sept 2011)DocsNIST(opens in a new tab)
- SP 500-325: Fog Computing Conceptual Model (March 2018)DocsNIST(opens in a new tab)
- Computer Networking: A Top-Down Approach, 9th ed. (Kurose and Ross)BookPearsonBackground reading on client-server and HTTP(opens in a new tab)