Feature flags
A feature flag decides whether a capability or a named behaviour variant is active for a given evaluation context (client, principal, tier, roles or domain attributes) while an application runs. Use flags for release gates, operational kill switches, gradual tenant or user rollouts, and small algorithm variant choices.
What belongs in a feature flag (and what does not)
Section titled “What belongs in a feature flag (and what does not)”Feature flags are strictly BOOL (on/off) or closed ENUM (a small, code-declared set of
named variants). Free-form strings, numbers and arbitrary JSON are deliberately excluded so flags
never turn into an untyped configuration store.
| Need | Capability |
|---|---|
| On/off release gate, kill switch, gradual rollout, closed variant choice | Feature flags (BOOL or closed ENUM) |
| Deployment settings, URLs, credentials, API keys | Platform configuration and secrets or startup config |
| Per-client business data (SLAs, prefixes, retention periods, thresholds) | Per-client settings or domain tables |
| Who is allowed to perform an action | Permissions and roles |
A feature flag never bypasses authorisation. Check permissions first, and use flags to control whether a capability is rolled out or active for that tenant or context.
Code-first definitions, data-driven runtime state
Section titled “Code-first definitions, data-driven runtime state”Every flag is declared once in application code with its key (^[a-z][a-z0-9._-]{0,99}$), value
type (BOOL or ENUM), allowed values (for ENUM), required default, lifecycle (RELEASE,
EXPERIMENT, KILL_SWITCH or PERMANENT), governance (OPERATORS_ONLY or CLIENT_MANAGED),
whether it may be exposed to browser/mobile clients (exposeToClient), and an optional
reviewAfter date.
Applications sync their declarations to the platform at start-up or in CI (POST /api/applications/{app}/flags/sync). Sync updates metadata and flags removed from code become
orphaned (inCode = false) so operators can see stale flags and remove them once all instances
have rolled past them. Sync never overwrites live kill switches, targeting rules or client
overrides.
Deterministic in-memory evaluation
Section titled “Deterministic in-memory evaluation”Hot-path flag checks never make a network or database call. Each application holds an immutable
snapshot in memory, kept current by conditional HTTP fetches (ETag / 304 Not Modified), live
server-sent events (GET /api/applications/{app}/flags/watch), or PostgreSQL LISTEN/NOTIFY
(for the standalone database driver).
flowchart TD
start["Evaluate(ctx, flag, evalCtx)"] --> s0{"Flag in snapshot?"}
s0 -- No --> d0["Return code default (CODE_DEFAULT)"]
s0 -- Yes --> s1{"Master kill switch on?"}
s1 -- Yes --> d1["Return off value (KILLED)"]
s1 -- No --> s2{"Per-client override?"}
s2 -- "Sub-rule matches" --> d2a["Return sub-rule value (CLIENT_RULE)"]
s2 -- "Direct value set" --> d2b["Return override value (CLIENT_OVERRIDE)"]
s2 -- "None / lock-only" --> s3{"Global rule matches?"}
s3 -- Yes --> d3["Return rule value (GLOBAL_RULE)"]
s3 -- No --> s4{"Global default set?"}
s4 -- Yes --> d4["Return global default (GLOBAL_DEFAULT)"]
s4 -- No --> d5["Return code default (CODE_DEFAULT)"]
Evaluation follows a strict top-to-bottom precedence shared by Go, Java, TypeScript and PHP (pinned by shared conformance vectors):
- Master kill switch (
KILLED). Immediately returnsfalse(forBOOL) or the code default (forENUM). Nothing — no client override, no targeting rule — overrides a global kill switch. - Per-client override (
CLIENT_RULE,CLIENT_OVERRIDE). Matches either the client’s platform id (clt_...) or its client identifier (acme). Client sub-rules run first, then the client’s explicit override value. A lock-only override (locked: true,value: null) falls through to step 3. - Global targeting rules (
GLOBAL_RULE). Evaluated in order; the first matching rule wins. Every clause in a rule must match (logical AND) and any rollout percentage must match. - Global default (
GLOBAL_DEFAULT), then code default (CODE_DEFAULT).
Targeting clauses and rollouts
Section titled “Targeting clauses and rollouts”- Attributes:
client,principal,principalKind,tier,role(set-valued), andattr.<name>(custom string attributes such asattr.siteorattr.appVersion). - Missing attributes fail closed: if a referenced attribute is absent or empty, every operator
(including
neqandnot_in) returnsfalse. - Operators (fixed set of 7):
eq,neq,in,not_in,prefix,semver_gte,semver_lt(SemVer 2.0.0 §11 comparison). - Monotonic percentage rollouts:
SHA-256(salt + ":" + flagKey + ":" + bucketValue), taking the first 8 bytes as an unsigned big-endian 64-bit integer modulo 100. Raising a rollout from10%to25%preserves every bucket already in[0, 10).
If a snapshot ever contains an unexpected type or a retired ENUM variant, evaluation never throws
or crashes: it logs a throttled error, increments fw_flags_eval_errors_total, and returns the
code default with reason FALLBACK_ERROR.
Domain pinning
Section titled “Domain pinning”When a flag selects a workflow path or variant for a multi-step lifecycle (for example an order, shipment or delivery job), evaluate the flag once when the workflow starts and record the chosen value on the aggregate. Do not re-evaluate a mutable flag mid-flight where toggling it could leave an active record half-way between two behaviours.
Two-tier governance and locks
Section titled “Two-tier governance and locks”Every flag declares a governance level:
OPERATORS_ONLY(default): visible and mutable only to platform operators (ANCHORtier). Use this for kill switches, infrastructure migrations, and staged rollouts.CLIENT_MANAGED: client administrators can view and toggle their own client’s override (through the application’s own admin UI delegating withX-On-Behalf-Of). Platform operators can lock any client’s override (locked: true) to pin a tenant on or off during an incident or commercial entitlement, preventing client self-service changes until unlocked.
Browser and mobile exposure
Section titled “Browser and mobile exposure”Flags marked exposeToClient: true are evaluated server-side against the signed-in caller’s
EvalContext and returned as a flat key -> value map alongside the snapshot revision. Raw
targeting rules and other clients’ overrides never leave the server.
Resilience and cold start
Section titled “Resilience and cold start”- Stale on error: if a background refresh fails, the previous snapshot continues to be served and the informational health check reports degraded once staleness exceeds the configured threshold (default 5 minutes).
- Cold start: by default (
UseDefaultsAndRetry), start-up succeeds even when the platform or backing store is temporarily unreachable, serving code defaults while retrying in the background.