# External Config Store: Change App Settings Without Redeploying

> Move app settings out of the deployment package into one shared store, so teams can change, secure, and share them without rebuilding the code.

**In short:** An external config store moves app settings out of the deployment package into one shared store, so teams can change, secure, and share them without redeploying.

From "System design", a free course by Venkat R. Murty: https://designervenkat.online/learn/system-design/external-config-store

## What You Will Learn

Almost every app depends on settings. A setting is a value the app reads while it runs. Examples include the address of a database, a switch that turns a feature on or off, the link to a partner service, and a limit such as how many items fit on one page. This lesson covers the External Config Store pattern. The idea is to move these settings out of the app's deployment package and into a separate shared service. After that move, people can change a setting, lock it down, and share it across many running copies of the app without rebuilding or redeploying the code.

You will learn why settings packed inside the app cause trouble, how apps read settings from a store, how a real Azure example works step by step, and what to watch for in production. A short Python sample shows the fallback idea without using any outside service.

- **Setting:** A value the app reads while it runs, such as a URL, a limit, or an on/off switch.
- **Deployment package:** The bundle of code and files that you ship to a server to run an app.
- **Config store:** A separate service that holds settings and gives them to apps on request.
- **Feature flag:** A switch that turns a feature on or off without changing the code.
- **Instance:** One running copy of an app. A service may run 20 instances at once.
- **Redeploy:** Build the app again, ship it, and start it again on the servers.
- **Cache:** A local copy of data kept in the app's memory, so the app does not ask for it every time.
- **Secret:** A sensitive value, such as a password, API key, or certificate.
- **Fallback:** A backup value the app uses when the live value cannot be read.

## What Is the Problem with Settings Inside the Package?

Most platforms ship configuration files together with the app. Some teams edit those files on a server to change behavior. Many changes, though, still need a full redeploy. A redeploy means building, testing, and shipping the whole app again. It often causes downtime and extra admin work, so a small change can cost as much effort as a code change.

- **Slow to change:** A new partner URL means a new build and a rollout to every server. A one-line edit turns into a release.
- **Copies drift apart:** When some instances get an update and others do not, users can see different behavior. Hand-edited files on 20 machines are easy to get wrong.
- **Hard to share:** Two services that need the same database address each keep their own copy. When one copy changes, the other may keep the old value.

The root cause is that settings change on a different schedule than code. Developers ship code when a feature is ready. A team may need to change a setting in minutes, for one region or for every user.

## What Is the Idea of One Central Source of Truth?

The External Config Store pattern puts settings in external storage. It then gives apps one clear interface to read them and to update them. In a cloud app, that storage is usually a cloud service or a dedicated configuration service. It can also be a hosted database. Whatever the storage is, the store becomes the single place where anyone can ask what the current value is.

- **Versions:** The store keeps more than one version of settings, so you can compare what changed and go back to an earlier value.
- **Access control:** Only approved people and apps can read or write settings. Azure documents that access is set at the level of the store, so separate stores can have separate permissions.
- **Audit history:** Logs record who read or changed a value, and when. This helps you answer what changed before an incident.
- **Environments:** Development, staging, and production can each have their own values, so one setting does not leak into the wrong place.

## How Do Apps Read and Refresh Settings?

1. **Read at startup:** The app loads its settings from the store when it starts. Azure's App Configuration provider is added like a JSON file source, and configuration is read on startup.
2. **Keep a local cache:** Asking the store on every request would be slow and would add load. A cache inside the configuration layer may be worth adding when the backing store is slow or has high latency.
3. **Refresh while running:** The app can check for changes on a timer, or it can listen for change notices. Apps may check the store repeatedly, or they may receive push notifications when settings change.
4. **Use the new value:** After a refresh, the app reads the new value on its next check. The default polling interval in the .NET provider was 30 seconds. In case the polling interval was not specified, a default value of 30 seconds was used.
5. **Fall back when the store is unreachable:** The app keeps working with what it already has. Cached data can help an application through brief connectivity problems with the store.

### Should You Use Polling or Change Events?

Polling is the simplest choice. The app asks the store on a timer, and it works even if the store has no event system. The cost is extra requests, even when nothing has changed. Azure's.NET team said that constant polling was not the smartest approach, and it moved toward refresh that happens when the app is busy. The blog describes the earlier approach as one that promoted constant polling of configuration. Change events avoid that waste. The store sends a notice when a value changes, and the app refreshes in response. Events add more parts to run, so they are a trade you choose on purpose.

