Skip to main content

Feature Flags and Configuration

A feature flag turns a feature on or off at runtime, without a deploy. Runtime configuration changes values such as limits or timeouts in the same way. When many instances of a service read the same flag, they must all see the same value, and a bad change must be easy to find and undo.

Kahuna stores flags and settings as persistent keys. Every instance reads the same committed value, revisions and compare-and-set updates keep two admins from overwriting each other's change, and historical snapshot reads show which values were visible at a past moment.

To refresh a local copy when a persistent flag changes, see Watch Key Changes.

Use a predictable key layout:

config/{environment}/{service}/{name}

Examples:

config/prod/payments/max-refund-amount
config/prod/search/enable-new-ranking

Read a Flag​

KahunaKeyValue flag = await client.GetKeyValue(
"config/prod/search/enable-new-ranking",
KeyValueDurability.Persistent
);

bool enabled = flag.Success && flag.ValueAsString() == "true";

Update Safely With Compare Revision​

Read the current revision, then update only if nobody changed it first:

KahunaKeyValue current = await client.GetKeyValue(
"config/prod/search/enable-new-ranking",
KeyValueDurability.Persistent
);

KahunaKeyValue updated = await client.TryCompareRevisionAndSetKeyValue(
"config/prod/search/enable-new-ranking",
"true",
compareRevision: current.Revision,
durability: KeyValueDurability.Persistent
);

if (!updated.Success)
Console.WriteLine("Flag changed before this update was applied.");

Read Historical Configuration​

Use LastModified from one read as a snapshot anchor:

KahunaKeyValue anchor = await client.GetKeyValue(
"config/prod/search/enable-new-ranking",
KeyValueDurability.Persistent
);

List<KahunaKeyValue> configAtAnchor = await client.ScanAllByPrefix(
"config/prod/search",
KeyValueDurability.Persistent,
snapshotMs: anchor.LastModified
);

This is useful during incident review when you need to know which flags and settings were visible at one point in time.

For settings that should be read together, use one bucket:

get by bucket `config/prod/search`

From a client:

List<KahunaKeyValue> settings = await client.GetByBucket(
"config/prod/search",
KeyValueDurability.Persistent
);

Operational Notes​

  • Use persistent durability for production configuration.
  • Use compare-revision updates in admin tools to avoid lost updates.
  • Keep values compact and parseable, for example JSON for structured settings.
  • Use snapshot reads during postmortems to reconstruct the exact configuration that was visible at the time.