Microservice Patterns
External Configuration Store
Keep settings, feature flags and secrets out of the deployable artefact, in a central store the application reads at runtime — so one image runs everywhere and a bad setting is fixed in seconds, not with a redeploy.
What you will learn
- Separate configuration from code and from the build artefact.
- Refresh configuration at runtime safely.
- Treat secrets differently from ordinary settings.
- Plan for the configuration store being unavailable.
Overview
A restaurant chain prints menus in every branch. If a price is wrong, every branch must reprint. With a digital menu board fed from head office, one change shows up everywhere within a minute.
When configuration is baked into the image (application.yml in the JAR, values in the container), changing it means a new build and a redeploy, and each environment needs its own artefact. An external configuration store (Spring Cloud Config, Azure App Configuration, AWS AppConfig, Consul, Kubernetes ConfigMaps) holds settings per environment; the same image reads them at start-up and refreshes them while running. Secrets go to a dedicated secrets manager.
Run it
A wrong payment-provider setting ships at t = 10 s. Compare how long checkouts keep failing when the fix needs a rebuild and rolling redeploy (A) and when the value is reverted in the store (B).
What goes where
| Kind | Where | Refresh |
|---|---|---|
| Code defaults | In the artefact | Never at runtime |
| Environment settings (URLs, pool sizes) | Config store / ConfigMap | On start-up, some at runtime |
| Feature flags and kill switches | Config store or flag service | Seconds |
| Secrets (passwords, keys) | Secrets manager (Key Vault, Secrets Manager, Vault) | Rotation, short TTL |
Example
@ConfigurationProperties("payments")
@RefreshScope // rebound when the config store publishes a change
public record PaymentSettings(URI providerUrl, Duration timeout, boolean newCheckoutEnabled) {}
// application.yml in the image holds only defaults; the store overrides per environment:
// spring.config.import: optional:configserver:http://config:8888
// Values are validated on load — an invalid URL is rejected instead of silently applied.Trade-offs
| Benefits | Costs | |
|---|---|---|
| Speed | Change behaviour in seconds without a build or deploy. | Changes skip the code-review and test pipeline unless you add one for config. |
| Consistency | One artefact for every environment; one source of truth. | Runtime refresh must be safe — not every setting can change on the fly. |
| Operations | Audit trail of who changed what and when. | Another critical service to secure and keep available. |
Production considerations
- Version configuration and review changes like code (GitOps or approval workflows).
- Validate values on load and reject changes that fail validation.
- Roll out risky flags gradually (per tenant or percentage) and keep a kill switch.
- Never log secrets; reference them by name in configuration and fetch them at runtime.