Feature Flags
Overview
Feature flags let you merge unfinished work behind a switch, expose it to a chosen slice of users, and turn it off without shipping a build. A flag can be a plain on/off, a multivariate flag with weighted variants, or a carrier for a JSON payload used as remote config.
Flags are scoped to a single project. Every serving query filters on project_id and the column is NOT NULL, so a flag created in one project is never served to another project's SDK keys.
How a verdict is reached
Evaluation runs four stages in order. Understanding the order explains most surprises — in particular, that targeting is applied before rollout, so a 50% rollout means 50% of the users who already matched your conditions, not 50% of everyone.
- Master switch. If the flag is disabled, the verdict is off. Nothing else runs.
- Release conditions. If the flag has a targeting rule, it must match. A flag with no rule is ungated — that is a flag with no conditions, not a broken one.
- Rollout percentage. The user is hashed into a bucket and compared against the flag's percentage. The hash is salted with the flag key, so two different flags both set to 50% do not expose the same half of your users.
- Variant assignment. If the flag has variants, a second, independent hash picks one by cumulative weight. Independence matters: variant assignment is not correlated with whether the user made it past the rollout gate.
Edge case worth knowing: if your variant weights sum to less than 100, a user can fall through every variant. They are still on — the flag returns enabled with no specific variant. Design for that, or make your weights total 100.
Targeting conditions
Release conditions are evaluated by the shared audience engine — the same engine that powers paywall targeting and Journey entry — so a condition you can express for an audience you can express for a flag.
| Category | Conditions | Typical use |
|---|---|---|
| Device & app | platform · app_version · sdk_version · device_type · country | Ship to iOS first, gate a feature behind a minimum app version, or roll out by market. |
| Person | attribute · custom_attribute · install_date · last_seen | Anything you pass in `attributes` (PostHog's personProperties), plus lifecycle timestamps. |
| Audience | cohort · group · group_property | Target a saved cohort, or a whole B2B account — this is what makes “roll this out to Acme” expressible. |
| Subscription | entitlement · offering · auto_renew_enabled | Gate on what the user actually owns — paid-only features, or win-back treatment for lapsing users. |
| Behaviour | event_count · event_fired_in_window · days_since_event | Target on what the user has done, not just who they are. |
| Cross-product | experiment · experiment_variant · feature_flag · journey · journey_step · paywall · in_app_message · push_notification · email_notification | Chain a flag off another flag, an experiment arm, or where someone sits in a Journey. |
Evaluation context — what you must send
A condition can only match on data the SDK actually sends. This is the most common cause of a targeting rule that appears to match nobody: the rule is fine, but the request never carried the field.
| Field | Notes |
|---|---|
| customer_id | Required. The identity the rollout hash is computed from. |
| anonymous_id | Used when no customer is identified yet. |
| platform · app_version · sdk_version | Required for version and platform conditions. |
| country | Falls back to the x-geo-country / cf-ipcountry edge header when not supplied, so geo targeting works without you resolving location yourself. |
| attributes | Free-form person properties, read by attribute and custom_attribute conditions. |
| groups | A group_type → group_key map, e.g. { company: 'acme' }. Set it via BillDog.group() and B2B targeting works everywhere. |
Server-authoritative evaluation
Client SDKs never bucket locally. The verdict — on/off, which variant, and any payload — is computed server-side and delivered as a cached map. A user's assignment cannot drift between iOS, Android and web, and changing a rollout percentage takes effect without an app release.
Because the value is served rather than computed, reads are synchronous and cheap. A read before the first fetch completes returns the default — false, or nil for variant and payload.
Reading flags
Four accessors are available on iOS and Android:
| Method | Returns | Use for |
|---|---|---|
| getFeatureFlag(key) | Bool | The plain on/off question |
| getFeatureFlags() | Map<String, Bool> | Every cached flag at once |
| getFeatureFlagVariant(key) | String? | Which variant this user was assigned |
| getFeatureFlagPayload(key) | Any? | Remote JSON config attached to the flag or variant |
Variant and payload return nil when the flag is off, so an off flag can never leak a variant or a config blob.
// iOS (BillDogFull): the SDK's registered manager, created on first use
let abTest = BillDog.shared.abTest
await abTest.waitForFlags()
if abTest.getFeatureFlag(key: "new_checkout_flow") {
showNewCheckout()
}
let variant = abTest.getFeatureFlagVariant(key: "paywall_copy")
let config = abTest.getFeatureFlagPayload(key: "pricing_rules")// Android
val abTest = BillDogABTest(context)
if (abTest.getFeatureFlag("new_checkout_flow")) {
showNewCheckout()
}
val variant = abTest.getFeatureFlagVariant("paywall_copy")
val config = abTest.getFeatureFlagPayload("pricing_rules")// React Native / Expo
import { ABTestManager } from "@billdog.io/react-native";
const abTest = ABTestManager.getInstance();
if (await abTest.getFeatureFlag("new_checkout_flow")) {
showNewCheckout();
}
const variant = await abTest.getFeatureFlagVariant("paywall_copy");
const config = await abTest.getFeatureFlagPayload("pricing_rules");// Flutter
if (await BillDogFeatureFlags.getFeatureFlag('new_checkout_flow')) {
showNewCheckout();
}
final variant = await BillDogFeatureFlags.getFeatureFlagVariant('paywall_copy');
final config = await BillDogFeatureFlags.getFeatureFlagPayload('pricing_rules');Web: flags load only once a customer id is set — via customerId in configure() or logIn(). Before that, every flag reads as off.
Remote config without a release
Attaching a JSON payload turns a flag into a remote-config channel: ship the reader once, then change the payload from the dashboard. Payloads can be attached per variant, so one flag can serve different configuration to different arms. Because a payload only returns when the flag is on, you get a kill switch for free — turn it off and your code falls back to its built-in defaults.
Billing
Flag evaluation is metered once per request, not per flag returned. Fetching fifty flags in one call costs the same as fetching one — so batch your evaluation at app start rather than calling per flag, and the meter rewards you for it.
Flags created by experiments
Experiments are flag-backed: each creates a backing flag named __exp_<id> and buckets users through it. These are filtered out of the Feature Flags UI because the experiment owns them — manage them from Experiments. Do not create your own flags with an __exp_ prefix.
The experiment and experiment_variant conditions let a flag depend on an experiment arm — useful for shipping a follow-on change only to users who saw a particular variant.
Server SDKs
BillDog's eight server SDKs evaluate flags locally using a shared murmur-hash implementation, so a backend check costs no network round-trip. Bucketing is pinned to one conformance fixture across every SDK, so a given user resolves to the same bucket everywhere. See Server SDKs.
Related
Was this page helpful?
Or rate this page: