Skip to content

What are Feature Flags

Key idea:

Feature Flags (feature toggles) — mechanism for turning features on/off at runtime without deploy. Code: if (flags.isEnabled("new-checkout")) { ... }. Enables: gradual rollout, A/B testing, kill switch for broken features, targeted release (beta users only, RU segment). Tools: LaunchDarkly ($), GrowthBook (open-source), Unleash, ConfigCat, build-your-own feature service.

Below: details, example, related terms, FAQ.

Check your site →

Details

  • Release flags: progressive rollout %
  • Experiment flags: A/B test 50/50
  • Kill switch: emergency disable a feature
  • Permission flags: user/tenant-based access
  • Ops flags: on/off for infrastructure (circuit breaker)

Example

// LaunchDarkly example
import { LDClient } from 'launchdarkly-node-server-sdk'
const ld = LDClient.init(sdkKey)
if (await ld.variation('new-checkout', user, false)) {
  return renderNewCheckout()
}

Related Terms

How to Implement Feature Flags in Your Codebase

Implementing feature flags in your codebase can significantly enhance your deployment strategy. Here’s a step-by-step guide on how to set up feature flags using a popular tool, LaunchDarkly.

1. Set Up Your LaunchDarkly Account: First, create an account at LaunchDarkly and set up your project.

2. Install the SDK: Depending on your programming language, install the corresponding SDK. For example, in a Node.js environment, use:

npm install launchdarkly-node-server-sdk

3. Initialize the SDK: Initialize the SDK with your client-side ID:

const LDClient = require('launchdarkly-node-server-sdk');
const client = LDClient.init('YOUR_SDK_KEY');

4. Define Feature Flags: In your LaunchDarkly dashboard, create a new feature flag. For example, create a flag named new-checkout.

5. Check Flag Status: Use the following code snippet to check if the feature is enabled for a user:

client.on('ready', () => {
client.variation('new-checkout', user, false, (err, showFeature) => {
if (showFeature) {
// Code for new checkout feature
} else {
// Code for old checkout feature
}
});
});

By following these steps, you can seamlessly integrate feature flags into your application, allowing for dynamic feature management.

Best Practices for Using Feature Flags

Feature flags can be a powerful tool, but their effectiveness depends on how they are implemented. Here are some best practices to ensure you get the most out of feature flags:

  • Keep Flags Short-Lived: Avoid long-term flags. Once a feature is fully rolled out and stable, remove the associated flag to reduce code complexity.
  • Document Flag Purpose: Maintain clear documentation for each feature flag. This ensures that all team members understand its purpose and can make informed decisions about its management.
  • Use Targeted Rollouts: Leverage targeted rollouts to test features with specific user segments. For example, start by enabling a feature for internal users before a wider release.
  • Monitor Performance: Use monitoring tools to track the performance of features controlled by flags. This helps in making data-driven decisions about whether to keep or remove a feature.
  • Implement a Kill Switch: Always have a plan for quickly disabling a feature if it causes issues. Feature flags serve as a kill switch that allows you to revert to the previous state without redeploying.

By following these best practices, you can maximize the benefits of feature flags while minimizing potential pitfalls.

Common Use Cases for Feature Flags

Feature flags are employed in various scenarios to enhance software development and deployment processes. Here are some common use cases:

  • Gradual Rollouts: Feature flags allow for gradual rollouts of new features to a subset of users. This minimizes risk and provides valuable feedback before a full rollout.
  • A/B Testing: Use feature flags to conduct A/B testing by toggling different features for different user groups. This helps in determining which version performs better based on user engagement metrics.
  • Beta Testing: Feature flags can target beta users to test new functionalities before they are released to the general public. This ensures that any issues are identified early.
  • Feature Toggle for Maintenance: Temporarily disable features that are under maintenance without a new deployment. This allows for quick fixes without affecting the entire application.
  • Regional Feature Deployment: Enable features for specific geographic regions, allowing companies to tailor their offerings based on local market needs.

These use cases demonstrate the versatility of feature flags, making them an essential strategy for modern software development.

Learn more

Frequently Asked Questions

Why need if we have canary?

Canary — deploy-time gradual. Feature flags — runtime toggle. Flags live longer (weeks): progressive rollout + experiments + kill switch.

Feature-flag debt — a problem?

Yes. Old flags clutter code. Best practice: TTL on a flag, auto-reminder in PR review after 30 days.

Open-source tools?

GrowthBook (free + paid), Unleash (free for 1 project), Flipt. LaunchDarkly — premium SaaS.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.