Charlie Roffe

Principal Architect & Engineering Director · Cloud & AI

Madrid, Spain · LinkedIn · GitHub

ADR-016: Feature Flag Lifecycle & Two-Sided Rollouts

Context

A single container artifact serves both environments, and capabilities differ sharply in blast radius: a new demo tab is harmless, but security enforcement (App Check, Turnstile) can lock every visitor out if it goes live before the client is ready. The delivery model must allow shipping dark, config-time rollback without a code revert, server–client agreement on what is enabled, and zero standby budget — no hosted flag service.

Decision

Implement flags as environment variables behind a typed, end-to-end contract flowing one way from infrastructure to UI:
1. FEATURE_* variables are parsed once in features.ts into a typed FeatureFlags object; server middlewares consult isFeatureEnabled() before enforcing or serving.
2. GET /api/features publishes the flags verbatim; the React FeatureFlagsProvider fetches them at boot and gates demo tabs and security widgets on the same flags the server enforces.
3. Default polarity declared per flag (FLAG_DEFS): capability flags fail open (only the literal "false" disables — a missing variable can never hide content), enforcement flags fail safe (only the literal "true" enables — a missing variable can never lock visitors out).
4. Flips are reviewed Terraform changes pinned to Cloud Run revisions — rolling back a deployment atomically rolls back its flags.
5. Two-sided rollouts: client capability ships before server enforcement, dev first, prod after verification (runbooks in docs/feature-flags.md; applied across the abuse-protection rollout, ADR-019).
6. Retirement is part of the lifecycle: once rollback is no longer plausible, the variable and its dead branch are removed.

Amended 2026-10-16: there are now 19 flags (updated 2026-10-30 with demoRedTeam, jobMatch, adrExplainers; updated 2026-11-02 with demoArb, demoDefender; updated 2026-11-20 with onDemandTranslation). Besides App Check and Turnstile, demoCost, demoAdr, demoDefender, blog, lookingForWork, cvDownload and contactChat also fail safe (default off). Only six flags are Terraform variables (App Check, Turnstile, blog, lookingForWork, cvDownload, contactChat); rateLimiting, onDemandTranslation, and the FEATURE_DEMO_* flags have none and run at their code defaults.

Consequences

Benefits:
* A kill switch per capability, per environment, with no rebuild — the same image runs in every flag state (12-factor config).
* No code/config drift: because flags ride Cloud Run revisions, the running flag state is exactly what that revision was reviewed and deployed with.
* Both sides are testable; optimistic client defaults mirror server polarity, so the pre-fetch UI shows demos and assumes no enforcement — no layout flash.
* Security rollouts became routine: App Check and Turnstile each went capability → dev enforcement → prod enforcement as three reviewed, independently reversible steps.

Trade-offs:
* Flips take minutes (a deploy), not milliseconds — acceptable for rollout gates, not live experiments.
* Booleans only: no percentage rollouts or per-user targeting — deliberate, the site has no user accounts.
* Every flag doubles a test matrix somewhere; the retirement step keeps the set bounded.

Alternatives considered

1. Hosted flag services (LaunchDarkly, ConfigCat): Rejected — a subscription plus client SDK weight to manage thirteen booleans violates the zero-budget baseline and adds a third-party runtime dependency.
2. Firebase Remote Config / Firestore-backed flags: Rejected — real-time toggling is not required, and reading config at runtime puts a network dependency in the boot path; environment variables are atomic with revisions and free.
3. Build-time flags (Vite define): Rejected — flag state baked into artifacts means a rebuild per flip, separate bundles per state, and the server and client can skew.

Architecture Decision Records