Architecture Decision Record
ADR-031: Config-Driven Feature Flags with Dual-Surface Enforcement
Status
Accepted (2026-06-27). Revised 2026-08-18 (a targeting-context accessor is now registered, so the
built-in Targeting and Percentage filters give consistent per-user bucketing across replicas; the
last Trade-offs entry is narrowed accordingly. See the Revision (2026-08-18) at the end). Revised
2026-08-31 (the targeting identifier is the JWT sub claim read through FindUserIdValue(), not a
user_id claim; the Revision section is corrected accordingly).
Revised 2026-09-11 (the flag-debt trade-off is closed on the framework side: [FeatureFlag] declares a
flag's lifetime, removal date and owner, FeatureFlagRegistry reports a host's own inventory, and two
fitness rules behind FeatureFlagLifecycleTestsBase fail the build for an undeclared flag or a
temporary one past its date; adoption is per repo, like every other fitness base. See the Revision
(2026-09-11) at the end.)
Revised 2026-10-01 (the disabled response is 404 but not anonymous: the edge writes its own
"Feature not available" ProblemDetails and the CQRS failure carries the Feature.Disabled code; the
Decision and Rationale describe the bodies as they are. See the Revision (2026-10-01) at the end.)
Revised 2026-10-06: the CQRS disabled failure no longer names the flag; its message is the generic
wording the edge handler uses, and clients branch on the Feature.Disabled code. See the Revision
(2026-10-06) at the end. Revised 2026-10-21: anchors refreshed after the DisabledFeatureHandler
statement moved down one line. Revised 2026-10-26: the last Trade-offs entry now states that AddAPI
wires the targeting context unconditionally and that only the Targeting filter is sticky per user
(the Percentage filter is random per evaluation, so the 2026-08-18 sentence above holds for Targeting
only), and the flag-debt entry records that all four repos adopt the lifecycle gate.
Revised 2026-11-07: the targeting context adds the group tenant:<tenantId> when the request has
resolved a tenant, so a Targeting audience can turn a flag on per tenant. See the Revision (2026-11-07)
at the end.
Revised 2026-11-08 (MMCA.Common v1.281.0): stored overrides can be layered over the configuration
(AddReloadableFeatureFlags), so a kill switch flips without a new revision; configuration stays the
default and the answer whenever the overrides cannot be loaded. See the Revision (2026-11-08) at the
end. Revised 2026-11-23: the command FeatureGate decorator sits directly inside ViewAs rather than
outermost, a stored override can define a flag configuration never mentions, and the override
snapshot key carries the owning service as well as the data source; anchors refreshed.
Context
The apps need to decouple release from deploy: ship code dark, flip a kill switch, or roll a feature
out to a percentage of users without a redeploy. A flag has to be enforceable at two different points
of the request path (the HTTP edge (an MVC action) and inside the CQRS pipeline (a command or query))
because a feature can be reachable from either. ADR-014 already places a FeatureGate decorator at the
outer end of the command/query pipeline (outermost for queries, directly inside ViewAs for
commands), but it only decides the decorator ordering; it does not
decide the provider, the controller-edge surface, the disabled-response convention, or the rollout
filters. This ADR records those.
Decision
Standardize on Microsoft.FeatureManagement, configured from the "FeatureManagement" configuration
section and registered once in AddAPI
(services.AddFeatureManagement() + services.AddSingleton<IDisabledFeaturesHandler, DisabledFeatureHandler>(), MMCA.Common.API/DependencyInjection.cs:108-110), with the built-in
Percentage / TimeWindow / Targeting filters available for progressive rollout. The same flag name
is enforced at two independent surfaces:
- HTTP edge:
[FeatureGate("X")](Microsoft.FeatureManagement.Mvc) on a controller or action. WhenXis off,DisabledFeatureHandlerreturns an RFC 9457 ProblemDetails404("Feature not available",MMCA.Common.API/FeatureManagement/DisabledFeatureHandler.cs:19-27). The body is built by hand, so it does not carry theApiControllerBase.HandleFailureshape (title "Operation failed" plus anerrorsextension,MMCA.Common.API/Controllers/ApiControllerBase.cs:49-77, title at:67,errorsat:72). - CQRS pipeline: a command/query implements
IFeatureGated(exposingFeatureName). TheFeatureGateQueryDecoratoris the outermost query decorator, and theFeatureGateCommandDecoratorsits directly insideViewAsCommandDecorator, outside every other command decorator (ADR-014;MMCA.Common.Application/DependencyInjection.cs:158-159,:167). Each checksIFeatureManager.IsEnabledAsync(FeatureName)and, when off, short-circuits withError.NotFoundError("Feature.Disabled", ...)(ErrorType.NotFound) before any authorization, logging, caching, validation, or transaction work. A command from a view-as caller is refused byViewAsbefore the flag is checked, so that caller never reaches the disabled-feature answer. - Disabled =
404(NotFound), never403. Both surfaces return not-found rather than advertising a forbidden capability. The bodies still say a feature is off: the edge title reads "Feature not available", and the CQRS failure carries codeFeature.Disabledwith the generic message "The requested feature is not currently available." (the flag name is kept out of it; clients branch on the code), the same wording as the edge'sDetail(MMCA.Common.Application/UseCases/Decorators/FeatureGateCommandDecorator.cs:61-63,FeatureGateQueryDecorator.cs:59-61). - Flag names are module constants (
CatalogFeatures/SalesFeaturesin Store,ConferenceFeatures/EngagementFeaturesin ADC) that match keys in each service's"FeatureManagement"config, so a flag flips at config + restart, not at deploy (in a host that callsAddReloadableFeatureFlags, a stored override flips it on the next evaluation with no restart; see the Revision (2026-11-08)). The framework itself uses[FeatureGate](e.g. the notification controllers), and the decorators ship with unit tests.
Rationale
- Release decoupled from deploy. A kill switch or a percentage rollout becomes a configuration change, not a code change: the central reason feature management exists.
- Two surfaces because the enforcement points see different request shapes. Gating both the edge and the handler with one flag name keeps controller and use case in agreement, so a disabled feature is unreachable from either entry instead of leaking through the one that was missed.
- The
404convention reuses the not-found status. The CQRS surface goes through the Result to ProblemDetails edge (ADR-013), whoseerrorsextension serializes each error'sCodeandMessage(MMCA.Common.API/Middleware/ErrorHttpMapping.cs:65-74); the MVC edge writes its own ProblemDetails. Both answer404rather than403, so neither reveals a guarded capability, but neither body is identical to an ordinary not-found: each states that a feature is unavailable.
Trade-offs
- The two enforcement points must agree. A flag gated on the controller but not the handler (or vice versa) is a half-protected feature; no fitness rule asserts both are wired, so coherence is a convention/audit concern.
- Flag debt. Every flag is a branch that must eventually be removed. The framework now ships the
expiry check it used to lack (
[FeatureFlag]plus two fitness rules; see the Revision (2026-09-11)), but the gate is adopted per repo: a repo that has not subclassedFeatureFlagLifecycleTestsBasestill carries its flag debt uncounted. All four repos (Common, ADC, Store, Helpdesk) currently subclass it. - Per-service configuration. The same flag name must be present in each service that enforces it. A
missing key resolves to disabled (
IsEnabledAsync's default): fail-safe for a kill switch, but it will silently hide a feature you meant to ship if the key is forgotten. In a host that callsAddReloadableFeatureFlags, a stored override also defines a flag configuration never mentions: the evaluation path answers from the override before the configured provider is consulted (MMCA.Common.Infrastructure/FeatureFlags/StoredOverrideFeatureDefinitionProvider.cs:43-50, override branch:45-49; the enumeration path yields it too,:65-69), so a missing configuration key means off only while no override exists for it. - Only the Targeting filter is sticky per user. Filters are evaluated locally in each process.
AddAPIregistersCurrentUserTargetingContextAccessorthroughWithTargetingunconditionally (MMCA.Common.API/DependencyInjection.cs:108-109), so in a host that goes throughAddAPIa Targeting-filter rollout gives a signed-in user the same answer across requests and replicas, keyed on the targeting id: thesub(or mappedNameIdentifier) claim, falling back toIdentity.Namewhen a principal carries neither (MMCA.Common.API/FeatureManagement/CurrentUserTargetingContextAccessor.cs:121). An anonymous caller gets no user id, and its only group is the resolved tenant's, if any (:101-108), so it matches no named user or role; the accessor documents a targeted feature as off for anonymous callers unless the audience opts everyone in or names their tenant (:37-39). When the request has resolved a tenant, every caller also carries the grouptenant:<tenantId>(see the Revision (2026-11-07)). The built-in Percentage filter never reads the targeting context: it activates on a random percentage at each evaluation, so a Percentage-filter flag can flip between requests for the same user. A rollout that must be sticky uses Targeting with aDefaultRolloutPercentage, not Percentage.
Revision (2026-08-18)
Progressive rollout is now usable, because the targeting context exists. The Decision above listed the Percentage / TimeWindow / Targeting filters as "available", and the last Trade-offs entry recorded the catch: without a targeting context wired, bucketing is evaluated per process, so a percentage rollout assigns a user differently on each replica and a user can see a feature appear and disappear between requests.
CurrentUserTargetingContextAccessor
(MMCA.Common/Source/Presentation/MMCA.Common.API/FeatureManagement/CurrentUserTargetingContextAccessor.cs:54-55)
implements ITargetingContextAccessor and is registered inside AddAPI as
services.AddFeatureManagement().WithTargeting<CurrentUserTargetingContextAccessor>(), preceded by
AddHttpContextAccessor() (MMCA.Common/Source/Presentation/MMCA.Common.API/DependencyInjection.cs:90-92,
rationale at :84-89). It takes IHttpContextAccessor rather than the scoped ICurrentUserService
precisely because WithTargeting registers the accessor as a singleton. UserId resolves to the JWT
sub claim through user.FindUserIdValue(), falling back to Identity.Name (:86), and Groups
accepts role claims under ClaimTypes.Role, "role" or "roles" (:76-82), so a rollout can target
a role as well as a user. An unauthenticated or absent principal yields an empty context rather than an
exception (:67-74), which keeps anonymous traffic evaluating to the flag's non-targeted result
instead of failing. FindUserIdValue
(MMCA.Common/Source/Core/MMCA.Common.Shared/Auth/ClaimsPrincipalExtensions.cs:26-28) reads the raw
sub claim (AuthClaimTypes.Subject,
MMCA.Common/Source/Core/MMCA.Common.Shared/Auth/AuthClaimTypes.cs:25) and falls back to the mapped
ClaimTypes.NameIdentifier the JWT bearer handler produces, so targeting buckets on exactly the
identifier CurrentUserService and the idempotency filter read.
No decorator changed. FeatureGateCommandDecorator still depends only on IFeatureManager and
still calls IsEnabledAsync(featureGated.FeatureName) with no targeting argument (:20, :51); the
targeting context is resolved inside the filter through the registered accessor. Both enforcement
surfaces therefore inherit consistent bucketing with no change at either call site, which is the
property that made this a registration-only change.
The Trade-offs entry above is narrowed, not removed: bucketing is now consistent across replicas
for any host that goes through AddAPI, but it is only as consistent as the sub claim is
stable, and a flag whose filter is configured without a targeting audience still behaves exactly as
before.
Related
ADR-014 (the decorator pipeline and the ordering that puts FeatureGate outermost for queries and
directly inside ViewAs for commands, with Authorization registered directly inside it so a disabled
feature does not leak which permission guards it), ADR-013 (the Result / Error and ProblemDetails edge the disabled responses
reuse), ADR-019 / ADR-020 / ADR-021 / ADR-026 (the other opt-in, audit-the-inventory capabilities),
ADR-020 (the role vocabulary the targeting accessor reads as Groups).
Revision (2026-09-11)
The expiry gap the Trade-offs recorded is closed. "The framework provides no expiry or staleness check" was true from this record's acceptance until now. What it cost was never the flag itself but the branch behind it: once a rollout finishes, the losing branch is unreachable code that no test, no coverage report and no reviewer is prompted to notice.
A flag declares its lifecycle on the constant. [FeatureFlag]
(MMCA.Common/Source/Core/MMCA.Common.Shared/FeatureFlags/FeatureFlagAttribute.cs:32) takes a
FeatureFlagLifetime (MMCA.Common/Source/Core/MMCA.Common.Shared/FeatureFlags/FeatureFlagLifetime.cs:9,
Permanent at :15, Temporary at :21) and carries an optional Owner
(FeatureFlagAttribute.cs:52) and a RemoveBy written as ISO yyyy-MM-dd (:46, the format constant
at :35, the parser at :60). RemoveBy is required on a temporary flag and forbidden on a permanent
one, which is what keeps a removal date meaningful rather than decorative.
The inventory is readable at runtime. FeatureFlagRegistry
(MMCA.Common/Source/Core/MMCA.Common.Shared/FeatureFlags/FeatureFlagRegistry.cs:35) describes the
public const string fields of every static *Features class in an assembly (:46, :64, the class
test at :77, the field selection at :91) as FeatureFlagDescriptor records (:17) carrying field
name, flag name, lifetime, removal date and owner, so an administration surface reporting a host's
flags does not have to re-derive the *Features convention for itself.
Two fitness rules make it a build gate. ArchitectureRules.FeatureFlagsDeclareLifetime
(MMCA.Common/Source/Hosting/MMCA.Common.Testing.Architecture/Rules/Governance/ArchitectureRules.FeatureFlags.cs:28)
fails for a constant with no attribute (:42), for a permanent flag that sets RemoveBy (:46), and
for a temporary flag whose date is missing or unparseable (:51).
TemporaryFeatureFlagsAreNotPastRemoveBy (:70) fails for any temporary flag whose date has passed
(:77), naming the flag, the date and the owner. The second rule is the dead-toggle detector: the red
build is what tells you the rollout finished and the branch it chose between can go. Both are exposed
as facts on FeatureFlagLifecycleTestsBase
(MMCA.Common/Source/Hosting/MMCA.Common.Testing.Architecture/Bases/Governance/FeatureFlagLifecycleTestsBase.cs:10,
the two facts at :20-:25, the architecture map at :12), whose Today is a protected virtual
property (:18) so a repo can pin the judgement date rather than let the build's clock decide when a
toggle goes red.
Adoption is per repo, and the framework annotates its own flags. Like every fitness base
(ADR-058), the gate exists only where a repo subclasses it,
so this closes the trade-off for an adopting repo and leaves it open for one that changes nothing; it
is additive, and a consumer that adopts none of it keeps building exactly as before. The framework's
own two flags are annotated Permanent
(MMCA.Common/Source/Core/MMCA.Common.Shared/Notifications/NotificationFeatures.cs:11,
MMCA.Common/Source/Core/MMCA.Common.Shared/Privacy/PrivacyFeatures.cs:11). The fix for a flag that
goes red is to delete the flag and the branch it no longer chooses between, not to push the date out.
Revision (2026-10-01)
The disabled response is not-found, but not anonymous. The Decision and Rationale said both surfaces
emit the HandleFailure not-found shape, so a disabled feature is indistinguishable from a nonexistent
one. The code does not do that. DisabledFeatureHandler writes its own ProblemDetails with title
"Feature not available" and no errors extension
(MMCA.Common/Source/Presentation/MMCA.Common.API/FeatureManagement/DisabledFeatureHandler.cs:18-26),
unlike HandleFailure's "Operation failed" body
(MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/ApiControllerBase.cs:50-58). The CQRS
surface does go through HandleFailure, and BuildErrorsExtension
(MMCA.Common/Source/Presentation/MMCA.Common.API/Middleware/ErrorHttpMapping.cs:61-69) serializes the
Feature.Disabled code and the message "Feature '{FeatureName}' is not currently available."
(MMCA.Common/Source/Core/MMCA.Common.Application/UseCases/Decorators/FeatureGateCommandDecorator.cs:57-59),
so that response names the flag. The decision itself (404, never 403, at both surfaces) is
unchanged; the Decision and Rationale bullets now describe the bodies as they are. The AddAPI
registration anchor in the Decision is refreshed to DependencyInjection.cs:105-107.
Revision (2026-10-06)
- The CQRS disabled failure no longer names the flag. The Revision (2026-10-01) quoted the message
"Feature '{FeatureName}' is not currently available." and said that response names the flag. Both
decorators now return
Error.NotFoundError("Feature.Disabled", "The requested feature is not currently available.")(MMCA.Common/Source/Core/MMCA.Common.Application/UseCases/Decorators/FeatureGateCommandDecorator.cs:60-62,FeatureGateQueryDecorator.cs:59-61), the same wording asDisabledFeatureHandler'sDetail(MMCA.Common/Source/Presentation/MMCA.Common.API/FeatureManagement/DisabledFeatureHandler.cs:22). The source comment (FeatureGateCommandDecorator.cs:56-58) records why: the message reaches the user verbatim, so the internal flag name stays out and clients branch on the code. The response is still not anonymous (the code and the edge title both say a feature is off); the Decision bullet now says so. - Current locations for facts recorded in the Revision (2026-08-18). The decorator's
IFeatureManagerparameter is atFeatureGateCommandDecorator.cs:22(class at:20) and theIsEnabledAsync(featureGated.FeatureName)call at:53.AddHttpContextAccessor()is atMMCA.Common/Source/Presentation/MMCA.Common.API/DependencyInjection.cs:104andAddFeatureManagement().WithTargeting<CurrentUserTargetingContextAccessor>()at:105-106, with the singleton rationale at:98-103.AuthClaimTypes.Subject("sub") is atMMCA.Common/Source/Core/MMCA.Common.Shared/Auth/AuthClaimTypes.cs:34. - Anchors in the live sections were re-verified against current source;
BuildErrorsExtensionis atErrorHttpMapping.cs:62-70.
Revision (2026-10-21)
Re-verified against current source. The decision is unchanged: both surfaces answer 404, the edge
writes its own "Feature not available" ProblemDetails, and both decorators return the generic
Feature.Disabled failure that does not name the flag. Only the edge handler's anchor moved.
- Anchors re-verified against current source: the
DisabledFeatureHandlerresult statement is atMMCA.Common/Source/Presentation/MMCA.Common.API/FeatureManagement/DisabledFeatureHandler.cs:19-27(Title at:22, Detail at:23); the decorators'Error.NotFoundError("Feature.Disabled", ...)is atMMCA.Common/Source/Core/MMCA.Common.Application/UseCases/Decorators/FeatureGateCommandDecorator.cs:60-62andFeatureGateQueryDecorator.cs:59-61; theAddAPIregistration atDependencyInjection.cs:105-107,HandleFailure's body atApiControllerBase.cs:50-58andBuildErrorsExtensionatErrorHttpMapping.cs:62-70are unchanged.
Revision (2026-10-26)
Re-verified against current source. The decision is unchanged: both surfaces answer 404, the edge
writes its own "Feature not available" ProblemDetails, and both decorators return the generic
Feature.Disabled failure. Two live Trade-offs entries moved to match source.
- The rollout trade-off no longer says "per-process out of the box". The Status recorded in
2026-08-18 that the last Trade-offs entry was narrowed, but only that Revision qualified it; the
entry itself still said the rollout is per-process out of the box.
AddAPIcallsAddFeatureManagement().WithTargeting<CurrentUserTargetingContextAccessor>()unconditionally (MMCA.Common/Source/Presentation/MMCA.Common.API/DependencyInjection.cs:105-106, preceded byAddHttpContextAccessor()at:104), so the entry now states the residual limits instead. The per-user stickiness belongs to the Targeting filter alone: the built-in Percentage filter never reads the targeting context and activates "based on a random percentage" on each evaluation (Microsoft.FeatureManagement4.8.0, pinned atMMCA.Common/Directory.Packages.props:32), so the Status sentence of 2026-08-18 ("the built-in Targeting and Percentage filters give consistent per-user bucketing") holds for Targeting only. The targeting id is thesubclaim falling back toIdentity.Name(MMCA.Common/Source/Presentation/MMCA.Common.API/FeatureManagement/CurrentUserTargetingContextAccessor.cs:86), and an anonymous caller gets an empty context (:67-74), which the accessor documents as leaving a targeted feature off unless the audience opts everyone in (:27-28). - The lifecycle gate is adopted in all four repos.
FeatureFlagLifecycleTestsBaseis subclassed inMMCA.Common/Tests/Architecture/MMCA.Common.Architecture.Tests/Governance/FeatureFlagLifecycleTests.cs:13,MMCA.ADC/Tests/Architecture/MMCA.ADC.Architecture.Tests/Governance/FeatureFlagLifecycleTests.cs:9,MMCA.Store/Tests/Architecture/MMCA.Store.Architecture.Tests/Governance/FeatureFlagLifecycleTests.cs:9andMMCA.Helpdesk/Tests/Architecture/MMCA.Helpdesk.Architecture.Tests/ArchitectureTests.cs:210. Adoption stays per repo; the flag-debt entry now records the current state. - Anchors re-verified against current source: the decorators'
IFeatureManagerparameter atFeatureGateCommandDecorator.cs:22andFeatureGateQueryDecorator.cs:22,IsEnabledAsyncat:53in both, andError.NotFoundErroratFeatureGateCommandDecorator.cs:60-62andFeatureGateQueryDecorator.cs:59-61;DisabledFeatureHandler.cs:19-27with Title at:22and Detail at:23(the:22Detail anchor in the Revision (2026-10-06) is superseded by this one);AuthClaimTypes.SubjectatAuthClaimTypes.cs:34;BuildErrorsExtensionatErrorHttpMapping.cs:62; theAddAPIregistration atDependencyInjection.cs:105-107. The stale anchors inside the Revisions (2026-08-18) and (2026-10-01) stay as written, as does the:22Detail anchor in the Revision (2026-10-06) superseded above; the rest of the Revision (2026-10-06) and the Revision (2026-10-21) carry current locations.
Revision (2026-11-07)
Tenant targeting. The two enforcement surfaces, the 404 answers and the lifecycle gate are unchanged;
the targeting context gains one group.
- A resolved tenant becomes a targeting group.
CurrentUserTargetingContextAccessor.GetContextAsyncreads the request's scopedITenantContextfromHttpContext.RequestServicesand, when it holds a non-blankTenantId, adds the grouptenant:<tenantId>(MMCA.Common/Source/Presentation/MMCA.Common.API/FeatureManagement/CurrentUserTargetingContextAccessor.cs:99,:128-132). It is appended after the role groups for a signed-in caller (:110-117) and is the only group of an anonymous one (:101-108), so a request in tenantacmematches an audience group namedtenant:acmewhether or not the caller is signed in. The name is built by the publicTenantGroup(tenantId)fromTenantGroupPrefix="tenant:"(:75,:83-87), so a test or an admin tool can produce the exact group string. - No host changes. The accessor is the one
AddAPIalready registers (MMCA.Common.API/DependencyInjection.cs:104-106). A host without tenancy never registers or resolves a tenant, so no group is added (CurrentUserTargetingContextAccessor.cs:126-127), and the group only matters to an audience that names it. The tenant is the one ADR-073's resolution put on the request. - The Trade-offs entry now names the tenant group and the current anchors (
:121for the targeting id,:101-108for the anonymous context,:37-39for the documented anonymous behavior). The accessor's own example targets a tenant withRolloutPercentage100 (:53-55).
Revision (2026-11-08): stored overrides over configuration
Context. A flag's value came from configuration alone, so flipping a kill switch meant a new
revision: the very deploy a kill switch exists to avoid. MMCA.Common v1.281.0
(MMCA.Common/CHANGELOG.md:19) adds an opt-in layer of stored overrides. The two enforcement surfaces,
the 404 answers, the targeting context and the lifecycle gate are unchanged.
Decision.
- Overrides are a definition provider layered over the configured one.
AddReloadableFeatureFlags(configuration, params Assembly[] flagAssemblies), called afterAddAPI(), decorates the registeredIFeatureDefinitionProviderand throws when none is registered yet (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/DependencyInjection.FeatureFlags.cs:47,:77-86).StoredOverrideFeatureDefinitionProvideranswers a flag with a stored override from that override and every other flag from the configured provider, unchanged (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/FeatureFlags/StoredOverrideFeatureDefinitionProvider.cs:43-70). The FeatureGate decorators and[FeatureGate]keep callingIFeatureManager, so an override takes effect on the next evaluation with no restart (:16-18). - An override is expressed with the built-in filters. On becomes
AlwaysOn, off becomes no filter, and a percentage or a targeted audience becomes the targeting filter's audience, so a percentage stays sticky per user (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/FeatureFlags/FeatureFlagDefinitions.cs:13-17,:33-46). - One snapshot, invalidated on write. The whole override table is one cache entry in the host's
ICacheService, keyed by the owning data source underfeatureflags:overrides:(MMCA.Common/Source/Core/MMCA.Common.Infrastructure/FeatureFlags/FeatureFlagOverrideSnapshot.cs:43-57), thePermissionGrantCacheshape. Every set or clear invalidates it by prefix (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/FeatureFlags/FeatureFlagAdministrationService.cs:80,:99,:111-119). With the two-level cache the prefix invalidation replaces one generation token on the shared Redis (ADR-077), so a flip reaches every replica within seconds; on a memory-only hostFeatureFlags:OverrideCacheSeconds(default 30, 1 to 3600) bounds how long another replica serves the old snapshot (FeatureFlagOverrideSnapshot.cs:16-23;MMCA.Common/Source/Core/MMCA.Common.Application/FeatureFlags/FeatureFlagOverrideSettings.cs:14-24). A failed invalidation after a committed write is logged and the write still succeeds (FeatureFlagAdministrationService.cs:19-23). - Configuration answers when the overrides cannot be loaded. A load failure is logged as a
Warning and every flag answers from configuration until the next load succeeds; cancellation is
never swallowed (
StoredOverrideFeatureDefinitionProvider.cs:75-95). The override layer is never more fragile than the configuration under it: a transient database error or an unapplied migration would otherwise fail every feature-gated command and query. - Only declared flags can be overridden. The catalog is
FeatureFlagRegistry.Describeover the assemblies the host passes (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/FeatureFlags/FeatureFlagCatalog.cs:17-20); any other name, including one configuration happens to carry, is refused withFeatureFlag.Undeclared(404) before anything is written (FeatureFlagAdministrationService.cs:15-17,:69-72,:88-91,:103-106). An override must name a flag some code reads, or it is a typo stored as data. - Stored in the owning service's database, mapped only where enabled.
FeatureFlagOverrideslives in the databaseFeatureFlags:DataSourceNamenames (FeatureFlagOverrideSettings.cs:26-31), and the call registers the model gate that maps it there and nowhere else (DependencyInjection.FeatureFlags.cs:36-40,:69-70;MMCA.Common/Source/Core/MMCA.Common.Infrastructure/Persistence/DbContexts/ApplicationDbContext.cs:470,:1009). Clearing an override soft-deletes the row, so the audit fields record who cleared it. - An administration surface behind
features:manage.FeatureFlagsControllerBase(abstract, no route) lists each declared flag with its lifetime, owner, configured value, override and effective value, sets an override with a requiredReason, and clears one (MMCA.Common/Source/Presentation/MMCA.Common.API/Controllers/Administration/FeatureFlagsControllerBase.cs:37-38,:49,:68,:93;AdministrationPermissions.ManageFeatures,MMCA.Common/Source/Core/MMCA.Common.Shared/Auth/Permissions/AdministrationPermissions.cs:33). The routelessFeatureFlagAdminpage shows one table across the flag sources given toAddFeatureFlagAdministrationUI(params string[] sources)(MMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:387), so a multi-service host shows every service's flags together.
Consequences.
- A host opts in per service: the call, one
FeatureFlagOverridesmigration on that service's database (DesignTimeDbContextOptions.EnableFeatureFlagOverrides), the controller subclass and a page route behindfeatures:manage(MMCA.Common/UPGRADING.md:72-88). A host that never calls it changes nothing. - MMCA.ADC adopts it on Conference and Engagement, with
features:managegranted to Organizer only and one Feature flags page over both sources (MMCA.ADC/Source/Modules/Conference/MMCA.ADC.Conference.UI/DependencyInjection.cs:58-60). - An override outlives its reason: it is not time-boxed, and the page shows each active override with
its
Reasonso a stale one is visible. - Rejected: Azure App Configuration (a paid service and a vendor dependency for a table the owning service can hold), and per-tenant override rows (targeting groups already cover tenants, see the Revision (2026-11-07)).
Revision (2026-11-23)
Re-verified against current source. The decision is unchanged: both surfaces answer 404, the edge
writes its own "Feature not available" ProblemDetails, both decorators return the generic
Feature.Disabled failure, and the override layer stays opt-in. Three facts moved and the live
anchors were re-pointed.
- FeatureGate is outermost for queries only. The command chain registers
ViewAsCommandDecoratorafterFeatureGateCommandDecorator, soViewAsis outermost and FeatureGate sits directly inside it (MMCA.Common/Source/Core/MMCA.Common.Application/DependencyInjection.cs:158-159; the decorator's own doc says so atMMCA.Common/Source/Core/MMCA.Common.Application/UseCases/Decorators/FeatureGateCommandDecorator.cs:14-16). The query chain still ends withFeatureGateQueryDecorator(DependencyInjection.cs:167). The Context, Decision and Related sections now say so, and the Decision notes the consequence: a view-as caller's command is refused byViewAsbefore the flag is read. - A missing configuration key is off only while no override exists. With
AddReloadableFeatureFlags,StoredOverrideFeatureDefinitionProvideranswers a flag from its stored override before consulting the configured provider (MMCA.Common/Source/Core/MMCA.Common.Infrastructure/FeatureFlags/StoredOverrideFeatureDefinitionProvider.cs:43-50, override branch:45-49) and also enumerates every stored override that configuration never mentions (:65-69). The per-service configuration Trade-offs entry now records it. - The override snapshot is keyed by the owning service and the data source. The Revision
(2026-11-08) says the entry is keyed by the owning data source under
featureflags:overrides:. The key isfeatureflags:overrides:<service>:<DataSourceName>:all, where the service is the host'sIHostEnvironment.ApplicationName, else the entry assembly name, else the literalhost(MMCA.Common/Source/Core/MMCA.Common.Infrastructure/FeatureFlags/FeatureFlagOverrideSnapshot.cs:53,:62,:66,:77-78; the resolver:85-94,hostfallback:93), because two services on one Redis that keep the defaultFeatureFlags:DataSourceNamewould otherwise share one snapshot (:27-33). A write still invalidates that one prefix (:70-71). The memory-only staleness remarks are at:16-25. - Anchors re-verified against current source:
Error.NotFoundError("Feature.Disabled", ...)atFeatureGateCommandDecorator.cs:61-63(class:21,IFeatureManager:23,IsEnabledAsync:54, the rationale comment:57-59) andFeatureGateQueryDecorator.cs:59-61(IFeatureManager:22,IsEnabledAsync:53); theAddAPIregistration atMMCA.Common/Source/Presentation/MMCA.Common.API/DependencyInjection.cs:107-110(AddHttpContextAccessor:107,WithTargeting:108-109,DisabledFeatureHandler:110, singleton rationale:101-106);HandleFailureatApiControllerBase.cs:49-77(title:67,errors:72);BuildErrorsExtensionatErrorHttpMapping.cs:65-74;Microsoft.FeatureManagementand.AspNetCore4.8.0 atMMCA.Common/Directory.Packages.props:99-100. For the Revision (2026-11-08): theFeatureFlagOverridesmodel gate is resolved atApplicationDbContext.cs:437, applied at:537and decided byResolveFeatureFlagOverrideGateat:1083;AddFeatureFlagAdministrationUI(params string[] sources)is atMMCA.Common/Source/Presentation/MMCA.Common.UI/DependencyInjection.cs:456; v1.281.0 is atMMCA.Common/CHANGELOG.md:695and its opt-in steps underMMCA.Common/UPGRADING.md:525(the reloadable-feature-flags block at:562, steps:565-574). The stale anchors inside the earlier Revisions stay as written.