Skip to content

Feature flags

The framework provides a strictly typed feature flags capability built on the same contract in Go and Java. Flags carry BOOL or closed ENUM values only, evaluate purely in memory against an immutable snapshot, and plug into four interchangeable drivers: memory, database, redis, and platform (documented on Platform flags).

The normative specification is in Feature flags specification, and the platform model is explained in Feature flags.

Driver Go package Java module Backing & invalidation
memory go/flags (Fake) framework-flags (FakeFlags) In-process mutable state for unit tests
database go/flags/flagsdb framework-flags-database Shared Postgres tables fw_feature_flags* + LISTEN/NOTIFY + 60 s poll fallback
redis go/flags/flagsredis framework-flags-redis Redis hash + revision counter + Pub/Sub + 60 s poll fallback
platform go/flowcatalyst (PlatformFlags) framework-flowcatalyst (PlatformFlags) Platform control plane: sync, ETag/304 snapshot, SSE watch + 30 s poll fallback
Admin (headless) go/flags/flagsadmin framework-flags-admin Operations under /api/admin/flags, permissions, nav item, direct Go/Java service

The database driver shares a single migration (V0001__create_feature_flags.sql, module id flags) verified byte-for-byte between Go and Java.

Declare each flag once as a package-level or class-level constant. Duplicate keys fail start-up.

package orders
import "github.com/flowcatalyst/framework/go/flags"
type RoutingMode string
const (
RoutingStandard RoutingMode = "standard"
RoutingFast RoutingMode = "fast"
)
var (
ExpressCheckout = flags.Bool("checkout.express", false).
Description("Enable express checkout").
Lifecycle(flags.LifecycleRelease).
Governance(flags.GovernanceClientManaged).
ExposeToClient()
Routing = flags.Enum("routing.mode", RoutingStandard, RoutingStandard, RoutingFast).
Description("Route calculation engine").
Lifecycle(flags.LifecycleExperiment).
Governance(flags.GovernanceOperatorsOnly)
)

Choose one driver at wiring time. For production services running against FlowCatalyst, use the platform driver. For standalone services without a platform control plane, use the database or redis driver.

// Standalone PostgreSQL driver:
dbDecl := database.Declare(app)
flagsDB := flagsdb.Declare(app)
flagsDecl := flags.Declare(app, ExpressCheckout, Routing)
// In build:
store := flagsdb.NewStore(db, flagsDB)
appFlags, err := flagsDecl.Build(ctx, b, store)

By default (OnBootError = UseDefaultsAndRetry), start-up does not fail if the backing store is temporarily unavailable; code-declared defaults are served while the background refresh loop retries. Strict deployments can opt into FailBoot.

Build an EvalContext explicitly from the framework’s Context and attach any domain or device attributes with WithAttr / WithRoles.

evalCtx := flags.FromContext(cx).WithAttr("site", cmd.SiteCode)
if appFlags.Enabled(cx, orders.ExpressCheckout) {
// ...
}
mode := flags.EvalEnum(appFlags, evalCtx, orders.Routing).Value
// Full trace (value, reason, ruleID) for logging or diagnostics:
res := appFlags.EvalBool(evalCtx, orders.ExpressCheckout)

To bootstrap a browser or mobile app, call EvaluateClientExposed(evalCtx) — it evaluates only flags declared with ExposeToClient() and returns a flat key -> value map plus the snapshot revision.

Mount the headless admin section (flagsadmin / FlagsAdminModule) to expose /api/admin/flags operations, permissions and direct in-process methods for server-rendered admin pages:

Permission Scope Grants
{app}:admin:flags:view Client or operator List/inspect flags (non-operators see only CLIENT_MANAGED flags and only their own client’s override)
{app}:admin:flags:manage-client Client or operator Set/clear 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) Kill switches, global defaults and rules, any client’s override, locks, delete orphaned flag, and simulator

{app}:admin:flags:manage is registered as an operators-only permission. Both start-up validation (Admin.OperatorsOnlyPermissions) and platform definition sync refuse any clientManaged role that grants {app}:admin:flags:manage directly or via wildcard.

// Mount against any flagsadmin.Writer (flagsdb.Store or flowcatalyst.PlatformFlags):
flagAdmin := flagsadmin.New(appFlags, store, flagsadmin.WithOperatorsOnly(false))
flagAdmin.Register(adminArea, api)

Use the in-memory fake (flags.NewFake / FakeFlags) in unit and integration tests without a database or platform server:

appFlags, fake := flags.NewFakeFlags(orders.ExpressCheckout.Definition(), orders.Routing.Definition())
fake.SetBoolForClient(orders.ExpressCheckout, fw.MustClientID("acme"), true)
fake.Kill("routing.mode", true)
  • fw_flags_evaluations_total{flag,reason} — counter per evaluation.
  • fw_flags_eval_errors_total{flag} — counter when a stored value fails type or enum validation.
  • fw_flags_refresh_errors_total{driver} — counter on failed snapshot reloads.
  • fw_flags_snapshot_age — gauge in seconds since the last successful snapshot load.
  • Health check "flags" — informational (UP when fresh, DEGRADED if never loaded or older than staleThreshold, default 5 minutes).