Feature flags: decoupling deploy from release with OpenFeature
Why deploy is not release, the four types of feature flags (with lifetime and owner), progressive rollouts, kill switches during incidents, and how to use OpenFeature with flagd without vendor lock-in.
Development$ npm install @openfeature/server-sdk @openfeature/flagd-provider▍Friday, 5 p.m. The code for the new checkout is done, reviewed, and tested, but the product team wants to launch it only on Monday — and only to 5% of customers. Without feature flags, the only option is to hold the merge, let the branch go stale, and hope the rebase doesn’t hurt. With feature flags, the code ships to production right now, turned off, and the launch becomes a separate decision, made with a click.
Deploy is not release
It’s worth separating two words that usually travel together:
- Deploy means putting a new version of the code into production. It’s a technical event.
- Release means exposing a feature to users. It’s a business decision.
A feature flag (or feature toggle) is a decision point in the code that chooses between two or more behaviors based on external configuration, which can change without a new deploy. In practice, it’s an if whose condition lives outside the code.
This separation is what makes trunk-based development possible: everyone integrates into the main branch several times a day, and whatever isn’t ready yet stays hidden behind a flag. Deploys become small and frequent; releases stay under control.
The four types of flags
Not all flags are the same. The classification popularized by Pete Hodgson on Martin Fowler’s website helps decide how long each one should live and who is responsible for it:
| Type | What it’s for | Lifetime | Owner |
|---|---|---|---|
| Release toggle | Hide incomplete code and roll it out gradually | Days to a few weeks | Team building the feature |
| Experiment (A/B) | Compare variants by measuring a metric | Length of the experiment | Product, supported by data |
| Ops (kill switch) | Turn off something expensive or unstable during an incident | Long, sometimes permanent | Team operating the service |
| Permission (entitlement) | Unlock features by plan, customer, or region | Permanent | Product / business |
The most common mistake is treating them all as release toggles — or, worse, letting release toggles live forever. A release flag that has completed its rollout is technical debt, not configuration.
Targeting and progressive rollouts
Targeting is the rule that decides which variant each request gets, based on an evaluation context: user ID, email, plan, country, app version. The most useful patterns:
- Internal audience first: release to anyone with a company email and use the feature for real before customers do.
- Cohorts: a group of beta customers, a country, a specific plan.
- Percentage: 1%, 5%, 25%, 50%, 100%. The key point is that the split must be deterministic: the same user must always land in the same variant, or they’ll see the checkout change on every click. That’s why tools hash a stable key (the user ID) instead of drawing a random number.
Between steps, watch the signals that matter: error rate, latency, and business metrics. If you already have symptom-based alerting, it’s the best gate for deciding whether the rollout moves forward.
Kill switches during incidents
A kill switch is an ops flag that turns off an entire feature — the personalized recommendations that overload the database, the integration with a partner that’s down. During an incident, flipping a flag takes seconds; a rollback with a new deploy takes minutes and may drag other changes along with it. Document kill switches in the service runbook: this cuts recovery time significantly, as discussed in reducing MTTR with business context.
OpenFeature: one API, many vendors
The problem with feature flag tools is coupling: each one has its own SDK, and switching vendors means touching every if in the codebase. OpenFeature solves this with an open specification for an API and SDKs, maintained as a CNCF project.
The idea is similar to OpenTelemetry’s: application code talks only to the standard API, and a provider bridges it to the actual tool. There are providers for many tools — flagd, LaunchDarkly, Flagsmith, Unleash, GrowthBook, ConfigCat, among others. Switching tools becomes a one-line change at initialization.
The main concepts:
- Provider: the adapter for the tool that stores and evaluates flags.
- Client: the object your code uses to evaluate flags.
- Evaluation context: the request attributes used for targeting. The
targetingKeyfield is the stable key used for percentage rollouts. - Hooks: functions that run before and after each evaluation, useful for logs, metrics, and traces.
TypeScript example
A Node.js service using the server SDK and the flagd provider (the file must be an ES module to use top-level await):
import { OpenFeature } from '@openfeature/server-sdk';
import { FlagdProvider } from '@openfeature/flagd-provider';
// connect to flagd; the address comes from environment variables
await OpenFeature.setProviderAndWait(
new FlagdProvider({
host: process.env.FLAGD_HOST ?? 'localhost',
port: Number(process.env.FLAGD_PORT ?? 8013),
}),
);
// record the variant of every evaluation as a structured log
OpenFeature.addHooks({
after(_hookContext, details) {
console.log(JSON.stringify({
msg: 'flag evaluated',
flag: details.flagKey,
variant: details.variant,
reason: details.reason,
}));
},
});
const client = OpenFeature.getClient();
type User = { id: string; email: string; plan: string };
function currentCheckout(user: User): string {
return `current checkout for ${user.id}`;
}
function newCheckout(user: User): string {
return `new checkout for ${user.id}`;
}
export async function startCheckout(user: User): Promise<string> {
const context = {
targetingKey: user.id, // stable key for percentage rollouts
email: user.email,
plan: user.plan,
};
// the second argument is the default value, used if anything fails
const useNewCheckout = await client.getBooleanValue('new-checkout', false, context);
return useNewCheckout ? newCheckout(user) : currentCheckout(user);
}
Note the default value false: if the provider is down or the flag doesn’t exist, evaluation doesn’t throw — it returns the default and records the reason. Always pick the safest default, usually the old behavior.
The flag definition in flagd
flagd is the project’s reference provider: a lightweight service that reads flag definitions in JSON (from a file, a ConfigMap, or a URL) and evaluates rules written in JsonLogic. The flag below enables the new checkout for anyone with a company email and for 10% of all other users:
{
"$schema": "https://flagd.dev/schema/v0/flags.json",
"flags": {
"new-checkout": {
"state": "ENABLED",
"variants": {
"on": true,
"off": false
},
"defaultVariant": "off",
"targeting": {
"if": [
{ "ends_with": [{ "var": "email" }, "@example.com"] },
"on",
{ "fractional": [["on", 10], ["off", 90]] }
]
}
}
}
}
To try it locally:
docker run --rm -p 8013:8013 -v "$(pwd)":/etc/flagd \
ghcr.io/open-feature/flagd:latest start --uri file:/etc/flagd/flags.flagd.json
Advancing the rollout means changing 10/90 to 25/75 and committing the change to Git — which gives you an audit trail for free. Check the current flagd documentation for the available operators and source options.
Flag debt: the part nobody talks about
Feature flags multiply code paths. Ten boolean flags are, in theory, 1,024 combinations. Without discipline, the codebase turns into a maze. A few practical rules:
- Descriptive, consistent names:
new-checkout, notflag2orjohns-test. - Owner and expiration date recorded alongside the flag, in the definition file itself or in the tool.
- Cleanup as part of the work: when you create a release toggle, open the ticket to remove it right away. The task is only done when the flag is out of the code.
- Test both paths: automated tests should cover the flag both on and off. The SDK provides an
InMemoryProvider, handy for pinning values in tests without depending on an external service.
Performance and observability
Evaluating a flag must not add noticeable latency. The flagd provider can evaluate remotely (with caching) or in-process, syncing the definitions and deciding locally. Avoid evaluating the same flag dozens of times per request: evaluate it once at the entry point and pass the result along.
And always record which variant was served. When the error rate goes up, the first question will be “does this only happen to users on the new checkout?”. With the variant in the logs and as a span attribute, you get the answer in seconds. The hook in the example does exactly that, and there are ready-made OpenTelemetry hooks in the project’s contrib repository. For the application side, see also the checklist for production-ready applications.
Checklist
- New features reach production turned off, behind a flag
- Every flag has a defined type, owner, and expiration date
- Percentage rollouts use a stable
targetingKey - Kill switches for critical services are documented in the runbook
- Automated tests cover the flag both on and off
- The evaluated variant shows up in logs and traces
- Release flags are removed from the code after a full rollout
Deploy is a technical routine; release is a business decision — and feature flags are what let you treat them separately.