Delivery & OperationsComplete guide

Feature Flags

Feature flags separate deployment from release by making an explicit, observable runtime decision about which behavior a caller receives.

Overview

The Microsoft.FeatureManagement libraries give .NET applications consistent APIs for Boolean flags, filters, targeting, time windows, variants, request-aware evaluation, gates, middleware, and evaluation telemetry. Azure App Configuration can store definitions centrally, select them by key and label, authenticate workloads with Microsoft Entra ID, and refresh flags without rebuilding an artifact. A flag is not just a Boolean configuration value: it is temporary operational control with an owner, audience, safe fallback, metrics, expiry condition, and removal change. Good designs evaluate once at stable boundaries, keep a user in a deterministic cohort, avoid using flags as authorization, exercise both branches, and fail safely when configuration is stale or unavailable. Progressive delivery succeeds only when technical and business signals govern expansion, kill switches are rehearsed, and completed flags and dead branches are deleted promptly.

What you will learn

  • Explain deployment, release, experimentation, migration, entitlement, and operational kill-switch use cases.
  • Use Microsoft.FeatureManagement abstractions and Azure App Configuration without coupling business logic to a provider.
  • Design stable targeting and percentage rollout that avoids users switching cohorts between requests.
  • Choose safe refresh, caching, fallback, and outage behavior.
  • Test enabled, disabled, targeted, variant, stale-configuration, and cleanup states.
  • Observe evaluation and outcome metrics without leaking sensitive targeting attributes.
  • Own and remove temporary flags before they become permanent architecture.

Prerequisites

  • ASP.NET Core routing, dependency injection, configuration, and request context.
  • Basic continuous delivery and rollback concepts.
  • Microsoft Entra managed identity and Azure RBAC for an Azure-backed deployment.
  • A .NET 10 SDK to run the dedicated checkout rollout sample.

When to use Feature Flags

Good fit

  • Use release flags for gradual exposure of already-deployed code.
  • Use operational flags as tested kill switches for optional risky behavior.
  • Use variants when named behavior or configuration differs by stable audience.
  • Use short-lived migration flags when old and new implementations must overlap safely.

Choose another approach when

  • Do not use a feature flag as the only authorization or entitlement control.
  • Do not flag every refactor or scatter the same decision through many layers.
  • Do not run an experiment without assignment and outcome telemetry.
  • Do not keep a temporary flag after the rollout decision is complete.

Key concepts

Deployment versus release

Code can reach production disabled, then be enabled gradually without building and deploying another artifact.

Filters and context

Time-window, targeting, percentage, and custom filters evaluate contextual rules instead of one global value.

Stable cohorts

Deterministic assignment based on a durable subject identifier keeps the same user in the same rollout group.

Variants

A flag can assign named configurations to audiences for experiments, migrations, or tier-specific behavior.

Refresh and consistency

Instances cache definitions and observe changes over time, so rollout propagation is bounded but not globally atomic.

Telemetry

Evaluation reason, allocation, version, technical health, and business outcomes make rollout decisions explainable.

Safe fallback

Every flag defines behavior for disabled, missing, stale, invalid, or unreachable configuration states.

Flag lifecycle

Every flag needs an owner, purpose, creation date, review date, completion condition, and cleanup change.

Architecture

A central configuration source supplies flag definitions, the feature manager evaluates them against request context, and application code selects the enabled behavior while telemetry records the decision.

Flag configuration
Feature manager
Application decision
Telemetry + cleanup

Conceptual architecture · Adapt to your system context

Implementation walkthrough

Build the critical path deliberately, then verify its observable behavior.

  1. 01

  2. 02

  3. 03

  4. 04

  5. 05

  6. 06

  7. 07

Code example

Azure App Configuration loads selected flags using managed identity, while the feature manager evaluates the release decision at one application boundary.

Program.cs
using Azure.Identity;
using Microsoft.FeatureManagement;

var endpoint = new Uri(builder.Configuration["AppConfig:Endpoint"]!);
builder.Configuration.AddAzureAppConfiguration(options =>
    options.Connect(endpoint, new DefaultAzureCredential())
        .UseFeatureFlags(flags => flags
            .Select("Checkout:*", "Production")
            .SetRefreshInterval(TimeSpan.FromSeconds(60))));

builder.Services.AddAzureAppConfiguration();
builder.Services.AddFeatureManagement().WithTargeting();

app.UseAzureAppConfiguration();
app.MapGet("/checkout", async (IVariantFeatureManager features) =>
    await features.IsEnabledAsync("Checkout:V2")
        ? Results.Ok(new { experience = "v2" })
        : Results.Ok(new { experience = "current" }));

Testing strategy

Prove deterministic assignment, both behaviors, provider integration, and failure fallback before changing live exposure.

  • Unit-test globally disabled, globally enabled, targeted, excluded, percentage, and variant outcomes with deterministic subjects.
  • Test both behavior branches independently rather than only testing the evaluator.
  • Verify one subject receives stable assignment across processes, restarts, and scale-out.
  • Exercise missing, malformed, stale, delayed, and unreachable configuration with the documented fallback.
  • Contract-test selected key prefixes and labels so production does not load the wrong environment.
  • Run progressive-delivery drills that prove alerts stop expansion and the kill switch restores the safe path.

Security considerations

Treat definition storage, targeting context, administrative changes, and every enabled action as separate security boundaries.

  • Treat flags as release controls, never as the sole authorization check for protected data or actions.
  • Use managed identity and the App Configuration Data Reader role; disable access keys when operationally possible.
  • Restrict selected keys, labels, network paths, administrative roles, and change permissions by environment.
  • Audit definition changes and protect high-impact kill switches with separation of duties and emergency access procedures.
  • Do not emit raw user identifiers, group membership, secrets, or sensitive business attributes in evaluation telemetry.
  • Validate custom-filter inputs and bound external calls; evaluation must not become an SSRF, injection, or availability path.

