Video in progress

What is a feature flag, and how does it separate deploy from release?

A feature flag lets you keep a new feature in the code and turn it on and off through configuration. The code is deployed to prod ahead of time, the feature is enabled for the right users when it's ready, and if there's a problem it's turned off without a redeploy.

📖 Answer

@Service
class CheckoutService {
    private final FeatureFlags flags;
    // ...
    Receipt checkout(Cart cart, User user) {
        if (flags.isEnabled("new-pricing", user)) {
            return newPricing.checkout(cart);
        }
        return legacyPricing.checkout(cart);
    }
}

What this gives you:

  • the new pricing is deployed on Friday, and on Monday it's enabled first for employees, then for 5% of customers;
  • if something goes wrong, turning off the flag takes a few seconds, while a rollback deploy takes 15 minutes;
  • you don't need a long feature branch; code goes into main in small pieces.

Where flags live: in the simple case application.yml or a config server; if you need to enable by user, a dedicated service (Unleash, LaunchDarkly, flagd) or a provider connected through the OpenFeature SDK.

There are traps too. The biggest is old flags. Two years later there are 80 ifs in the code, nobody knows which combination is enabled on prod, and the tests don't cover every variant. So each flag gets an owner and a removal date, and once the feature is at 100%, the if code is removed.

The second is that the flag service itself becomes a dependency. What happens if it doesn't respond? The client SDK should cache the last known values and have a safe default.