08. Shipping: cheatsheets

2 lessons, one page each when printed.

System Design · 08. Shipping · 8 min · Beginner

Testing

Find the bug before your users do, without waiting all day.

In short

Our suite has 1,150 tests and runs in about 5.6 min: unit tests for the details, integration tests for the joins, a few E2E journeys, and contract tests between services.

Load tests find the limit; chaos tests check the system survives failures. Keep the pyramid the right way up, and keep every test fast and trustworthy.

Key ideas

  • The later a bug is found, the more it costs: a customer's money, a support call, a night fix. (step 1)
  • Test each thing at the lowest level that can catch it. Use the slow tests only for what the fast ones cannot see. (step 5)
  • Load tests answer "how many users can we take?", the capacity question from napkin math, with measurements instead of guesses. (step 7)

Good to know

  • Fast tests get run all the time, on every save. Slow tests get skipped. (step 2)
  • The contract is a shared promise. Breaking it fails the provider's build, before anyone deploys. (step 6)

Watch out

  • Give every test fresh data and clean up after it. Tests that share data fail in confusing ways. (step 3)
  • A flaky test teaches people to ignore red. Fix it or delete it. (step 4)
  • Begin in a test environment or with a tiny share of traffic. Chaos is an experiment, not a surprise. (step 8)
Unit: 1,000Integration: 100End-to-end: 20

Key numbers

Tests
1,150
Run time
5.6 min
Failure points to
a small area

Terms

Unit test
A test of one small function with no network or database; fast and exact.
Integration test
A test that runs real parts together, such as the app and a test database.
End-to-end test
A test that drives a real browser through the whole system like a user.
Flaky test
A test that sometimes fails when nothing is broken.
Test pyramid
Many fast unit tests, fewer integration tests, and very few end-to-end tests.
Contract test
A check that a service still keeps the API another service expects.
Load test
Sending many fake users to find how much traffic the system can take.
Chaos testing
Causing failures on purpose, carefully, to check the system survives them.

System Design · 08. Shipping · 10 min · Intermediate

CI/CD & Deployments

Ship small changes often, and make a bad one cheap to undo.

In short

CI builds and tests every change; the pipeline makes one artifact; delivery puts it in staging and is ready for production at a click, or with no click at all.

Release it with a rolling, blue-green or canary method, hide risky features behind flags, and keep a quick rollback. Small, frequent, reversible: a bad change then reaches 5% of users for a few minutes.

Key ideas

  • CI answers "does my change work together with everyone else's?" within minutes. (step 2)
  • CD makes releasing boring. A boring release is a safe release. (step 4)
  • Canary limits the blast radius: a bug hurts 5% of users for minutes, not 100% of users for an hour. (step 7)

Good to know

  • Each stage is a gate. The fastest, cheapest checks go first, so a mistake fails in seconds, not minutes. (step 3)
  • Great when you want a fast, simple undo. Cost and the all-at-once switch are the trade-off. (step 6)
  • Rollback speed by method: flag flip, canary or blue-green switch in seconds; rolling back a rolling deploy takes another full roll, here 8 minutes. (step 9)

Watch out

  • Rare releases make each release riskier, which makes people release even less. Break that circle with small, frequent, automatic ones. (step 1)
  • Change the database in two steps: first add the new column (both versions work), later remove the old one. Never rename it in one go. (step 5)
  • Flags pile up. Remove each one after the feature is fully released, or the code fills with old branches. (step 8)
Git repositoryCI runnerBuild artifactsProduction

Key numbers

Users seeing the change
5% to 100%
Downtime
0 min
Time to undo
seconds

Terms

Continuous integration (CI)
Merging small changes often, with an automatic build and tests on every push.
Build pipeline
An ordered list of automatic stages that turns a commit into a tested artifact.
Artifact
The one built package (for example a container image) that is deployed to every environment.
Continuous delivery
Every green build is ready to go to production with one click.
Continuous deployment
Every green build goes to production automatically, with no click.
Rolling deploy
Updating servers one at a time so the service never goes down.
Blue-green deployment
Two full environments; deploy to the idle one and switch traffic in one step.
Canary release
Sending the new version to a small share of traffic first and watching it.
Feature flag
A setting that turns new code on or off without a deploy.
Rollback
Going back to the previous version after a bad release.