Feature Flag Management Best Practices
In trunk based development, unfinished features are integrated into the trunk while hidden behind feature flags (feature toggles). In other words, feature flags are the foundation for separating "integration" from "release," and if flag management does not work, trunk based development falls back to long-lived branches.
This article assumes a tech stack of infrastructure: Kubernetes, frontend: Angular, backend: .NET / Go, and summarizes the feature flag management best practices that support trunk based development. For the basic concepts of flags and the overall trunk based development workflow, see Trunk Based Development Best Practices.
Design Principles
Regardless of the tech stack, there are five design principles to follow.
- Evaluate in the app, manage centrally — Flag definitions and changes are made in a centralized flag service (the control plane), while evaluation is performed locally by each app's SDK. Making a remote API call per flag evaluation drags latency and availability problems into every request.
- Insert a vendor-neutral abstraction — Implement against a standard API such as OpenFeature (CNCF) so the provider (flagd, Unleash, a SaaS, etc.) can be swapped. SDKs exist for Angular, .NET, and Go.
- Fail-safe default values — When the flag service is unavailable, the app keeps working with default values. Release flags default to
false(hidden), and kill switches explicitly define the safe value for their purpose. - Manage flag definitions as code (GitOps) — Add and change flags through pull requests to a Git repository, keeping reviews and audit logs.
- Keep flags short-lived — Decide the lifespan per flag type, assign an owner and a deletion deadline, and detect overdue flags automatically.
Flag Types and Examples for This Stack
| Type | Lifespan | Examples for this stack |
|---|---|---|
| Release flag | Delete within 2 weeks after release | New checkout screen (Angular), new API implementation (.NET / Go) |
| Experiment flag | Delete right after the experiment | Search ranking algorithm change (Go) |
| Ops flag | Permanent | Pausing the recommendation API (Kubernetes operations), kill switch for expensive features |
| Permission flag | Permanent | Beta dashboard for a specific plan (Angular + .NET) |
The important distinction is: treat long-lived flags (ops and permission) carefully as a form of configuration management, and always delete short-lived flags (release and experiment).
Overall Architecture
Apps fetch a snapshot of flags at startup and then receive updates via streaming (SSE, etc.) or polling. The principle is: never call the flag service on every evaluation.
Flag Infrastructure on Kubernetes
Choosing a Flag Service
| Service | Characteristics |
|---|---|
| flagd (OpenFeature Operator) | Part of the CNCF OpenFeature ecosystem. A lightweight daemon that can be injected into app pods as a sidecar via CRDs. JSON-based flag definitions |
| Unleash | A popular OSS choice. Rich UI, and Unleash Edge scales evaluation in large environments. Has a frontend API |
| Flipt | OSS. Strong at GitOps management of flag definitions and client-side evaluation |
| SaaS (LaunchDarkly, etc.) | Low operational burden and feature-rich. Use a relay proxy or similar for availability |
Whichever you choose, implementing the app side through OpenFeature keeps the migration cost low.
Operational Notes on Kubernetes
- Separate the flag service per environment (Dev / Staging / Prod); never mix production flag state with development
- Set two or more replicas, a PodDisruptionBudget, and resource limits to keep the flag infrastructure itself available
- When using the OpenFeature Operator, manage flag definitions declaratively with FeatureFlag / FlagSource CRDs, and let apps evaluate through the sidecar flagd over localhost (no external dependency)
- Inject secrets (SDK keys, API tokens) from Kubernetes Secrets or an external secret manager
- Division of roles with canary/blue-green: Deployment strategies (Argo Rollouts, Flagger, etc.) control "what percentage of traffic sees which version," while feature flags control "which features are exposed to whom." Combine both to achieve "deployed but not released"
- Observability: turn flag evaluation events into metrics (e.g., with OpenTelemetry) so error rates and latency can be compared per flag. Alert when a kill switch is activated
Angular (Frontend)
Evaluate at Runtime (Do Not Bake Flags into the Build)
Writing flag values into Angular's environment.ts requires a rebuild per environment and breaks "Build Once, Promote Everywhere." Fetch flags at runtime when the app starts, then evaluate them.
- Initialize the provider in
APP_INITIALIZER(orprovideAppInitializer) at startup, set the user context (targetingKey), and only then render the first screen. Rendering before loading causes flicker - If initialization fails, continue rendering with default values (a flag infrastructure failure must not take down the whole app)
- Receive updates via streaming or polling and re-evaluate when they change
Wrap It in a Service with Types
Do not call the SDK directly from components; centralize access in a thin service and directive.
// feature-flag.service.ts (overview)
import { Injectable } from '@angular/core';
import { OpenFeature } from '@openfeature/web-sdk';
import type { Provider } from '@openfeature/web-sdk';
export const FLAGS = {
checkoutV2: 'release.checkout-v2',
betaDashboard: 'perm.beta-dashboard',
} as const;
@Injectable({ providedIn: 'root' })
export class FeatureFlagService {
private readonly client = OpenFeature.getClient('web');
// Inject an OpenFeature web provider such as flagd or Unleash
async initialize(provider: Provider, targetingKey: string): Promise<void> {
await OpenFeature.setProviderAndWait(provider);
OpenFeature.setContext({ targetingKey });
}
isEnabled(key: string): boolean {
return this.client.getBooleanValue(key, false);
}
}
- Use it from templates with a directive (or pipe) such as
*appFeatureFlag="FLAGS.checkoutV2" - Manage keys as constants in one place to avoid scattered string literals
Angular-Specific Notes
- SSR (Angular Universal): Evaluate with the per-request user context, and never put user-specific evaluation results into a shared cache
- Flicker prevention: While a flag is unresolved, render the default (usually hidden) and switch after it is resolved
- Security: Use frontend flags only for UI presentation, and always enforce authorization on the backend. Design so that tampering with a flag value cannot lead to unauthorized access
- Privacy: Pass only the minimum information needed for evaluation (such as a user ID) in the evaluation context; never include PII
.NET (Backend)
Using Microsoft.FeatureManagement
ASP.NET Core has a standard library that reads flags from appsettings.json, Azure App Configuration, or custom providers.
// Program.cs
builder.Services.AddFeatureManagement();
// Controller / handler
public class CheckoutController(IFeatureManager featureManager) : ControllerBase
{
[HttpGet("checkout")]
public async Task<IActionResult> Get()
{
if (await featureManager.IsEnabledAsync("release.checkout-v2"))
{
return Ok(new CheckoutV2Response());
}
return Ok(new CheckoutV1Response());
}
}
- For controller/action-level gating, use the
[FeatureGate("release.checkout-v2")]attribute for a declarative approach - Use
IFeatureManagerSnapshotso flag evaluation does not vary within a single request - Targeting (user attributes, percentages) can be configured from settings with the TargetingFilter
- In tests, mock
IFeatureManageror swap in a test provider to verify both the ON and OFF paths
Using OpenFeature
Register it with DI via OpenFeature.DependencyInjection and inject IFeatureClient. Because it aligns the API and providers with Go and Angular, teams with multi-language stacks can unify operations around it.
- Initialize the provider only once at startup
- Manage flag names in a single constants class
- Return the default value and continue when evaluation fails
Go (Backend)
Use the OpenFeature Go SDK and set the provider only once at startup.
// Initialize once at startup (flagdProvider is a provider such as flagd or Unleash)
openfeature.SetProvider(flagdProvider)
client := openfeature.NewClient("orders")
// Evaluate per request, passing the evaluation context
enabled, err := client.BooleanValue(ctx, "release.checkout-v2", false,
openfeature.NewEvaluationContext(userID, map[string]any{"plan": plan}))
if err != nil {
// On evaluation error, continue with the default value (false) and log it
}
- The client is a singleton: Never initialize the provider/client per request
- Pass the evaluation context: Target with a targetingKey (user ID / tenant ID) and attributes, propagated through context.Context
- Provider choice: flagd (sidecar/remote), Unleash, a SaaS, etc. Because it goes through OpenFeature, it can be swapped later
- Create a wrapper package to centralize flag name constants, default values, and error handling
Testing Strategy
- Unit tests: Test both the ON and OFF paths using an in-memory provider (such as the OpenFeature InMemoryProvider) or a mock
- Integration / E2E tests: Run key scenarios with flags both ON and OFF. Covering every combination of flags explodes, so focus on the important combinations
- CI: Ensure tests pass with the default flag values. Add a check that statically detects unremoved flags (e.g., flag definitions no longer referenced in code)
Lifecycle and Governance
Naming Convention
Standardize on <type>.<domain>.<feature>.
release.checkout-v2— release flagexp.search-ranking— experiment flagops.recommendation-killswitch— ops flagperm.beta-dashboard— permission flag
Lifecycle
- Create: Add the flag through a PR to the flag definition repository. Require an owner (CODEOWNERS) and a deletion deadline
- Roll out: OFF → internal users → canary (per user/tenant, percentage-based) → everyone. Check error rates, latency, and business metric guardrails at each step
- Kill switch: Ops flags are permanent. Clarify the activation procedure and permissions, and alert when activated
- Delete: Delete within 2 weeks after release. Delete not only the flag definition but also the code branches. Detect overdue flags in CI and alert
Auditing and Permissions
- Record the flag change history (who changed what and when)
- Require approval for production flag changes (enforced by flag service permissions)
- Managing flag definitions in Git integrates review and history into the development workflow
Anti-Patterns
| Anti-Pattern | What Goes Wrong | Countermeasure |
|---|---|---|
| Baking flags into the Angular build | Requires a rebuild per environment, breaking Build Once | Evaluate at runtime and fetch flags at startup |
| Calling the flag service synchronously per request | Increases latency and makes flag outages app outages | Local evaluation + caching + streaming updates |
| Using flags for environment configuration | The number of flags explodes and none can be deleted | Express environment differences with configuration/IaC; limit flags to feature exposure control |
| Using frontend flags for authorization | Tampering with a flag value can lead to unauthorized access | Always enforce authorization on the server side |
| Making flags depend on each other (nested flags) | State combinations explode and become untestable | Keep flags independent; rethink the design if dependencies are needed |
| Initializing the SDK/client per request (Go / .NET) | Causes performance degradation and connection leaks | Initialize once at startup and use it as a singleton |
| Leaving long-lived release flags around | They become technical debt and the code branches rot | Owners, deadlines, automated detection, and a deletion CI check |
Adoption Steps for This Stack
- Introduce OpenFeature across the stack — Start with a lightweight foundation such as flagd (OpenFeature Operator) on Kubernetes
- Prepare thin wrappers in each language — Angular's
FeatureFlagService, a .NET client wrapper, and a Go wrapper package. Centralize flag name constants and default values - Pilot with a single release flag — Combine it with Kubernetes canary releases to establish the rollout procedure
- Start Git management with owners and deadlines — Define the flag definition repository, CODEOWNERS, and deletion deadline rules
- Automate — Overdue detection, a deletion CI check, and a per-flag metrics dashboard
- Improve through retrospectives — Measure flag usage, incidents, and deletion lead time
Final Checklist
- Flags are evaluated at runtime, not at build time
- Flag evaluation is not an external dependency in the request path (local evaluation + caching)
- A fail-safe default value is defined for every flag
- The provider can be swapped thanks to an abstraction such as OpenFeature
- Flag definitions are managed in Git with an owner and a deletion deadline
- Frontend flags are not used for authorization (authorization is verified server-side)
- Tests exist for both the ON and OFF paths
- Detection and deletion of overdue flags is automated
- The division of roles between canary/blue-green and feature flags is clear
Conclusion
The core of feature flag management is: "evaluate in the app, manage centrally, define in Git, keep lifespans short." For a stack of Kubernetes, Angular, and .NET / Go, the most balanced choice is to abstract the whole stack with OpenFeature, run a lightweight flag foundation on Kubernetes, and unify types and default values through thin wrappers in each language. Managing flags correctly as the mechanism that separates integration from release is the key to scaling trunk based development.