All guides

Feature flags: release without a deploy

OpenFeature describes a feature flag as an if/else statement that can be controlled at runtime, so application behavior changes without the deployment of new code. Unleash's documentation adds the discipline: keep flags short-lived and remove them when a rollout is complete.

A laptop showing a stylesheet in a code editor

Four kinds of flag

OpenFeature's introduction lists what flags are used for, and Unleash gives each use a flag type with an expected lifetime.

  • Release. Manage the release of new or incomplete features. OpenFeature describes it as hiding work-in-progress functionality from end users. Unleash's expected lifetime is 40 days.
  • Experiment. Perform multivariate or A/B testing. Unleash's expected lifetime is 40 days.
  • Operational and kill switch. Unleash's operational type covers a transition between technical implementations, with an expected lifetime of 7 days. Its kill switch type gracefully degrades system functionality and is permanent. OpenFeature describes this use as safely degrading parts of a production system during an outage.
  • Permission. Control feature access based on user roles or entitlements. Unleash treats it as permanent.

These lifetimes are Unleash's defaults, and an administrator can change them. Unleash marks a flag as potentially stale once it passes the expected lifetime of its type.

Where to evaluate a flag

Unleash's best practices give two rules.

  • Evaluate server-side when the context holds personal data. Evaluation needs contextual data such as user IDs, email addresses or locations. Unleash's guidance is to keep that data inside your application. A backend SDK fetches the flag configuration and evaluates locally. A frontend SDK sends its context to an evaluation server and receives the evaluated results.
  • Evaluate as close to the user as possible. Local evaluation removes network round trips, and it lets the application continue when the flag service is down.

Unleash also asks for a consistent user experience in percentage-based rollouts. Its first strategy is user hashing: assign users to consistent groups with a hashing algorithm based on a unique identifier, such as a user ID.

The OpenFeature standard

OpenFeature is an open specification. Its API for feature flagging is community-driven and tied to no vendor. It is a CNCF incubating project. It was accepted to CNCF on 17 June 2022 and moved to the Incubating maturity level on 21 November 2023.

The application calls a standardized SDK. A provider is the translation layer between that SDK and the flag management system in use. It can wrap a vendor SDK, call a REST API or parse a local file. This usage example is from the Node.js SDK documentation:

TypeScript

import { OpenFeature } from '@openfeature/server-sdk';

// Register your feature flag provider
try {
  await OpenFeature.setProviderAndWait(new YourProviderOfChoice());
} catch (error) {
  console.error('Failed to initialize provider:', error);
}

// create a new client
const client = OpenFeature.getClient();

// Evaluate your feature flag
const v2Enabled = await client.getBooleanValue('v2_enabled', false);

if (v2Enabled) {
  console.log('v2 is enabled');
}

The second argument of getBooleanValue is the default value. Data about one request goes in a third argument, the evaluation context. The same page shows a context that holds targetingKey: req.session.id.

The OpenFeature ecosystem page lists providers for many flag systems, among them flagd, Flagsmith, Flipt, GO Feature Flag, GrowthBook, LaunchDarkly and Unleash.

The default when the flag service is unreachable

The OpenFeature specification requires that evaluation methods never throw exceptions or otherwise abnormally terminate. In the event of abnormal execution, such as a network failure, a flag evaluation call must return the default value. The detailed evaluation methods return an evaluation details structure, which carries an error code in that case.

Unleash's best practices add a rule about availability. An application should have no dependency on the availability of the flag system, and SDKs should work with locally cached data, using the last known configuration or defaults.

Choose each default as the behavior you want when the flag service cannot be reached. Then check whether your SDK keeps the last known configuration.

Tests for both paths

The trunk-based development site says CI should guard the flag permutations you reasonably expect. After the unit tests, the pipeline fans out and runs once for each meaningful flag permutation. The site also counts on unit tests for everything, including code that is turned off in production.

Unleash asks for a testable SDK. Developers can then toggle flags, simulate conditions and observe results without redeployments.

Flag debt and removal

Unleash's rule for a finished rollout: take the feature flag out of your code, archive it, and delete the old code paths the new functionality replaced. Unleash also says to avoid feature flags for static application configuration, such as credentials, a server port or an API base URL.

The trunk-based development site describes how the debt builds up. Flags get put into codebases and are forgotten as the team turns to new deliverables. It suggests listing each flag with a review-for-delete date.

A checklist for each new flag

  • Give it a type, and with the type an expected lifetime.
  • Give it a name that is unique across your whole system. Unleash lists this among its best practices.
  • Choose its default for the case where the flag service is unreachable.
  • Pass user data in the evaluation context, and evaluate server-side when that data is personal.
  • Test each flag permutation that you expect to run.
  • Plan its removal: the flag, and the old code path.

Sources

Want a second pair of eyes on yours? We do this work for a living.

Book a call

More guides