Area 07 · Deployment · Concept 15 of 20

Feature Flags

Turn a feature on or off for some users without redeploying.

11–20 · Production levelPhase 5 · Weeks 18–20≈ 45 min

The idea

A feature flag is a runtime switch your code checks: if flags.enabled("new_reranker", user): ... You can turn features on for internal users, a percentage of users or specific customers, and turn them off instantly if something breaks, all without a deploy.

For AI products, flags control prompt versions, model choices, new tools for agents and expensive features. They pair with A/B tests: the flag decides the variant, analytics compares outcomes.

Clean up flags after rollout; old flags become hidden complexity.

Why it matters

It separates deploying code from releasing features, which makes both safer.

Words to know

  • Kill switchA flag that disables a feature immediately.

Try it without code

List flag candidates

  1. List 3 upcoming changes in your app.
  2. For each, decide who should get it first.

Use it in code

A minimal percentage-rollout flag store backed by a JSON file or Redis.

python
import hashlib, json

FLAGS = json.loads('{"new_reranker": {"enabled": true, "percent": 20, "allow": ["staff@ourco.ie"]},'
                   ' "agent_email_tool": {"enabled": false}}')

def enabled(flag, user_id):
    f = FLAGS.get(flag, {})
    if not f.get("enabled"): return False
    if user_id in f.get("allow", []): return True
    bucket = int(hashlib.md5(f"{flag}:{user_id}".encode()).hexdigest(), 16) % 100
    return bucket < f.get("percent", 0)

print(enabled("new_reranker", "user-9"), enabled("agent_email_tool", "user-9"))
PRACTICE · TICK IT AFTER THIS

Put your reranker behind a flag and enable it for 20% of users.

Common mistakes

  • Flags that live forever.
  • Flag checks scattered with inconsistent user IDs.

Go deeper