Skip to content

Use feature flags from code

Applications declare their feature flags in code, sync the definitions to FlowCatalyst, and evaluate flags locally in memory from a cached snapshot. Feature flags explains the evaluation rules, precedence and governance model; this guide shows the code across the SDKs.

If you are building on the FlowCatalyst application framework in Go or Java, see Framework feature flags and Platform flags driver for module wiring and the headless admin section.

Declare each flag with a stable key (^[a-z][a-z0-9._-]{0,99}$), type (BOOL or ENUM), default value, lifecycle and governance. Syncing is idempotent: it creates new flags, updates metadata, marks removed flags as orphaned (inCode = false), and preserves live kill switches, rules and client overrides.

set := sync.ForApplication("orders").
AddFeatureFlag(sync.MakeBoolFlag("checkout.express", false).
WithDescription("Enable one-click express checkout").
WithLifecycle("RELEASE").
WithGovernance("CLIENT_MANAGED").
WithExposeToClient(true)).
AddFeatureFlag(sync.MakeEnumFlag("routing.engine", []string{"standard", "fast"}, "standard").
WithDescription("Route calculation engine").
WithLifecycle("EXPERIMENT").
WithGovernance("OPERATORS_ONLY"))
res := sync.NewSynchronizer(fcClient).Sync(ctx, set, sync.DefaultOptions())

Always pass an explicit evaluation context carrying the tenant (client) and any targeting attributes (principal, tier, roles, custom attrs). Evaluation is pure and runs strictly against the cached snapshot.

// Fetch conditional snapshot (uses If-None-Match / 304 Not Modified)
snap, changed, err := sdkflags.New(fcClient).FetchSnapshot(ctx, "orders", lastRevision)
// For framework services, evaluate through *flags.Flags with PlatformFlags:
evalCtx := flags.FromContext(cx).WithAttr("site", "west")
if appFlags.EvalBool(evalCtx, ExpressCheckout).Value {
// ...
}
engine := flags.EvalEnum(appFlags, evalCtx, RoutingEngine).Value

In Laravel applications using laravel/pennant, register FlowCatalystPennantDriver so standard Feature::for($scope)->active('checkout.express') and Feature::for($scope)->value('routing.engine') calls evaluate directly against the FlowCatalyst snapshot:

use FlowCatalyst\Flags\EvalContext;
use FlowCatalyst\Flags\FlowCatalystPennantDriver;
use Illuminate\Support\Facades\App;
use Laravel\Pennant\Feature;
Feature::extend('flowcatalyst', function ($app) use ($defs) {
$client = $app->make(\FlowCatalyst\Client\FlowCatalystClient::class)
->featureFlags('orders', $defs);
return new FlowCatalystPennantDriver(
client: $client,
scopeResolver: fn (mixed $scope): EvalContext => new EvalContext(
client: $scope?->tenantCode ?? '_platform',
principal: $scope?->principalId,
roles: $scope?->roles ?? [],
),
);
});

4. Expose selected flags to browsers or mobile apps

Section titled “4. Expose selected flags to browsers or mobile apps”

Only flags declared with exposeToClient = true are included in client-exposed evaluation. Never send raw rules or other tenants’ overrides to a browser or mobile client.

exposed := appFlags.EvaluateClientExposed(evalCtx)
// Returns flags.ExposedFlags{Revision: snap.Revision, Flags: map[string]any{...}}

5. Delegated client overrides (X-On-Behalf-Of)

Section titled “5. Delegated client overrides (X-On-Behalf-Of)”

Applications that provide a self-service settings screen for client administrators can set or clear a CLIENT_MANAGED override through the platform’s delegated client-override endpoint while passing X-On-Behalf-Of: <principalId> so the platform records the acting user in the audit log. The platform refuses changes to OPERATORS_ONLY flags (403 FLAG_OPERATORS_ONLY) and locked client overrides (403 FLAG_LOCKED).

See each SDK’s dedicated page for complete API signatures: