Feature flags
Status: accepted 2026-12-01. Builds on core, config and code, database and redis, admin, and flowcatalyst.
1. What a feature flag is (and is not)
Section titled “1. What a feature flag is (and is not)”A feature flag controls whether a capability or named behaviour variant is active for a given evaluation context (tenant, principal, tier, roles, or domain attributes) while the application runs: kill switches, gradual client rollouts, pilot opt-ins, and small algorithm variant selections.
It is not:
- Deployment configuration or secrets (config and code, platform-config): URLs, pool sizes, API keys and credentials belong in startup
ConfigandSecretResolver. - Per-client business domain data (client-settings): SLA minutes, retention periods, timezones, site mappings and workflow definitions belong in
clientsettingsor domain aggregates. - Authorization (RBAC): a feature flag decides whether a capability is enabled for a tenant or context; it never bypasses permission checks (
{app}:{domain}:{resource}:{action}).
Domain pinning rule. When a flag governs a multi-step business workflow or offline aggregate, evaluate it once at workflow start and record the resolved choice on the aggregate so mid-flight toggles cannot split an active workflow.
2. Definitions are code; value kinds are strictly BOOL and closed ENUM
Section titled “2. Definitions are code; value kinds are strictly BOOL and closed ENUM”Every flag is declared once, in code, as a typed value and registered with the flags module at start-up. Duplicate keys fail start-up. There is no flag list in YAML.
Value kinds are strictly BOOL and closed ENUM. Free-form string, int, and arbitrary JSON flags are deliberately excluded.
| Part | Rule |
|---|---|
key |
^[a-z][a-z0-9._-]{0,99}$ (1 to 100 characters); unique within the application |
valueType |
BOOL or ENUM |
allowedValues |
empty for BOOL; non-empty, unique list of ^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$ for ENUM |
defaultValue |
required, never null; for ENUM must belong to allowedValues |
description |
optional, at most 500 characters |
lifecycle |
RELEASE (default), EXPERIMENT, KILL_SWITCH, or PERMANENT |
governance |
OPERATORS_ONLY (default) or CLIENT_MANAGED |
exposeToClient |
boolean (default false); whether the flag is included in EvaluateClientExposed |
reviewAfter |
optional ISO-8601 date (YYYY-MM-DD) signalling when a RELEASE or EXPERIMENT flag should be reviewed for removal |
3. Evaluation context
Section titled “3. Evaluation context”An EvalContext is built explicitly from Context (never from thread-locals or context.Value) with optional domain or device attributes:
| Field | Source | Required |
|---|---|---|
client |
Context.client (canonical id or identifier, or _platform) |
yes |
principal |
Context.principal |
no |
principalKind |
Context.principalKind (USER, SERVICE, FIELD_WORKER) |
no |
tier |
Context.tier (ANCHOR, PARTNER, CLIENT) |
no |
roles |
optional list of role names attached via WithRoles(...) |
no |
attrs |
optional map[string]string attached via WithAttr(key, value) |
no |
4. Deterministic evaluation semantics
Section titled “4. Deterministic evaluation semantics”Evaluation is pure and strictly in-memory against an immutable Snapshot held in an atomic reference. Hot-path reads never perform network or database I/O.
Given a declared flag def, its runtime FlagState from the current Snapshot (if present), and an EvalContext, evaluation proceeds strictly top-to-bottom:
- Absent from snapshot: return
def.defaultValuewith reasonCODE_DEFAULT. - Master kill switch (
state.killed == true): immediately return the off value (falseforBOOL;def.defaultValueforENUM) with reasonKILLED. Nothing overrides a global kill switch. - Per-client override (
state.clientOverrides): look upevalCtx.clientagainst both the override map key (clientId) and any aliasclientIdentifierrecorded on an override entry (case-exact O(1) index built when loading the snapshot).- If an override exists, evaluate
override.subRulesin order; the first matching rule returns its value with reasonCLIENT_RULEandruleId. - Else if
override.valueis present (non-null), returnoverride.valuewith reasonCLIENT_OVERRIDE. - Else (an override with only
locked: trueor non-matchingsubRulesand nullvalue), fall through to step 4.
- If an override exists, evaluate
- Global targeting rules (
state.rules): evaluate in order; the first matching rule returns its value with reasonGLOBAL_RULEandruleId. - Global default (
state.defaultValue): if non-null, return it with reasonGLOBAL_DEFAULT; otherwise returndef.defaultValuewith reasonCODE_DEFAULT.
4.1 Invalid or corrupt values on read
Section titled “4.1 Invalid or corrupt values on read”Invalid values are rejected on write (400 VALIDATION). On read, if a matched or default value in a snapshot is the wrong JSON type or an ENUM variant no longer in def.allowedValues, evaluation never throws or crashes: it logs a throttled ERROR, increments fw_flags_eval_errors_total{flag}, and returns def.defaultValue with reason FALLBACK_ERROR.
4.2 Clauses and operators
Section titled “4.2 Clauses and operators”A rule matches iff every clause in rule.clauses matches (logical AND; an empty clauses list matches everyone) and its optional rollout matches.
Attributes: "client", "principal", "principalKind", "tier", "role" (set-valued), and "attr.<name>". Any unknown attribute returns false.
Missing-attribute rule (fail-closed): If a single-valued attribute is absent or empty (""), or if "role" is empty, every operator returns false (including neq and not_in).
Operators (fixed set of 7):
| Operator | Single-valued attribute v (non-empty) |
Set-valued "role" (non-empty R) |
|---|---|---|
eq |
v equals any element of values |
any r in R equals any element of values |
neq |
v equals no element of values |
no r in R equals any element of values |
in |
v equals any element of values |
any r in R equals any element of values |
not_in |
v equals no element of values |
no r in R equals any element of values |
prefix |
v starts with any non-empty element of values |
any r in R starts with any non-empty element of values |
semver_gte |
parseSemver(v) >= parseSemver(values[0]) |
false |
semver_lt |
parseSemver(v) < parseSemver(values[0]) |
false |
SemVer parsing: Accepts optional leading v, then MAJOR.MINOR.PATCH, optional -prerelease (SemVer 2.0.0 §11 precedence), and optional +build metadata (ignored). Unparseable versions cause the clause to return false.
4.3 Deterministic percentage rollout
Section titled “4.3 Deterministic percentage rollout”A rule may carry rollout: { percent: 0..100, bucketBy?: string }. Default bucketBy is "client".
percent <= 0: returnsfalse.percent >= 100: returnstrue.1 <= percent <= 99:- Resolve
bucketValfrombucketBy("client","principal", or"attr.<name>"). If empty or unknown, returnfalse. - Compute
digest = SHA-256(UTF8(salt + ":" + flagKey + ":" + bucketVal)). - Interpret
digest[0..7]as an unsigned big-endian 64-bit integeru. - Rule matches iff
(u % 100) < percent.
- Resolve
4.4 Client-exposed evaluation (EvaluateClientExposed)
Section titled “4.4 Client-exposed evaluation (EvaluateClientExposed)”Returns a flat map key -> value (plus snapshot revision) for every declared flag with exposeToClient == true, evaluated against the caller’s EvalContext. Raw targeting rules and other clients’ overrides are never sent to browsers or mobile devices.
5. Drivers & resilience
Section titled “5. Drivers & resilience”The read contract is one small interface (SnapshotSource): Load(ctx, sinceRevision) and optional Watch(ctx, onChange). Four drivers are provided: memory, database, redis, and platform.
- Running failure (
staleIfError): when a refresh fails, the previousSnapshotcontinues to be served without error; aWARNis logged and the informational health check reports degraded once staleness exceedsstaleThreshold(default 5 minutes). - Cold start: default
OnBootError = UseDefaultsAndRetry— start-up does not fail when the backing store or platform is unreachable; code-declared defaults are served while retrying. Strict environments may opt intoFailBoot.
6. Storage (database driver, shared between Go and Java)
Section titled “6. Storage (database driver, shared between Go and Java)”Migration set id flags (V0001__create_feature_flags.sql, verified byte-for-byte in go/internal/conformance/shared-files.txt):
fw_feature_flagsfw_feature_flag_overridesfw_feature_flag_revisions(singleton revision counter)
Every write increments fw_feature_flag_revisions.revision and executes SELECT pg_notify('fw_flags_changed', revision::text) in the same transaction.
7. Headless admin section & governance
Section titled “7. Headless admin section & governance”Module: go/flags/flagsadmin (Go), framework-flags-admin (Java). Section id flags, path /admin/flags.
| Permission | Scope | Grants |
|---|---|---|
{app}:admin:flags:view |
Client or operator | List/get flags (non-operators see only CLIENT_MANAGED flags and their own client’s override) |
{app}:admin:flags:manage-client |
Client or operator | Set/delete own client’s override on CLIENT_MANAGED, unlocked flags (403 FLAG_LOCKED or 403 FLAG_OPERATORS_ONLY otherwise) |
{app}:admin:flags:manage |
Operators only (ANCHOR) |
Master kill switch, global default, global rules, any client override, lock/unlock, delete orphaned flag, simulator |
Start-up and platform sync refuse any clientManaged role granting {app}:admin:flags:manage directly or via wildcard.
8. Metrics, health and conformance
Section titled “8. Metrics, health and conformance”fw_flags_evaluations_total{flag,reason},fw_flags_eval_errors_total{flag},fw_flags_refresh_errors_total{driver},fw_flags_snapshot_age.- Informational health check
"flags". - Shared conformance vectors in
conformance/flags/evaluation.jsonare verified by Go, Java, TypeScript and PHP implementations.