Skip to content

Feature flags: risk-free releases and keeping toggles under control

B2Bnetwork team · · 6 min

Technology and trends

In brief

A feature flag (feature toggle) is a condition in the code that turns a feature on or off without a new deployment. Flags let you separate deploying code from releasing a feature to users: code reaches production switched off, and you turn it on gradually, for a chosen group, with the option to roll it back instantly. The risk then shifts from the release to flag management. Every flag needs an owner, a type, a removal date and tests of both states, or after a year the system has hundreds of dead toggles.

What feature flags are and what they give you

A flag is a decision point in the code: “if the `new-installment-calculator` flag is on for this customer, use the new installment calculator, otherwise the old one”. The flag value comes from a flag management system or from configuration, not from the code, so it can be changed in seconds.

The main benefits:

  • deploy without releasing: the team merges code to the main branch daily, including unfinished features that stay switched off;
  • progressive rollout: the feature goes to employees first, then to 1% of customers, then to everyone;
  • fast rollback: when error rates climb, you switch the flag off instead of rolling back the version;
  • experiments: two variants for two groups and a comparison of the results.

In banking and insurance a flag is often also a contingency plan written into the risk analysis, as we describe in the article on risk-based testing.

Flag types and how long they live

Flags differ in purpose and lifetime. Mixing the types is the most common source of mess.

TypePurposeWho toggles itLifetime
Releasehiding an unfinished feature, progressive rolloutproduct teamdays or weeks, then removal
Experimentcomparing variantsproduct team, analystduration of the experiment
Operational (kill switch)cutting off an expensive or unreliable feature under loadon-call, operations teamlong, but reviewed
Permissionaccess to a feature for a plan, region or customer groupbusinesslong, it is product configuration by then

A release flag that lives for a year is no longer a release flag. It becomes undocumented configuration and debt, which we cover in the article on technical debt.

Progressive rollout step by step

An example for a new loan application flow in a bank's app:

  1. Code in production, flag off. The deployment changes behavior for no one.
  2. Turned on for employees. Testing on real data and integrations, with log monitoring.
  3. Turned on for a small share of customers. Assignment by a stable key, such as the customer ID, so the same person does not jump between variants.
  4. Watching the indicators. Errors, response time, application abandonment rate. Set rollback thresholds before you start, ideally in relation to your SLOs and error budget.
  5. Expanding the reach. Further thresholds, up to all customers.
  6. Removing the flag and the old code. This is the step most often skipped, and without it the process is not finished.

OpenFeature: a shared standard instead of vendor lock-in

OpenFeature is an open specification that provides a single, vendor-agnostic API for evaluating flags. The project is developed within the Cloud Native Computing Foundation: it was accepted into the CNCF on June 17, 2022, and moved to the incubating level on November 21, 2023.

The main concepts of the specification:

  • Evaluation API: the methods an application uses to read a flag value;
  • provider: the translation layer between the API and a specific flag system, whether commercial, open source or a file;
  • evaluation context: data about the evaluation, for example the customer ID, country or plan;
  • hooks: extension points, for example for logging and telemetry of every evaluation;
  • events: notifications about changes in the provider state or flag configuration.

Evaluating a flag in the Node.js SDK looks like this:

const client = OpenFeature.getClient();
const newCalculator = await client.getBooleanValue("new-installment-calculator", false, {
  targetingKey: customer.id,
  country: customer.country,
});

The second argument is the default value, used when the flag system does not respond. Choosing a safe default is a design decision: usually it is the old, proven path. Changing your flag system vendor then means swapping the provider, not rewriting every call site in the code.

Testing and keeping toggles under control

Every flag doubles the number of possible paths through the code, so tests need deliberate planning:

  • unit tests of both states of every release flag;
  • regression in the production configuration and in the target configuration, meaning with the flags that will be turned on in the next release;
  • a default value test: what happens when the flag system is unavailable;
  • no testing of every combination: ten flags give over a thousand combinations, so pick the ones that affect the same process.

How to structure regression with frequent releases is covered in the article on regression testing with weekly releases.

Simple rules keep flags under control:

  1. Every flag has an owner, a type, a description and a planned removal date in the system.
  2. When a release flag is created, a task to remove it is created at the same time.
  3. A monthly review: flags that have been on for 100% for a long time, or that the application no longer reads, go up for removal.
  4. Flag names say what they do, for example `payments-new-gateway`, not `test2`.
  5. Changes to flag values in production leave an audit trail: who, when and why.

B2Bnetwork engineers build test automation and release pipelines on projects for banks, insurers and SaaS companies. An example from a product deployed for many clients is described in the SaaS B2B test automation case study.

Questions and answers

How does a feature flag differ from a branch in the repository?

A branch keeps unfinished code outside the main line, and it has to be merged later, often with conflicts. A flag lets you merge code daily and keep the feature switched off in production. Feature branches that live for weeks make integration harder, while flags move that difficulty into configuration, which is easier to control.

Do feature flags slow down the application?

Usually not, if the SDK evaluates flags locally: it keeps the configuration in memory and refreshes it in the background, so an evaluation does not require a network call. Problems appear when the application queries a remote service on every evaluation, or when there are so many flags that the code becomes unreadable. A cache in the SDK solves the first, regular flag removal the second.

How many flags is too many?

The number says less than their age. A few dozen active release flags in a large product is normal, as long as each has an owner and a removal date. Warning signs are flags that have been on for everyone for months, flags without an owner and flags nobody can safely turn off.

Do flags replace testing before a release?

No. A flag limits the impact of a defect, because the feature can be switched off quickly and released to a small group first. It does not prevent defects that show up immediately, for example in a data migration or a change to a shared library. Pre-release testing and progressive rollout work together.

What it looks like in a project

Considering a new technology for your system? Talk to an engineer.

Let's talk

Read more: Technology and trends