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.
Modules and drivers
Section titled “Modules and drivers”| 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.
1. Declare flags in code
Section titled “1. Declare flags in code”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))public final class OrderFlags { public enum RoutingMode { STANDARD("standard"), FAST("fast"); // value() accessor }
public static final BoolFlag EXPRESS_CHECKOUT = BoolFlag.of("checkout.express", false) .description("Enable express checkout") .lifecycle(FlagLifecycle.RELEASE) .governance(FlagGovernance.CLIENT_MANAGED) .exposeToClient(true);
public static final EnumFlag<RoutingMode> ROUTING = EnumFlag.ofEnum("routing.mode", RoutingMode.class, RoutingMode.STANDARD, RoutingMode::value) .description("Route calculation engine") .lifecycle(FlagLifecycle.EXPERIMENT) .governance(FlagGovernance.OPERATORS_ONLY);}2. Wire the module and a driver
Section titled “2. Wire the module and a driver”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)App.builder() .module(new DatabaseModule()) .module(new DatabaseFlagsModule()) .module(FlagsModule.builder() .flag(OrderFlags.EXPRESS_CHECKOUT) .flag(OrderFlags.ROUTING) .build());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.
3. Evaluate from Context
Section titled “3. Evaluate from Context”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)EvalContext evalCtx = EvalContext.from(ctx).withAttr("site", cmd.siteCode());
if (appFlags.bool(evalCtx, OrderFlags.EXPRESS_CHECKOUT)) { // ...}OrderFlags.RoutingMode mode = appFlags.enumValue(evalCtx, OrderFlags.ROUTING);EvalResult<Boolean> traced = appFlags.evalBool(evalCtx, OrderFlags.EXPRESS_CHECKOUT);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.
4. Headless admin section and governance
Section titled “4. Headless admin section and governance”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)App.builder() .module(new AdminModule()) .module(FlagsAdminModule.builder().build());5. Testing with the in-memory fake
Section titled “5. Testing with the in-memory fake”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)FakeFlags fake = FakeFlags.of(OrderFlags.EXPRESS_CHECKOUT, OrderFlags.ROUTING);fake.setClientOverride("checkout.express", "acme", true);fake.kill("routing.mode");
Flags appFlags = fake.flags();Metrics and health
Section titled “Metrics and health”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 (UPwhen fresh,DEGRADEDif never loaded or older thanstaleThreshold, default 5 minutes).