Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

OS 6.1 (10 of 10): Twelve factors, part two

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

45 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

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

WordWhat it meansExample
DatabaseAn organised store of data that programs can search and change.
Port bindingThe app listens on a port number and serves there.port 8000
ProcessOne running copy of a program.
Load balancerA tool that shares the users between your processes.
Scale outTo handle more users with more copies of a process.
DisposableEasy to start and easy to stop at any time.
Graceful shutdownFinish the work in progress, then stop.
ParityBeing alike.
StagingA copy of the live system used for a last check before release.
LogA record of events, one line each.
Event streamEvents 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

Code: python
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

FactorRule in plain wordsWhy
7 Port bindingThe app listens on a port and offers its own serviceIt does not need another program to run inside
8 ConcurrencyScale out: run more processes, not a bigger machineYou add copies on match day
9 DisposabilityStart fast. Shut down gracefullyA process can come and go without losing work
10 Dev and live alikeKeep development, staging and production as similar as you canA bug that appears on live also appears in testing
11 LogsWrite events as a stream of lines. Do not manage log files yourselfTools can collect, search and watch the lines
12 Admin tasksRun one-off jobs as one-off processes, from the same codeA 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?

FansFans one worker can serveWorkingWorkers needed
250100100 + 100 = 200, not enough. 100 + 100 + 100 = 300, enough3
3001003 workers serve exactly 3003
3011003 workers serve 300, one fan is left4

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

Code: python
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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Write 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.

Code: python
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

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.