Your first system in Proschi: a tiny greeting service. A user asks for a greeting, an API reads it from a database and answers. The design is small on purpose; this problem is about the language. Each test checks one idea, so you can solve it one step at a time and run the tests after each step.
Functional requirements
Say hello: the user sends GET /hello to a service, which reads the greeting from a database and answers 200 with it.
Use the use case name "Say hello" exactly: the traffic, requirements and tests in problem.proschi refer to it.
Scale
200 requests a second to Say hello.
Constraints
p99 of Say hello under 100 ms.
Say hello available 99.9% of the time.
Every component has a spare: two replicas or more.
What is given
problem.proschi declares the user and holds the traffic, the requirements and the tests; open Given below to read them. Your file imports it. Add the service and the database, connect them, and write the use case:
Add a node for the service (the starter has one) and one for the database.
Connect the user to the service, and the service to the database.
Write usecase "Say hello": the request, the database read, the response.
Run the tests, read what fails, and give each node a spare.
How your design is checked
You write the design as text in Proschi. Tests run in your browser: a simulation of the traffic above checks latency, availability, cost and what happens when a machine fails. How the simulation works.
A user asks for a greeting and gets one back; behind the scenes, a small API reads the text from a database and answers. One actor, one service, one store, one request.
Interview systems are bigger, but built from exactly these pieces. A URL shortener is this design with a cache in the middle; a news feed is this design with a queue and a lot of fan-out. Write the small version fluently and the big ones are about ideas, not syntax.
You do not write everything yourself. Your file starts with import "problem.proschi", which pulls in a read-only given file declaring the user (the actor who sends requests), the traffic, the requirements and the tests; open Given under the statement to read it. Your job is the part in between: the service, the database, how they connect, and what happens on a request.
Load is not the problem; availability is. A request needs the API and the database up at once, so multiply: 99.5% × 99.95% ≈ 99.45%, against a target of 99.9%. Over the roughly 720 hours of a month, 0.55% down is about four hours, against the 43 minutes that 99.9% allows.
With two replicas, a part is down only when both are: for the API 0.5% × 0.5% = 0.0025% of the time (99.9975% available), and the database pair is better still. The request comes out near 99.997%, comfortably above the target: the last step of this problem.
The id (weather) is how the rest of the file refers to the node: letters, digits and _. The name is what the diagram shows. The tech decides what the node is: [REST API] is a service, [MySQL] and [PostgreSQL] are databases, [Redis] is a cache.
Deep dive What else the tech and the line decide
The tech also sets the node's default numbers in the simulation: how many requests a second it takes, how long a call lasts, how often it is down and what it costs. An optional second string after the name is a description, shown when you hover the node.
A connection says that one node may call another: an arrow from the caller to the callee, with an optional label.
weather -> station : SQL
Connections are the lines an interviewer expects on the whiteboard. A use case step between two unconnected nodes still works, but the editor warns you: a request travelling along a wire nobody drew is usually a design mistake.
A use case is one thing a user can do, written as the requests it makes, in order. Each step is an arrow with a label:
usecase"Get forecast" { visitor -> weather : GET /forecast weather -> station : SELECT readings station --> weather : rows weather --> visitor : 200 forecast}
a -> b : … is a request from a to b, and a waits for the answer.
b --> a : … is the response to the latest request from a to b. A status at the start of the label, like 200 or 404, is the HTTP status.
Order matters: the weather API answers the visitor after reading the station store, because it needs those readings. The simulation measures latency along these steps, and the tests read them to check what calls what, in which order. Press play under the diagram to watch a use case run.
The traffic block, in the given file, says how often each use case happens:
traffic {"Get forecast"500 rps}
rps is requests per second; rpm and rpd work too. The simulation sends that load through the use case with that exact name, and each node's load comes from the steps that reach it. A use case named anything else gets no traffic, and the requirements and tests that name it cannot find it. Copy names from the given file rather than retyping them.
p99 < 200ms means 99 requests out of 100 finish within 200 ms. availability >= 99.9% compares the use case's computed availability (every node it touches, as in the arithmetic above) with the target.
Tests check how the design works rather than how fast it is. Each test block holds assertions, and every one must hold:
test"Forecasts come from the store" {"Get forecast"callsany database"Get forecast"responds200}
any database is a selector matching every node whose tech is a database, MySQL or PostgreSQL alike. Each test shows what it measured and, when it fails, a hint: reading a failing test is the fastest way to learn what it wants.
Every machine fails sometimes (a dead disk, a bad deploy, a replaced host). A node with one replica is a single point of failure: when it is down, every request that needs it fails. Write x2 at the end of a node's line to run two replicas:
weather "Weather API"[REST API] x2
Two service replicas share the name and the load, and one answers when the other is down; two database replicas are a primary and a standby that takes over. Replicas cost money too (two API replicas cost twice one), which is why bigger problems have a budget: add replicas where they buy something, not everywhere by habit.
The starter already has one node, the API. Add the database next to it: an id, a name and a database tech. Run the tests: most still fail, but the editor has no complaints and the diagram shows two boxes and the user.
Write usecase "Say hello" with four steps: the user's request to the API, the API's request to the database, the database's answer, and the API's answer to the user with a 200. Check the name against the traffic block. Now A service answers the user, Say hello answers with 200, The greeting is read from a database and the p99 requirement pass.
Two checks are still red: the availability requirement and Every component has a spare. The availability one shows the computed number, well under 99.9%. Add x2 to both nodes and everything passes. Then compare with the reference solution: its decision block records why the design is the way it is, a habit worth keeping in every problem.
One replica of everything (wrong/one-of-everything). Right in every other way, and the first thing almost everyone writes. Each node is a single point of failure, and the request's availability is the product of both nodes': about 99.45%. It fails the availability requirement and Every component has a spare.
A request without its response (wrong/no-response). The use case sends GET /hello, reads the database and stops. Nothing answers the user, so there is no status to check and no end to the request. It fails Say hello answers with 200. Every -> from the user needs a matching --> back.
No database (wrong/no-database). The API answers from memory: simple, but the greeting is lost on every restart, two replicas would each hold their own copy, and changing the greeting means a deploy. It fails The greeting is read from a database.
A use case name that does not match (wrong/use-case-name-mismatch). The flow is perfect but the use case is called "Hello". The traffic, requirements and tests all name "Say hello", so none finds it: the flow tests fail, and the requirements have no traffic to measure. The clue is the warnings under the tests about names in problem.proschi that match no use case.
Nobody asks for a greeting service, but interviewers watch for the habits it trains:
Start with the request path. Draw the client, the first service and the store, and walk one request through them before adding anything else. A use case is exactly that walk.
Say where the data lives. "The API reads it from PostgreSQL" is a design; "the API has it" is not.
Name the single points of failure before you are asked, and say what a second replica buys and costs.
Do the availability arithmetic out loud: parts in a row multiply, replicas in parallel multiply their downtime.