Lesson 3 of 3 Centralized Configuration with Azure App Configuration

Using Feature Flags and Dynamic Refresh

This lesson explains dynamic refresh with sentinel keys and events, feature flags and filters, and how refresh affects quotas.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain the sentinel key pattern.
  • Describe event-driven refresh.
  • Describe feature flag filters and variants.
  • Explain how refresh intervals affect request quotas.

Dynamic refresh with a sentinel key

By default the provider loads configuration once. Dynamic refresh lets a running application pick up changes. The application names keys to watch and a refresh interval; when the application calls refresh() after the interval has passed, the provider checks the watched keys and, if any changed, reloads the selected configuration.

The recommended design watches a single sentinel key, such as OrdersApi:Sentinel, rather than every key. Operators change all the settings they need, and change the sentinel last. This makes a group of changes take effect together, so the application never runs with half of a related set of values, and it keeps monitoring cheap: one request per interval checks one key.

from azure.appconfiguration.provider import load, SettingSelector, WatchKey

config = load(endpoint="https://STORE.azconfig.io", credential=credential,
              selects=[SettingSelector(key_filter="OrdersApi:*", label_filter="prod")],
              trim_prefixes=["OrdersApi:"],
              refresh_on=[WatchKey("OrdersApi:Sentinel", label="prod")],
              refresh_interval=60)

def handle_request(request):
    config.refresh()                    # cheap; checks the sentinel at most once per minute
    return search(request, top_k=int(config["Retrieval:TopK"]))

refresh() is called from the application's normal flow, such as at the start of each request or from a background timer. Settings resolved from Key Vault references are also reloaded on refresh, and the provider can refresh them on their own interval.

True or false

Dynamic refresh

Exam skills 4.1.2

Decide whether each statement about dynamic refresh is true.

Log in to try this activity Interactive activities are free with an account.

Event-driven refresh

Polling with an interval means a change takes up to the interval to arrive. App Configuration also publishes events, such as Microsoft.AppConfiguration.KeyValueModified, to Event Grid. An application can subscribe, for example through a Service Bus queue, and trigger a refresh immediately when the sentinel changes, while keeping a longer polling interval as a safety net. This reduces both latency and request volume for large fleets.

Scenario questions

Faster configuration changes

Exam skills 4.1.2 · 3.1.2

Choose how to make configuration changes reach a large fleet quickly.

Log in to try this activity Interactive activities are free with an account.

Feature flags

A feature flag turns a piece of functionality on or off at run time without a deployment, which supports gradual rollouts, quick kill switches and experiments, such as trying a new reranking step for some users. In App Configuration, feature flags are special key-values stored under the prefix .appconfig.featureflag/ with their own management experience in the portal and CLI.

A flag can be simply enabled or disabled, or it can have filters that decide when it is on.

  • The targeting filter enables a flag for named users or groups and a percentage of everyone else, which supports gradual rollouts.
  • The time window filter enables a flag only between a start and an end time.
  • Custom filters implement application-specific rules.

Feature flags can also have variants, which return different configurations, such as prompt templates or model names, to different users for experiments.

from azure.appconfiguration.provider import load
from featuremanagement import FeatureManager, TargetingContext

config = load(endpoint="https://STORE.azconfig.io", credential=credential,
              feature_flag_enabled=True, feature_flag_refresh_enabled=True, refresh_interval=30)
features = FeatureManager(config)

def answer(question, user):
    config.refresh()
    if features.is_enabled("SemanticReranker", TargetingContext(user_id=user.id, groups=user.groups)):
        return answer_with_reranker(question)
    return answer_basic(question)

Feature flags are loaded with feature_flag_enabled=True and evaluated by the featuremanagement library's FeatureManager. Feature flags are monitored for changes separately from the sentinel key.

The following diagram shows the rollout stages of a feature flag and the order of configuration changes for a new reranking step.

Rolling out the reranking step with a feature flag and changing its settings safely. A targeting filter enables the step for the testers group, then a 10% default rollout, then everyone, and a 30-second refresh interval lets the flag be turned off within a minute. The model name and threshold are updated first and the sentinel key last, so the application applies both together.
The key names are illustrative.
Match the pairs

Feature flag filters and variants

Exam skills 4.1.2

Match each rollout requirement with the feature flag capability that meets it.

Log in to try this activity Interactive activities are free with an account.

Refresh, quotas and safety

Every application instance sends refresh requests, so the refresh interval multiplied by the number of instances determines the request rate. A fleet of 200 containers refreshing every five seconds would quickly exhaust a Developer or Standard tier quota; intervals of 30 seconds or more, a single sentinel key and event-driven refresh keep the volume small. Repeated sentinel checks that find no change largely do not count against the hourly quota on the Standard tier, but they still consume throughput.

Watch a sentinel key
Requests per interval per instanceOne
Atomic group changesYes, change the sentinel last
Latency of changesUp to the interval
Choose when Most applications
Watch every key
Requests per interval per instanceOne per watched key
Atomic group changesNo, keys change one by one
Latency of changesUp to the interval
Choose when Very small configurations only
Event-driven refresh
Requests per interval per instanceNone until a change
Atomic group changesYes, when the event concerns the sentinel
Latency of changesSeconds
Choose when Large fleets that need fast changes
Fill in the value

Refresh request rates

Exam skills 4.1.2

Work out how many refresh requests a fleet sends.

Log in to try this activity Interactive activities are free with an account.
Worked example

A safe rollout of a new retrieval step

A team adds a reranking step to its RAG API. They want it enabled first for an internal testers group, then for 10% of customers, then for everyone, and they want to turn it off within a minute if quality drops, without redeploying. They also need to change the reranker's model name and threshold together.

The step goes behind a feature flag with a targeting filter: the testers group first, then a 10% default rollout percentage, then 100%. The application loads flags with feature flag refresh enabled and a refresh interval of 30 seconds, so disabling the flag takes effect within a minute. The model name and threshold are ordinary key-values watched through a sentinel key: operators update both values, then the sentinel, so the change applies atomically.

A new deployment for each rollout stage would be slow and could not be reversed within a minute. Watching both keys individually could apply the model change before the threshold change. A time window filter would enable the step by date, not by audience.

Check yourself

Why should operators change the sentinel key last when updating several related settings?

Show answer

The provider reloads configuration only when the watched sentinel changes, so changing it last makes all the related values take effect together.

Exam Tips

Remember for the exam

  • Dynamic refresh: refresh_on watches keys; refresh() reloads after refresh_interval.
  • Change related settings first and the sentinel key last so changes apply together.
  • Feature flags use filters such as targeting (users, groups, percentage) and time window.
  • Fleet size times refresh frequency drives request volume; use longer intervals or Event Grid events.