Match day, 10,000 fans
Your football app is quiet all week. On match day, 10,000 fans open it at once.
A good app can add more copies of itself in seconds. When the busy time ends, it removes them. It keeps a clear record of what happened. It starts fast and stops without losing work.
These are the last six factors.
Key words
| Word | What it means | Example |
|---|---|---|
| Database | An organised store of data that programs can search and change. | |
| Port binding | The app listens on a port number and serves there. | port 8000 |
| Process | One running copy of a program. | |
| Load balancer | A tool that shares the users between your processes. | |
| Scale out | To handle more users with more copies of a process. | |
| Disposable | Easy to start and easy to stop at any time. | |
| Graceful shutdown | Finish the work in progress, then stop. | |
| Parity | Being alike. | |
| Staging | A copy of the live system used for a last check before release. | |
| Log | A record of events, one line each. | |
| Event stream | Events that arrive one after another, in time order. |
The cells students fill in are left blank in this preview.
Six more habits
In part one you met codebase, dependencies, config, backing services, build and release, and processes.
Now try the idea behind factor 11. A log is a record of events. The app writes one line per event and does not care where it goes.
Logs are a stream of lines
def log(level, message):
print(level, message) # just print. Something else collects the lines.
log("INFO", "app started")
log("INFO", "fan joined")
log("ERROR", "score service did not answer")
# Add a fourth line of your own.
Make a free account to save your work and track your progress.
Factors 7 to 12
| Factor | Rule in plain words | Why |
|---|---|---|
| 7 Port binding | The app listens on a port and offers its own service | It does not need another program to run inside |
| 8 Concurrency | Scale out: run more processes, not a bigger machine | You add copies on match day |
| 9 Disposability | Start fast. Shut down gracefully | A process can come and go without losing work |
| 10 Dev and live alike | Keep development, staging and production as similar as you can | A bug that appears on live also appears in testing |
| 11 Logs | Write events as a stream of lines. Do not manage log files yourself | Tools can collect, search and watch the lines |
| 12 Admin tasks | Run one-off jobs as one-off processes, from the same code | A database fix uses the same code and settings as the app |
The cells students fill in are left blank in this preview.
Worked example: how many workers?
| Fans | Fans one worker can serve | Working | Workers needed |
|---|---|---|---|
| 250 | 100 | 100 + 100 = 200, not enough. 100 + 100 + 100 = 300, enough | 3 |
| 300 | 100 | 3 workers serve exactly 300 | 3 |
| 301 | 100 | 3 workers serve 300, one fan is left | 4 |
The cells students fill in are left blank in this preview.
Scale out: add copies
flowchart LR
fans([Fans]) --> lb[Load balancer: shares the fans out]
lb --> p1[Process 1]
lb --> p2[Process 2]
lb --> p3[Process 3]
p1 --> db[(Database)]
p2 --> db
p3 --> db
Match the factor to its rule
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Factor 7 in code: listen on a port
from http.server import HTTPServer, BaseHTTPRequestHandler
import os
class Hello(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b"Scores: Reds 2, Blues 1")
port = int(os.environ.get("PORT", "8000")) # the port is a setting too
HTTPServer(("0.0.0.0", port), Hello).serve_forever()
# Run this on your own computer, then open http://localhost:8000 in a browser.
# The app is its own web server. It needs no other program.
Make a free account to save your work and track your progress.
Which factor is it?
Have a go
Which factor is it?
5 questionsWrite logs, workers and a shutdown
Three small tools from the last six factors. format_event makes one log line. workers_needed works out how many processes to run, and rounds up. stop_gracefully finishes every job before stopping. Press Run Tests.
def format_event(time, level, message):
# One log line per event, as text: time, level and message, joined by one space.
# Example: format_event("2026-10-17T09:00:00", "INFO", "started") gives
# 2026-10-17T09:00:00 INFO started
return None
def workers_needed(users, users_per_worker):
# Scale out: how many workers (copies of the process) are needed?
# Every user must be served, so round up. 250 users, 100 per worker: 3 workers.
# At least 1 worker, even with 0 users.
# Hint: start with 1 worker and add one more until workers * users_per_worker is at least users.
return None
def stop_gracefully(jobs, finish):
# Graceful shutdown: call finish(job) for every job in the list, in order.
# Give back how many jobs were finished.
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Exit quiz
Have a go