Drawing clear architecture diagrams
35 min · Intermediate
Need help? Ask a tutor on WhatsApp (opens in a new tab)A good design can still fail an interview if the diagram is a tangle of tools and arrows nobody can follow. ShopLite's checkout is simple, yet drawn badly it looks like a mystery.
Your turn: draw ShopLite checkout
Take a blank page and draw what happens when a customer places an order on ShopLite: the browser, the API, the database and the confirmation email. Before reading on, decide your answers to three questions.
- Which boxes does the request pass through, in order?
- Which arrows make the customer wait, and which can happen later?
- What would you write on the database box so a reader knows what is inside?
Keep your page. The next sections show one clear way to draw it, and you can compare.
One good design: the standard boxes
Architecture diagram shows the parts of a system as boxes and how a request moves between them as arrows.
Most backend diagrams reuse the same eight boxes. Here they are in this course's notation.
Example 1 · The standard boxes in this notation
[Client] browser or mobile app[CDN] cache servers near users for images, JS, CSS[Load balancer] spreads requests over app servers[Order service x3] a running program; x3 = three copies[(Redis cache)] a data store: round brackets inside square ones[(MySQL orders)] a data store: technology + what it holds[[order events]] a queue: double square brackets[Email worker] a background program that reads a queue8 standard boxes 3 shapes: program [ ], data store [( )], queue [[ ]]
What this code does
- Each line shows one standard box in the notation with a short meaning.
- The shape tells you the kind of box: square for a program, round inside for data, double for a queue.
The client is a browser or app, a CDN serves static files, a load balancer spreads requests, services are your running programs, a cache and a database hold data, a queue holds work and workers process it in the background.
Standard names save time: the interviewer already knows what a load balancer does, so you only explain what is special. Show different kinds of box differently, so a reader can tell a program from a data store at a glance.
Request flow: numbered arrows, read and write paths
Request flow is the path one request takes through the boxes, with each arrow numbered in order.
Number each arrow, then draw the read path and the write path separately. Below are both paths for ShopLite.
Example 2 · ShopLite read path and write path
READ PATH: open a product page(1) [Client] --GET /api/v1/products/42--> [Load balancer](2) [Load balancer] --> [ShopLite API x3](3) [ShopLite API] --get product:42--> [(Redis cache)](4) on a miss: [ShopLite API] --SELECT--> [(MySQL read replica)](5) [ShopLite API] --200 + JSON--> [Client]WRITE PATH: place an order(1) [Client] --POST /api/v1/orders--> [Load balancer] --> [ShopLite API x3](2) [ShopLite API] --INSERT order, items (one transaction)--> [(MySQL primary)](3) [ShopLite API] ..OrderPlaced..> [[order events]](4) [ShopLite API] --201 Created--> [Client](5) [[order events]] ..> [Email worker] --> [Email provider]Read path: 5 steps, cache first, replica on a miss Write path: 5 steps, primary DB in one transaction, email after the reply
What this code does
- The read path never touches the primary database; the write path never reads the cache.
- Step (3) of the write path uses
..>: the email is sent after the user already got 201.
Numbers let you say "in step 3 we check the cache" while everyone looks at the same place. The two paths usually touch different boxes: reads hit the cache and replicas, writes hit the primary database and the queue.
Two short flows are easier to follow than one diagram with every arrow at once.
The diagram-in-words notation used in this course
Diagram-in-words notation writes a diagram as plain text: [ ] is a program, [( )] a data store, [[ ]] a queue, --> a call that waits and ..> a hand-off that does not.
The notation works in a chat window, a shared doc or a whiteboard.
[Name] a running program [Name x3] three copies[(Name)] a data store [[Name]] a queueA --> B A calls B and waits A ..> B A hands off, does not waitA --label--> B label = request/action (3) step number in the flowA label inside the arrow says what is sent, and a number in front says the order. Because the rules are fixed, a program can print and check diagrams, as the Java examples in this lesson do.
Example 3 · Printing a diagram from code
import java.util.List;
enum Kind { SERVICE, STORE, QUEUE }
record Box(String name, Kind kind, int copies) { String show() { String label = copies > 1 ? name + " x" + copies : name; return switch (kind) { case SERVICE -> "[" + label + "]"; case STORE -> "[(" + label + ")]"; case QUEUE -> "[[" + label + "]]"; }; }}
record Arrow(Box from, Box to, String label, boolean async) { String show(int step) { String arrow; if (label.isEmpty()) { arrow = async ? "..>" : "-->"; } else { arrow = async ? ".." + label + "..>" : "--" + label + "-->"; } return "(" + step + ") " + from.show() + " " + arrow + " " + to.show(); }}
public class DiagramPrinterDemo { public static void main(String[] args) { Box client = new Box("Client", Kind.SERVICE, 1); Box api = new Box("Paste API", Kind.SERVICE, 2); Box db = new Box("MySQL paste metadata", Kind.STORE, 1); Box blobs = new Box("Object storage: paste text", Kind.STORE, 1); Box events = new Box("paste events", Kind.QUEUE, 1); Box indexer = new Box("Search indexer", Kind.SERVICE, 1);
List<Arrow> writePath = List.of( new Arrow(client, api, "POST /api/v1/pastes", false), new Arrow(api, blobs, "PUT text", false), new Arrow(api, db, "INSERT row", false), new Arrow(api, events, "PasteCreated", true), new Arrow(events, indexer, "", true));
System.out.println("WRITE PATH"); for (int i = 0; i < writePath.size(); i++) { System.out.println(writePath.get(i).show(i + 1)); } }}WRITE PATH (1) [Client] --POST /api/v1/pastes--> [Paste API x2] (2) [Paste API x2] --PUT text--> [(Object storage: paste text)] (3) [Paste API x2] --INSERT row--> [(MySQL paste metadata)] (4) [Paste API x2] ..PasteCreated..> [[paste events]] (5) [[paste events]] ..> [Search indexer]
What this code does
Box.showpicks the shape from the kind:[ ],[( )]or[[ ]], and addsx2for copies.Arrow.showwrites--label-->for a sync call and..label..>for an async hand-off, with the step number in front.- Writing a diagram as data like this makes the notation exact: there is only one way to draw each arrow.
Before and after: a cluttered vs a clear diagram
Cluttered diagram puts every tool and arrow on one page: arrows both ways, question marks, deployment tools and boxes that hide several services.
Compare a tangled diagram with its clear rewrite, then hunt for the flaws yourself.
Example 4 · A cluttered diagram and its clear version
User -> nginx -> spring -> redis, mysql, kafka, s3 -> workers -> email/smsspring <-> mysql <-> replica, redis <-> mysql, kafka -> spring?? -> analyticsauth, logging, monitoring, jwt, docker, k8s everywhere(order, payment, product, cart all inside "spring")(1) [Client] --GET /api/v1/products/42--> [Load balancer] --> [ShopLite API x3]
(2) [ShopLite API] --get product:42--> [(Redis: product cache)]
(3) on a miss: [ShopLite API] --SELECT--> [(MySQL read replica)]
Write: (1) [Client] --POST /api/v1/orders--> [ShopLite API] --INSERT--> [(MySQL primary: orders)]
(2) [ShopLite API] ..OrderPlaced..> [[order events]] ..> [Email worker]
Note: JWT auth, logging and monitoring apply to every API call.What this code does
- The cluttered version mixes tools, both-way arrows and question marks; nobody can say which step happens first.
- The clear version keeps only the request path, numbers the steps, splits read and write, and moves auth and logging to one note.
- Docker and Kubernetes disappear: they are how things are deployed, not steps a request passes through.
To fix a diagram, keep only what a request passes through, split the read and write paths, number the steps, label stores with what they hold, and move logging, monitoring and auth to a single note line.
Find the bug
Find the flaw in the diagram
Select the line that is wrong.
ShopLite read path. Which line is not a step a request passes through?
Round 1 of 3Labelling data stores and sync vs async arrows
Sync and async arrows differ in waiting: a sync arrow (-->) means the caller waits, so it adds to the user's wait; an async arrow (..>) means the caller hands off work, often to a queue, and moves on.
Label each data store with its technology and what it holds, and mark each arrow sync or async. The small Java linter below checks three of these rules.
Example 5 · Checking labels and arrows with a small linter
import java.util.ArrayList;import java.util.List;
public class DiagramLintDemo { static List<String> lint(List<String> lines) { List<String> problems = new ArrayList<>(); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); String where = "line " + (i + 1) + ": "; if (line.contains("[[") && line.contains("-->")) { problems.add(where + "a queue is joined with a sync arrow; use ..>"); } if (line.contains("[(DB)]") || line.contains("[(Cache)]")) { problems.add(where + "label the store with technology and data, e.g. [(MySQL orders)]"); } if (!line.startsWith("(")) { problems.add(where + "no step number"); } } return problems; }
public static void main(String[] args) { List<String> diagram = List.of( "(1) [Client] --POST /api/v1/orders--> [ShopLite API x3]", "(2) [ShopLite API] --INSERT--> [(DB)]", "(3) [ShopLite API] --OrderPlaced--> [[order events]]", "[[order events]] ..> [Email worker]");
List<String> problems = lint(diagram); problems.forEach(System.out::println); System.out.println(problems.size() + " problems found"); }}line 2: label the store with technology and data, e.g. [(MySQL orders)] line 3: a queue is joined with a sync arrow; use ..> line 4: no step number 3 problems found
What this code does
lintflags a vague store name[(DB)], a sync arrow into a queue, and a line with no step number.- Each rule is one
if; the same three checks are worth doing by eye before you show a diagram.
Write [(MySQL primary: orders)], not [(DB)], and add the one detail that matters, such as a TTL on a cache or "replica" on a read copy.
Getting sync and async right shows which steps are on the critical path. Now put the ShopLite write path in order.
Order of execution
Order the place-order write path
Put these events in the order they happen.
Next step
Check your understanding
12 quick questions