.NET › API Versioning

How can feature flags be used as an alternative or complement to formal API versioning for rolling out changes gradually?

Intermediate

Answer

Feature flags let you toggle new behavior on or off for specific clients, percentages of traffic, or environments without deploying a formally versioned endpoint, enabling gradual rollout, A/B testing, and instant rollback of a change -- useful for behavior changes that don't need a permanent parallel version, though for changes to the wire contract itself, formal versioning is usually still needed since flags control behavior, not necessarily backward-incompatible schema shape.
if (featureManager.IsEnabled("NewPricingCalculation", context: request.UserId)) {
    return CalculateWithNewLogic(order);
} else {
    return CalculateWithLegacyLogic(order);
}
// No new API version needed -- same endpoint, gradually shifting behavior
Real-world example A team rolls out a new tax calculation algorithm to 5% of API traffic via a feature flag, monitoring for discrepancies before gradually increasing to 100%, entirely without introducing a new API version.

Common follow-ups: When does a behavior change actually require a new API version versus just a feature flag?;How do you clean up feature flags after a rollout completes?