Feature flags separate deploy from release: code ships dark, then a
flag turns it on for a percentage, a cohort, or everyone. This skill
covers doing it safely: flag types, targeting, kill switches, and the
hygiene that prevents flag sprawl. Done well, flags are the fastest
rollback you have; done badly, they are hidden complexity.
Quick Workflow
- Choose flag types: release flags (temporary), experiment flags,
ops flags (kill switches, permanent), and permission flags.
- Design targeting: percentage rollout, cohorts, and allowlists,
evaluated consistently.
- Make every flag have an owner and a planned removal date, except
true ops flags.
- Test both states: flag on and flag off are both production code
paths.
- Monitor flag evaluations: who sees what, and error rates per
cohort.
- Use flags as kill switches for risky features: one click off.
- Clean up: remove the flag and the dead code path after full
rollout.
- Audit flag changes: who flipped what, when, and why.
1. Implementation basics
#!/usr/bin/env python3
"""Flag evaluation sketch: consistent bucketing per user."""
import hashlib
def flag_on(flag_key, user_id, rollout_pct):
h = hashlib.sha256(f"{flag_key}:{user_id}".encode()).hexdigest()
bucket = int(h[:8], 16) % 100
return bucket < rollout_pct
for uid in ["u1", "u2", "u3", "u4"]:
print(uid, "new_checkout:", flag_on("new_checkout", uid, 25))
# Consistent: same user always gets the same bucket for the flag
# Flag hygiene queries (against your flag system):
# - flags older than 90 days without a removal ticket: review
# - flags at 100% for 30 days: remove the flag, keep the code path
# - flags with no owner: assign or delete
echo "hygiene review monthly; stale flags are tech debt with blast radius"
2. Kill switch pattern
# Every risky feature gets an ops flag defaulting to safe:
# - payment flow v2: flag off = old flow
# - new search backend: flag off = old backend
# Incident runbook: "turn off flag X" before "roll back the deploy"
echo "kill switches need no deploy, no approval chain, just the flag UI"
Edge cases
- Flag evaluation in the client can be tampered with. Security
decisions stay server side; client flags are UX only.
- Percentage rollouts with sticky sessions: bucket by user ID, not
by request, or users flap between versions.
- Flag systems go down. Define the default (usually off/safe) and
cache evaluations briefly.
Escalation
- Flag sprawl out of control: run a cleanup sprint with the rule
"every temporary flag older than 90 days gets a removal PR".
- Incident needs instant rollback: flip the flag, then investigate;
the deploy rollback can follow.
Detection and defender view
Flag misuse looks like unauthorized flag flips, flags left at
partial rollout forever, and security sensitive behavior gated only
by a client side flag. Defenders (the engineering org) monitor flag
change audit logs and alert on flips outside change windows. The
durable practice is treating flags as production config: reviewed,
audited, and cleaned up.
Key references
- Feature flag best practice literature (Martin Fowler's bliki).
- Related skills: testing-strategies, devsecops-pipeline.
1---2name: feature-flags3description: Use when implementing or reviewing feature flags. Covers4 flag lifecycle, targeting rules, kill switches, and flag hygiene.5 Also use when a release needs gradual rollout or instant rollback6 without a redeploy.7version: 1.0.08domain: engineering9lifecycle: stable10last_verified: "2026-10-23"11requires: []12extends: []13relates: [devsecops-pipeline, testing-strategies, secure-coding]14tools:15 - name: Python16 version: "3.12"17metadata:18 source: https://skillmd.com/skills/mizazhaider-ceh/feature-flags19---2021Feature flags separate deploy from release: code ships dark, then a22flag turns it on for a percentage, a cohort, or everyone. This skill23covers doing it safely: flag types, targeting, kill switches, and the24hygiene that prevents flag sprawl. Done well, flags are the fastest25rollback you have; done badly, they are hidden complexity.2627## Quick Workflow28291. Choose flag types: release flags (temporary), experiment flags,30 ops flags (kill switches, permanent), and permission flags.312. Design targeting: percentage rollout, cohorts, and allowlists,32 evaluated consistently.333. Make every flag have an owner and a planned removal date, except34 true ops flags.354. Test both states: flag on and flag off are both production code36 paths.375. Monitor flag evaluations: who sees what, and error rates per38 cohort.396. Use flags as kill switches for risky features: one click off.407. Clean up: remove the flag and the dead code path after full41 rollout.428. Audit flag changes: who flipped what, when, and why.4344## 1. Implementation basics4546```python47#!/usr/bin/env python348"""Flag evaluation sketch: consistent bucketing per user."""49import hashlib5051def flag_on(flag_key, user_id, rollout_pct):52 h = hashlib.sha256(f"{flag_key}:{user_id}".encode()).hexdigest()53 bucket = int(h[:8], 16) % 10054 return bucket < rollout_pct5556for uid in ["u1", "u2", "u3", "u4"]:57 print(uid, "new_checkout:", flag_on("new_checkout", uid, 25))58# Consistent: same user always gets the same bucket for the flag59```6061```bash62# Flag hygiene queries (against your flag system):63# - flags older than 90 days without a removal ticket: review64# - flags at 100% for 30 days: remove the flag, keep the code path65# - flags with no owner: assign or delete66echo "hygiene review monthly; stale flags are tech debt with blast radius"67```6869## 2. Kill switch pattern7071```bash72# Every risky feature gets an ops flag defaulting to safe:73# - payment flow v2: flag off = old flow74# - new search backend: flag off = old backend75# Incident runbook: "turn off flag X" before "roll back the deploy"76echo "kill switches need no deploy, no approval chain, just the flag UI"77```7879## Edge cases8081- Flag evaluation in the client can be tampered with. Security82 decisions stay server side; client flags are UX only.83- Percentage rollouts with sticky sessions: bucket by user ID, not84 by request, or users flap between versions.85- Flag systems go down. Define the default (usually off/safe) and86 cache evaluations briefly.8788## Escalation8990- Flag sprawl out of control: run a cleanup sprint with the rule91 "every temporary flag older than 90 days gets a removal PR".92- Incident needs instant rollback: flip the flag, then investigate;93 the deploy rollback can follow.9495## Detection and defender view9697Flag misuse looks like unauthorized flag flips, flags left at98partial rollout forever, and security sensitive behavior gated only99by a client side flag. Defenders (the engineering org) monitor flag100change audit logs and alert on flips outside change windows. The101durable practice is treating flags as production config: reviewed,102audited, and cleaned up.103104## Key references105106- Feature flag best practice literature (Martin Fowler's bliki).107- Related skills: testing-strategies, devsecops-pipeline.