Using ModHeader to toggle feature flag

What is a feature flag?

A feature flag is a software development process used to enable or disable functionality remotely without deploying code. New features can be deployed without making them visible to users. Feature flags help decouple deployment from release letting you manage the full lifecycle of a feature.

Feature flags go by many names:

  • Feature toggle
  • Feature flipper
  • Conditional feature
  • Feature switch
  • Feature controls
  • Release toggle
  • Experiment

Whatever their name, the idea behind feature flags is to build conditional feature branches into code in order to make logic available only to certain groups of users at a time. If the flag is on, new code is executed, if the flag is off, the code is skipped.

Feature flag use cases & benefits

Using feature flags during web development offers several benefits:

  1. Controlled Feature Rollout: Feature flags enable developers to release new features to a specific subset of users or environments, allowing for controlled testing and gradual rollout. It mitigates the risks associated with deploying untested or unstable features to all users at once.
  2. A/B Testing and Experimentation: Feature flags facilitate conducting A/B tests by selectively enabling or disabling a feature for different groups of users. This allows developers to gather data and compare the performance and user response to different variations, helping make informed decisions on feature improvements.
  3. Rapid Iteration and Continuous Deployment: Feature flags decouple the deployment of a feature from its activation, empowering developers to continuously deploy code while keeping certain features hidden until they are fully tested and ready for release. This enables a faster development cycle and reduces the time to market.
  4. Hotfix and Rollback: In cases where a deployed feature causes issues or bugs, feature flags provide a mechanism to quickly disable the feature without requiring a full deployment rollback. This ensures faster bug fixes, reduces downtime, and maintains overall system stability.
  5. Customized User Experiences: Feature flags allow developers to personalize the user experience by selectively enabling features for different user segments dynamically. This enables targeted releases, customized offerings, and tailored experiences based on user preferences or specific user cohorts.
  6. Continuous Integration and Collaboration: Feature flags promote collaboration among developers working on the same codebase by allowing them to work on separate features independently. Developers can merge their code into the main branch without adversely affecting features currently being developed by other team members.

Overall, using feature flags in web development provides greater flexibility, control, and risk mitigation during the release of new features. It fosters experimentation, quick iteration, targeted customization, and seamless collaboration among developers, ultimately leading to better user experiences and improved software quality.

How to use Feature flags

There are many platforms that will help you maintain and rollout feature flags. Here are a few:

Most large corporations also have their own internal feature flags solutions. Most solutions typically allow developers to quickly turn on/off a feature flag to a certain group of users. However, using feature flags can also creates more headaches to developers who need to test multiple states of the system. Insufficiently testing of feature flags may lead to more bugs that can potentially be disastrous.

Testing feature flags

Many feature flag solutions will allow you to force enable/disable a feature flag on a particular user. It might work on a specific user ID, or some magic request header, or based on a cookie value. Using ModHeader, you can quickly enable a feature flag using the following steps:

  • Click on , and select Request header
  • Add your feature flag request header. For example, X-Feature-Flag: FEATURE_FOO_BAR
  • Now visit your web server. It should have the FEATURE_FOO_BAR enabled.
  • To turn off the feature, simply uncheck the X-Feature-Flag: FEATURE_FOO_BAR request header row
  • Going one step further, you can click on , and select Tab filter to enable the feature flag override only on the selected tab. This way, you can open another tab side-by-side to view the page without the feature flag override.

Note: If your feature flag solution reads from the cookie instead of request header, you can use ModHeader for that too! Simply click on , and select Cookie request to override a cookie value.