Rzemiosło · The Craft
What is The CraftLevelsGet startedChapters Search Download PLEN
Level 2 · Technical ~2 min read

In one sentence: You rehearse a risky release on a preprod built from prod first — a failure in rehearsal is a Tuesday, on prod it’s an incident.

This chapter in plain terms

This chapter is about one thing: you rehearse a risky change to the live site on a faithful copy first. A database Migration (database) — A controlled change to the database layout — adding a column, a table or moving data — step by step. Like a renovation to plan: rebuilding data in a set order so nothing “collapses”. more in the glossary → run for the first time in a real Maintenance window — A short, planned period when users see a “work in progress” page while the database or configuration changes behind it. It guarantees the app never runs, even briefly, on half-changed data. more in the glossary → is being tested on your customers.

Hence three environments: dev (your machine — you build and reproduce bugs), Preprod (staging) — A faithful copy of production with no real users, where you rehearse a deploy. A migration that fails on preprod is an ordinary Tuesday; in production it’s an incident. more in the glossary → (a server that is a clone of Environment (dev / prod) — Separate places where the app runs: “dev” for safe tests, “prod” for real users. Dev is a playground, prod is where real users are — the rules for each are completely different. more in the glossary → — you rehearse the migration and the Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary → itself) and prod (real users — touched only on “deploy” and only with steps rehearsed the same day). Preprod is built from production the same way every time, by a script, and PII (personal data) — Information that identifies a person: name, email, address, phone number. They need special protection (GDPR) — they mustn’t end up in logs or on test servers. more in the glossary → is anonymised before it leaves production. On preprod you rehearse the real Runbook — A written step-by-step guide for production operations, with numbered lessons from incidents. The memory of outages can’t live in someone’s head — the next deploy starts by reading the runbook. more in the glossary → — timing the window and checking everything afterwards — not a simplified version.

Preprod is a rehearsal stage, never a second prod: behind a password, invisible to search engines, and its database is never moved back to production. Environment-dependent addresses (e.g. SITE_URL, Canonical — A tag that tells search engines which address is “the real one” for a piece of content. It prevents duplicates (e.g. the same product under several addresses) that split your Google ranking. more in the glossary →, the Sitemap — A file listing every address of the site, helping search engines find them. New pages reach search engines faster, and language versions get linked together. more in the glossary →) are set through environment variables — otherwise preprod passes itself off as production in its links, or lands in Google.

Example of a trap only a real preprod catches: a password-protected site also blocks automatic renewal of its HTTPS certificate — the Let’s Encrypt check gets a 401. Without an exception in the config, preprod loses HTTPS after a few weeks and rehearsals stop resembling production.

Read more: dev / staging / prod environments · Let’s Encrypt — challenge types (HTTP-01).

18 — Rehearse the release: dev → preprod → prod

Commandments V and VI: a Migration (database) — A controlled change to the database layout — adding a column, a table or moving data — step by step. Like a renovation to plan: rebuilding data in a set order so nothing “collapses”. more in the glossary → or a Database swap — Replacing the whole production database with a new version, carrying over user accounts and data. The hardest operation in The Craft — it has its own runbook and needs explicit consent. more in the glossary → run for the first time in the Environment (dev / prod) — Separate places where the app runs: “dev” for safe tests, “prod” for real users. Dev is a playground, prod is where real users are — the rules for each are completely different. more in the glossary → Maintenance window — A short, planned period when users see a “work in progress” page while the database or configuration changes behind it. It guarantees the app never runs, even briefly, on half-changed data. more in the glossary → is tested on your users. Run the exact Runbook — A written step-by-step guide for production operations, with numbered lessons from incidents. The memory of outages can’t live in someone’s head — the next deploy starts by reading the runbook. more in the glossary → once on a faithful copy first.

Three environments, three jobs

EnvironmentJobData
dev (your machine)build, reproduce bugsseed data, or an anonymised refresh from a prod Backup — A copy of your data saved earlier, which you return to when something goes wrong. It’s the only way to undo a change to data — code comes back from git, data only from a backup. more in the glossary →
Preprod (staging) — A faithful copy of production with no real users, where you rehearse a deploy. A migration that fails on preprod is an ordinary Tuesday; in production it’s an incident. more in the glossary → (server clone of prod: same OS, web server, process manager, TLS)rehearse migrations and the Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary → itselfanonymised prod backup; basic-auth gated, noindex
prodserve userssacred — touched only on “deploy”, only with steps rehearsed on preprod the same day

Add preprod when the project reaches the third branching rung or the first risky migration (→ 05).

Rules

  1. Build preprod from prod the same way every time — scripted: clone with prod’s deploy key; refresh the database from a prod backup; anonymise PII (personal data) — Information that identifies a person: name, email, address, phone number. They need special protection (GDPR) — they mustn’t end up in logs or on test servers. more in the glossary → before it leaves prod (→ 09).
  2. Environment-specific values are env-overridable, never hard-coded: SITE_URL, Canonical — A tag that tells search engines which address is “the real one” for a piece of content. It prevents duplicates (e.g. the same product under several addresses) that split your Google ranking. more in the glossary →, Open Graph (OG) — Tags that decide how a link looks when pasted into Facebook, LinkedIn or a messenger (image, title, description). A good link card means more clicks — a bad one can show what you don’t want (e.g. a price). more in the glossary →, Sitemap — A file listing every address of the site, helping search engines find them. New pages reach search engines faster, and language versions get linked together. more in the glossary → point at preprod — otherwise preprod leaks prod URLs or gets indexed (→ 10).
  3. Rehearse the real runbook, not a simplified one: run the migration, time the window, Smoke test — A quick “does it even work” test right after a deploy — checks the most important paths (e.g. login). Catches disasters in 30 seconds before a user sees them. A cheap way to sleep well after a deploy. more in the glossary →, confirm it is forward-only and Idempotency — A property of an operation you can run many times with the same result — no duplication. Key for scripts and events: a re-run doesn’t break data. Like an “ON” switch. more in the glossary → (→ 04).
  4. Expect the gotchas only a real preprod surfaces: the ACME/Let’s Encrypt http-01 challenge must bypass basic-auth or renewal fails with 401; a private Repository (repo) — A store of the whole project’s code together with its full history of changes — who changed what and when. The repo is the project’s memory: code, documentation and change history in one place. more in the glossary → needs its SSH — An encrypted connection to a server for sending it commands and transferring files. An SSH key is access to production — guard it like your most important password. more in the glossary → remote before the first pull.
  5. Preprod is a rehearsal stage, never a second prod: no live users, a stale DB is fine, and its database is never swapped back into prod (→ 11).

Anti-patterns

  • 🚫 A migration whose first run is the prod maintenance window.
  • 🚫 Real, non-anonymised user data on preprod — a second copy of your PII liability on a weaker box.
  • 🚫 Preprod indexed or emitting prod URLs.
  • 🚫 Treating preprod’s data as a source of truth.
Chapter deep-dive 18Why these rules, examples and stories from projects — what the core deliberately leaves out.

The canonical doctrine is written in English.