Post

Feature Flags — Architecture & Rollout Strategy

Introduction

Feature flags decouple deployment from release. They enable controlled rollout, rapid rollback, and experimentation. Advanced teams treat feature flags as a runtime system with strong governance, not just conditional statements in code.

Core Architecture

A production-grade flag system includes:

  • Flag service storing flag definitions and targeting rules.
  • SDKs that evaluate flags locally with cached configuration.
  • Audit logging for every flag change.
  • Emergency switches to disable risky features instantly.

Evaluation and Targeting

Flags should be evaluated quickly and deterministically. Use a consistent hashing strategy to split traffic.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import crypto from "node:crypto";

function isEnabled(flagKey, userId, rolloutPercentage) {
  const hash = crypto
    .createHash("sha256")
    .update(`${flagKey}:${userId}`)
    .digest("hex");

  const bucket = parseInt(hash.slice(0, 8), 16) % 100;
  return bucket < rolloutPercentage;
}

const enabled = isEnabled("new-checkout", "user-123", 10);
console.log(`new-checkout enabled: ${enabled}`);

Rollout Strategy

A safe rollout strategy typically looks like this:

  1. Deploy code with flag disabled by default.
  2. Enable for internal users or a small cohort.
  3. Gradually increase rollout percentage.
  4. Monitor telemetry and error budgets.
  5. Remove the flag once fully stable.

Governance and Cleanup

Long-lived flags are technical debt. Enforce lifecycle policies:

  • Every flag must have an owner and an expiry date.
  • Stale flags trigger alerts.
  • Flag removal is part of the normal release workflow.

Summary

Feature flags are a powerful safety mechanism when paired with strong governance and observability. Treat them as a product: design for low-latency evaluation, targeted rollout, and an enforced cleanup lifecycle.

This post is licensed under CC BY 4.0 by the author.