Lesson 9 of 9 · 25m
Retiring Flags and Preventing Flag Debt
Remove flags safely through inventory, dependency analysis, default hardening, staged cleanup, verification, and organizational incentives.
Flag debt is not the number of flags. It is the gap between the behavior your organization thinks it ships and the behavior the control plane can still conjure at runtime. A healthy system treats removal as engineering work with the same rigor as rollout: inventory, dependency analysis, hardening the default, staged deletion, and verification.
Start with an inventory that tells the truth
Useful cleanup inventory joins code references, control-plane configuration, telemetry, and ownership:
key age type refs evals/day owner
checkout.payment-orchestrator 41d migration 18 2.1m team-payments
search.v2-parser 9d release 7 900k team-search
legacy.invoice-pdf-fallback 2y ??? 31 12 unownedThe scary rows are not always the newest or most referenced. Low evaluations can mean dead code, rare emergency paths, or a control nobody dares touch. Investigate before deleting.
Harden the winning behavior first
Do not delete a flag while production still depends on runtime manipulation. First make the desired state the default in every environment:
checkout.payment-orchestrator:
default: true
rules: []Let that state bake. Verify that no traffic uses the losing path, then remove control-plane rules. Only after that should code cleanup begin. Otherwise deleting code and changing production behavior become the same irreversible act.
Remove the branch, not just the conditional
A lazy cleanup starts with this branch:
if flags.enabled("reports.query-builder", context):
return new_query_builder()
return old_query_builder()The lazy deletion replaces it with return new_query_builder() but leaves dead implementations, alternate routes, stale tests, unused SDK wiring, and translation strings. Follow the branch to its endpoints: feature handlers, legacy API versions, worker paths, client rendering, documentation, experiment events, entitlement checks, and seeded demo data.
Watch hidden dependencies
Flags often hide in places grep misses:
- database-backed configuration copied into tenants
- mobile clients pinned to old versions
- runbooks instructing operators to toggle behavior
- customer support macros referencing beta states
Search by key, variation names, event properties, route names, and product terminology. Then search again after cleanup for orphaned artifacts.
Make cleanup economically visible
Teams do not ignore cleanup because they are lazy. They ignore it because launch credit is visible and deletion is invisible. Track cleanup as launch work, show aging in service reviews, and celebrate deletions. A good dashboard metric is not raw flag count alone; it is expired temporary flags, unowned flags, and flags with zero evaluations but live code references.
Field notes
- Do not batch unrelated flag removals into one giant pull request; when behavior changes, you want a narrow suspect.
- Never delete a permanent operational control just because it looks old. Review its runbook instead.
- Zero evaluations can mean the SDK is broken, the key changed, or the service no longer deploys that path. Treat it as a mystery, not permission.
- The best flag cleanup is the one included in the original launch plan, staffed before the feature is declared done.
Was this lesson helpful?