### What Happens When the Store Is Down?

Cached values help with short network problems while the app is running. They do not help when the store is down at startup and there is no cache yet. So plan for both cases. While running, keep using the cached values and log the failure. At startup with no cache, use default values in the code, or a last-known-good file that your deployment pipeline ships with the app. Each path should be tested before an outage happens.

> **Tip:** Choose fallback defaults with care. A default that is too strict or too loose can hurt users as much as an outage does.

## Worked Example: A Flag and a Page Size in Azure

Azure App Configuration is a managed store for application settings and feature flags. In this example, a web app uses two values: a Beta feature flag and a page size of 20. An operator edits both in the Azure portal. The running app picks up the change without a redeploy. The same idea works with any store that offers a similar design.

1. **Create the flag:** Open the store in the Azure portal. Create a feature flag named Beta in the store.
2. **Add the page size:** Use the Configuration explorer to add a key named Shop:PageSize with the value 20. This is where ordinary key-values are edited.
3. **Wire up the app:** In Program.cs, call the feature flag option inside the store setup, so the app loads the flags. Then the Beta page checks the flag. With the flag off, the page returns 404 Not Found.
4. **Flip the switch:** The operator opens Feature manager and turns the Beta toggle to On. Nothing is built, copied to a server, or restarted by hand.
5. **Instances see the change:** Each running copy checks the store on its refresh schedule. With change events, the store can apply the change in a few seconds.

> **Tip:** Seconds are not a promise. The wait depends on how each app refreshes. A short polling interval gives fast updates, but every instance sends its own requests to the store.

**Quick check:** A checkout service runs on 12 instances. A manager asks to raise PageSize from 20 to 50 for a sale. The store is set to poll every 30 seconds. What happens after the operator saves the new value?

A. Every instance must be rebuilt and redeployed before the new size appears.
B. Each instance reads the new value on its next refresh, usually within about 30 seconds, with no build or deploy.
C. Only the instance that handles the next request sees 50, and the rest keep 20 until someone restarts them.
D. The change applies at once, but all instances crash until they are redeployed.

**Answer:** B. The store is the source of truth. The instances only need to refresh to read the new value. The wait depends on the refresh interval, so it is not always instant.

## Trade-Offs and Good Practice

- **The store is now a dependency:** Apps rely on the store to start and to stay current. Choose a store with good availability and robustness, make sure it can be backed up, and monitor it like any other critical service.
- **Keep secrets out of general settings:** Flags and endpoints fit well in the store. Passwords, API keys, and certificates belong in a dedicated secret system with encryption and tight access. The pattern guidance recommends keeping secrets in a dedicated secret-management system. The full protection story has its own lesson.
- **Validate and roll back:** Check a new value before it goes live. A URL should parse, and a number should be inside a safe range. Keep the history, so a bad change can be reversed quickly.
- **Stage changes that affect many apps:** One setting can change the behavior of several services. Roll shared changes out in stages, and tell the owners of every app that reads the setting.
- **Do not use a store for everything:** A small app whose settings change only during normal releases may not need a store. The extra service adds work that is only worth it when sharing and quick changes matter.

> **Tip:** Before you move a setting into the store, ask three questions: who needs to change it, how often it changes, and whether it is a secret.

## Try It: The Fallback Idea in Python

The sample below imitates a config store. It does not call Azure or any network service. It shows three outcomes: the live value, the last known value, and the built-in defaults. It uses only the standard library, so the output is the same every time.

```python
class StoreDown(Exception):
    pass

class ConfigStore:
    def __init__(self, values):
        self.values = dict(values)
        self.reachable = True

    def read(self):
        if not self.reachable:
            raise StoreDown('store is unreachable')
        return dict(self.values)

DEFAULTS = {'page_size': '10'}

def load_settings(store, cache):
    try:
        fresh = store.read()
        cache.clear()
        cache.update(fresh)
        return fresh, 'live'
    except StoreDown:
        if cache:
            return dict(cache), 'last known'
        return dict(DEFAULTS), 'defaults'

cache = {}
store = ConfigStore({'page_size': '20'})
settings, source = load_settings(store, cache)
print(source, settings['page_size'])

store.reachable = False
settings, source = load_settings(store, cache)
print(source, settings['page_size'])

down = ConfigStore({'page_size': '99'})
down.reachable = False
settings, source = load_settings(down, {})
print(source, settings['page_size'])

```

