ASP.NET Core

Keeping Feature Flags Consistent Across Multiple ASP.NET Core Instances

C# Corner Vivek Kumar
ASP.NET Core

Once an ASP.NET Core app scales past one instance, flags kept in appsettings.json start to disagree with each other. The article walks through a central source of truth with Azure App Configuration or Redis, what refresh really guarantees, and how to test it.

Key points

  • Microsoft.FeatureManagement.AspNetCore standardizes flag reads through AddFeatureManagement() and IFeatureManager, but does not sync instances.
  • An Azure App Configuration sentinel key plus a 30-second cache expiration bounds how stale a flag can get.
  • Refresh is periodic: a flag enabled at 10:00:00 reaches different instances at different seconds.
  • IDistributedCache with AddStackExchangeRedisCache shares one entry, but needs an update path and a Redis-down fallback.
  • Integration tests should poll the Version field with a timeout instead of sleeping for a fixed delay.
  • A feature flag is not authorization, and temporary flags need an owner and a cleanup date.

Why it matters

The real cost of feature flags appears after deploy and release are decoupled: the same flag now has to mean the same thing inside three containers. If a flag only gates a banner or a UI block, the eventual consistency described here is fine, and a short refresh interval over Azure App Configuration or Redis will do. If it guards money flow or a data migration, per-instance evaluation is the wrong shape — decide at the gateway, or tie behaviour to a versioned record you can audit. Before adopting, check that App Configuration access is wired through managed identity rather than a connection string in source.

Real-world use

  • A load-balanced e-commerce API rolling a new checkout experience out to a small slice of users
  • A marketing banner flag that can lag a few seconds, sitting next to a payments flag that cannot
  • Two test hosts started against one Redis instance to verify refresh behaviour
  • An instance that keeps serving the last known flag values while Redis is briefly unavailable

This summary was generated by the agent from the original post on C# Corner. The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message