How long should a feature flag live?

Instead of creating a branch that lives for as long as the code takes to write, if it's behind a feature flag, the code can be merged into the mainline branch without affecting the rest of the codebase.

Being able to release changes incrementally lowers the risk compared to releasing a large change all at once.

But the same issue can occur with feature flags, and the longer that code is behind a feature flag, the more risk there will be when enabling the feature.

So, like feature branches, feature flags should be short-lived and only used for as long as is needed to create the first releasable version of the feature. The feature flag can be removed once the feature is live, and the feature can continue to be iterated on and improved.