Output:

```text
live 20
last known 20
defaults 10

```

Read the output line by line. The first line shows a healthy store, so the app takes the live value and saves it in its cache. The second line shows the store unreachable, so the app uses the cached copy. The third line shows a store that is down at startup with an empty cache, so the app uses the defaults. A real app would also log each fallback, so the team knows the store needs attention.

## Check Your Understanding

**Quick check:** Your service runs on 20 instances. A third-party API URL changes. Today you must rebuild and redeploy every instance. Which plan uses an external config store well?

A. Edit the URL in each server's local file, then restart the servers one at a time.
B. Change the URL once in the store. Each instance reads it on its next refresh, with no rebuild. If the store is briefly down, each instance keeps its cached last-known URL.
C. Keep the URL in the code, but ship a new build every hour to pick up changes.
D. Change the URL in the store, and let every instance stop until the store is back.

**Answer:** B. One change in the store reaches all instances through refresh. The cache covers a short outage, so the service keeps running with the last good URL.

**Quick check:** A developer wants to save a payment API key in the same store as the feature flags, because the store is encrypted and easy to read at startup. What should the team lead say?

A. That is fine, since an encrypted store is safe for every kind of value.
B. Put the key in the deployment package, because only the code can read it.
C. Keep flags and endpoints in the store, and move the key to a dedicated secret manager with strict access.
D. Keep the key in the store, but make the store public so every service can read it.

**Answer:** C. Routine settings suit the store. Secrets need their own system with encryption and tight access, plus their own review. Encryption alone does not solve who can read the value.

## Key Takeaways

The External Config Store pattern moves settings out of the deployment package and into one shared, controlled place. Apps read values at startup, keep a cache, and refresh while they run. When the store is down, they fall back to the last known values or to safe defaults. The benefit is speed and consistency: a change happens once and reaches every instance without a rebuild. The cost is a new dependency to keep available, plus the discipline to validate, audit, and roll back changes. Keep secrets in their own system, and use the store only where its benefits outweigh the added work.

## Sources

- [External Configuration Store pattern - Azure Architecture Center](https://learn.microsoft.com/en-us/azure/architecture/patterns/external-configuration-store)
- [What is Azure App Configuration? - Microsoft Learn](https://learn.microsoft.com/en-us/azure/azure-app-configuration/overview)
- [External configuration store using Azure App Configuration Service - Code Samples](https://learn.microsoft.com/en-us/samples/azure-samples/azure-app-configuration-sample/dynamic-configuration-using-azure-app-configuration-service/)
- [Redesigning Configuration Refresh for Azure App Configuration - .NET Blog](https://devblogs.microsoft.com/dotnet/redesigning-configuration-refresh-for-azure-app-configuration/)
- [Tutorial: Use dynamic configuration using push refresh in a .NET app](https://learn.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-dotnet-core-push-refresh)
- [Tutorial: Use dynamic configuration using push refresh (.NET, GitHub source)](https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/azure-app-configuration/enable-dynamic-configuration-dotnet-core-push-refresh.md)
- [Quickstart for adding feature flags to Azure Functions](https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-feature-flag-azure-functions-csharp)
- [Quickstart for adding feature flags to ASP.NET Core apps](https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-feature-flag-aspnet-core)
- [Quickstart for adding feature flags to Spring Boot with Azure App Configuration](https://learn.microsoft.com/en-us/azure/azure-app-configuration/quickstart-feature-flag-spring-boot)
- [Quickstart: Manage feature flags in Azure App Configuration](https://learn.microsoft.com/en-us/azure/azure-app-configuration/manage-feature-flags)
- [Azure App Configuration Considerations for Multitenancy - Azure Architecture Center](https://learn.microsoft.com/en-us/azure/architecture/guide/multitenant/service/app-configuration)
- [Auto-Refresh Azure App Config in .NET: The Sentinel Key Pattern (DNT blog)](https://dnt.co.il/how-to-automatically-refresh-configurations-with-azure-app-configuration-in-net-code4it/)
