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

Here are some popular applications of feature flags in an agile environment.

  • Product testing
  • Conducting A/B experiments
  • Migrations
  • Canary launches
  • Enable safer continuous deployment

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.

Final thoughts

A feature flag adds to the system's complexity but brings more flexibility. With the correct testing techniques, you can ship code more frequently without jeopardizing your system reliability.