Performance and scalability

Keep evaluation local and predictable while controlling refresh traffic, propagation delay, and active flag complexity.

  • Evaluate at stable boundaries and reuse scoped decisions instead of repeatedly evaluating the same flag in a request.
  • Use provider caching and an intentional refresh interval; do not query a remote store on every decision.
  • Keep custom filters deterministic, cancellation-aware, bounded, and free of slow network dependencies.
  • Measure evaluation latency, refresh failures, cache age, provider requests, allocation skew, and downstream impact.
  • Expect propagation delay across instances and design rollouts that tolerate mixed behavior during the refresh window.
  • Limit active flags and targeting complexity so startup, refresh, cognition, and test matrices remain manageable.

Deployment and operations

Promote both code paths first, then change exposure through observable, reversible stages and remove temporary state afterward.

  • Provision separate stores or strong key/label boundaries per environment with infrastructure as code.
  • Grant workload identities read-only data-plane access and release operators only the permissions they require.
  • Deploy both branches before enabling, verify telemetry, start with staff or a small cohort, then expand by documented gates.
  • Keep rollout changes auditable and reversible independently from application deployment.
  • Coordinate flags that affect schemas, messages, or clients with compatibility windows and migration ordering.
  • After full rollout and soak, remove old code first where safe, remove the flag definition, and verify no references remain.

Common problems and fixes

A flag change is not visible

Likely cause: The key or label was not selected, the refresh interval has not elapsed, middleware is missing, or identity/network access failed.

Fix: Inspect selectors, label, endpoint, refresh registration, cache age, managed identity, RBAC, DNS, and provider diagnostics.

A user switches experiences

Likely cause: Assignment uses a transient identifier, random evaluation, inconsistent flag names, or different definitions across instances.

Fix: Use one durable subject ID and deterministic hash, then compare definition versions and selectors across the fleet.

The flag is enabled but access is denied

Likely cause: The release decision and authorization policy are separate controls.

Fix: Keep the authorization denial; verify the caller's permissions instead of weakening security because a flag is on.

Rollout metrics look worse but aggregate health is green

Likely cause: Metrics are not segmented by allocation, variant, or evaluation version.

Fix: Correlate evaluation telemetry with errors, latency, and business outcomes for each cohort before expanding.

Configuration outage breaks requests

Likely cause: Evaluation depends synchronously on the remote provider or has no tested stale/missing fallback.

Fix: Use cached definitions, bounded refresh, and an explicit fail-safe behavior; rehearse provider loss.

Nobody knows whether a flag can be removed

Likely cause: Ownership, completion criteria, references, and cleanup work were not recorded.

Fix: Assign an owner and expiry, search code and telemetry, remove dead behavior in a reviewed change, then delete the definition.

Best practices

  • Give every flag a clear owner, creation date, expected removal date, and documented behavior for configuration failure.
  • Evaluate flags at stable decision points and avoid scattering the same flag through many layers.
  • Use deterministic subjects for targeting and percentage filters so experiences remain stable.
  • Test enabled, disabled, targeted, excluded, variant, stale, and provider-outage paths.
  • Observe errors, latency, allocation, and business metrics while rollout changes.
  • Use managed identity, least privilege, narrow selectors, and separate environment boundaries.
  • Remove temporary flags and dead branches promptly after rollout or migration completes.

Production checklist

  • Flag type, purpose, owner, audience, safe default, creation date, review date, and removal condition are recorded.
  • Authorization and entitlement controls remain independent and tested.
  • Target identity and percentage assignment are deterministic and privacy-reviewed.
  • Key/label selectors, refresh interval, cache, outage fallback, and propagation expectations are documented.
  • Managed identity, least-privilege RBAC, network access, audit logs, and administrative controls are verified.
  • Both branches, exclusions, targeting, variants, stale configuration, and kill-switch behavior are tested.
  • Evaluation, technical health, and business outcome telemetry drive staged rollout gates.
  • The definition, dead branch, tests, dashboards, and documentation have an explicit cleanup task.

Common interview questions

How is a feature flag different from application configuration?

Both may use configuration infrastructure, but a feature flag represents a managed release decision with targeting, variants, telemetry, ownership, and a lifecycle rather than a general application setting.

What is a kill switch?

It is an operational flag designed to disable risky behavior quickly without redeploying, with a safe and well-tested fallback path.

Why must percentage rollout be deterministic?

Stable hashing keeps one subject in one cohort, making behavior consistent and telemetry attributable; random evaluation can switch experiences on every request.

What consistency should you expect after a flag change?

Instances normally refresh cached definitions independently, so the fleet can temporarily run mixed decisions. The design must tolerate propagation delay rather than assume an atomic global switch.

Can a feature flag replace authorization?

No. A flag controls release exposure; authorization decides whether an authenticated principal may access a resource or action and must be enforced independently.

What is the main long-term risk of feature flags?

Stale flags leave permanent branches and multiply the states developers must understand and test, so cleanup discipline is essential.

Dedicated GitHub sample

Clone, run, test, and modify the focused implementation created for this guide.

Verified sample

Feature Flags Checkout

A .NET 10 checkout API with a global kill switch, deterministic percentage rollout, targeted groups, ownership, review dates, and App Configuration Bicep.

.NET 10Feature FlagsAzure App ConfigurationBicep
dedicated-sampleprogressive-deliverytargetingkill-switch
Run
dotnet run --project src/FeatureFlagsCheckout
Test
dotnet test FeatureFlagsCheckout.slnx