Topic 188 / Core
Configuration management and feature flags
Chapter 11.5 · CI/CD and Safe Change
What and why
An artifact built once (→ 186) must still behave differently per environment (a different database host, a different log level) without being rebuilt, and some changes need to ship in code while staying invisible to users until a separate decision turns them on. Configuration management externalizes environment-specific values from the artifact; feature flags externalize behavioral on/off decisions from the deploy itself. Builds on: → 165 (key and secrets management: rotation).
Diagram
Artifact (same bits, every environment)
+
Config (per environment: endpoints, limits, flags) ── injected at startup/runtime
│
▼
running instance ── a flag flipped at runtime changes behavior, no new deploy
How it works
- Configuration values that differ per environment — database endpoints, timeouts, feature toggles — are injected at deploy or runtime (environment variables, mounted files, a config service), never baked into the artifact, so the exact same image (→ 180) runs correctly in every environment.
- Secrets are a special case of configuration that must never sit in plain config files or source control — they're injected the same way but sourced from a secrets manager with rotation (→ 165), kept separate from non-sensitive config in both storage and access policy.
- A feature flag wraps a piece of behavior behind a runtime-checked condition, so the code for a new feature can be deployed — shipped "dark," inactive — independently of the decision to enable it for any group of users.
- This decouples deploy from release: deploying is a code event, controlled by engineering on its own schedule; releasing is a business/product decision, controlled by toggling the flag, with no new deploy required and an instant, flag-flip rollback if something's wrong.
- Flags also enable progressive exposure — enabled for 1% of users, then 10%, then 100% — a product-level complement to canary deployment's (→ 187) infrastructure-level traffic control; the two mechanisms often run together, the flag controlling who sees a feature, the canary controlling which instances serve it.
- Flags accumulate technical debt if not retired: a flag whose rollout finished and will never be toggled again should be removed from the code, or the codebase fills with permanent branches testing conditions nobody will ever flip back.
Practical example
(numbers illustrative). A new checkout flow deploys behind a flag, inactive for all users — the deploy itself changes nothing visible. Product then enables it for 1% of traffic, watches conversion and error metrics for a day, and ramps to 100% over the following week with no further deploys. When a problem surfaces at 10%, the flag flips back to 0% in seconds — compared to a deploy-gated rollback, which would need a new build, a new pipeline run, and the full deployment-strategy machinery (→ 187) just to undo a decision the flag made instantly reversible.
When to use it
- Use externalized configuration for every value that differs by environment — no exceptions, since hardcoding even one environment-specific value defeats "build once, deploy everywhere."
- Use feature flags for risky or user-facing changes that benefit from progressive exposure or instant rollback, and for decoupling a business release date from an engineering deploy date.
- Avoid flags for changes with no realistic need for independent release timing or rollback — every flag is a permanent branch in the code until removed, and that cost is real even when the risk being managed is small.
- Failure scenarios: a secret accidentally committed as plain configuration because the two weren't kept in clearly separate systems; a flag left in the codebase long after its rollout finished, with a later engineer unsure whether it's safe to remove because no one remembers what it does; a flag-check itself becoming a performance or availability dependency — a slow or down flag service blocking every request — when it was meant to reduce risk, not add a new one.
- Simpler alternative: for a small, low-risk application with infrequent releases, a plain environment-variable config with no flag system is enough — reach for feature flags once release risk, release cadence, or the need for progressive rollout actually requires decoupling deploy from release.
Practice
(pattern kind — implement minimal, spot the misuse; 20 min, shared lab: Redis as the flag store). Implement a boolean feature flag read from Redis at request time, gating one piece of behavior in a minimal handler; flip it live without redeploying and confirm behavior changes immediately; then find and fix the misuse where the flag check sits inside a tight loop re-reading Redis on every iteration instead of once per request. Done when the flag flips live with no redeploy and the misuse is both reproduced and fixed.
Shared lab setupKey takeaway
Externalized configuration lets one artifact run correctly everywhere; feature flags decouple the deploy decision from the release decision and buy instant rollback — but every flag is debt until it's removed. Done when you can: inject environment-specific config without touching the artifact, and design a flag's full lifecycle including its removal. Used next in → 189 (expand-and-contract uses the same dual-mode idea — old and new coexisting briefly — applied to schemas).
References
None — this topic makes no external claims.
Source directory