Skip to content

Feature flags

Status: accepted 2026-12-01. Builds on core, config and code, database and redis, admin, and flowcatalyst.

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:

  1. Deployment configuration or secrets (config and code, platform-config): URLs, pool sizes, API keys and credentials belong in startup Config and SecretResolver.
  2. Per-client business domain data (client-settings): SLA minutes, retention periods, timezones, site mappings and workflow definitions belong in clientsettings or domain aggregates.
  3. 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

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

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:

  1. Absent from snapshot: return def.defaultValue with reason CODE_DEFAULT.
  2. Master kill switch (state.killed == true): immediately return the off value (false for BOOL; def.defaultValue for ENUM) with reason KILLED. Nothing overrides a global kill switch.
  3. Per-client override (state.clientOverrides): look up evalCtx.client against both the override map key (clientId) and any alias clientIdentifier recorded on an override entry (case-exact O(1) index built when loading the snapshot).
    • If an override exists, evaluate override.subRules in order; the first matching rule returns its value with reason CLIENT_RULE and ruleId.
    • Else if override.value is present (non-null), return override.value with reason CLIENT_OVERRIDE.
    • Else (an override with only locked: true or non-matching subRules and null value), fall through to step 4.
  4. Global targeting rules (state.rules): evaluate in order; the first matching rule returns its value with reason GLOBAL_RULE and ruleId.
  5. Global default (state.defaultValue): if non-null, return it with reason GLOBAL_DEFAULT; otherwise return def.defaultValue with reason CODE_DEFAULT.

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.

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.

A rule may carry rollout: { percent: 0..100, bucketBy?: string }. Default bucketBy is "client".

  • percent <= 0: returns false.
  • percent >= 100: returns true.
  • 1 <= percent <= 99:
    1. Resolve bucketVal from bucketBy ("client", "principal", or "attr.<name>"). If empty or unknown, return false.
    2. Compute digest = SHA-256(UTF8(salt + ":" + flagKey + ":" + bucketVal)).
    3. Interpret digest[0..7] as an unsigned big-endian 64-bit integer u.
    4. Rule matches iff (u % 100) < percent.

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.

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 previous Snapshot continues to be served without error; a WARN is logged and the informational health check reports degraded once staleness exceeds staleThreshold (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 into FailBoot.

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_flags
  • fw_feature_flag_overrides
  • fw_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.

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.

  • 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.json are verified by Go, Java, TypeScript and PHP implementations.