← Back to System Design, page 3

system-design-0050 · Medium mid

Design a distributed configuration management service that pushes configuration and feature flags to 50,000 service instances.

Keep versioned configuration in a strongly consistent store with validation, audit history and approval for changes. Distribute it through a read-only fan-out tier that clients watch with long polling, so changes reach instances within seconds, and have each client cache the last known good version on disk so instances still start if the service is down. Roll out risky changes gradually and roll back by version.

Full answer

Requirements

Functional:

  • Store key-value configuration and feature flags per service and environment (dev, staging, prod).
  • Every change is versioned, validated against a schema, attributed to a person, and can be rolled back.
  • Instances receive changes without redeploying; gradual rollout (1%, 10%, 100%) and targeting rules for flags.

Non-functional:

  • Changes reach all instances within about 10 seconds.
  • Reads must keep working if the config service is down: an outage of the config system must not stop the applications.
  • Strong consistency for writes (no lost updates); reads may be briefly behind.

Capacity estimates

Assumptions: 50,000 instances; 10,000 config keys averaging 2 KB; each instance subscribes to its own service's config, about 100 keys or 200 KB; about 500 changes per day.

  • Total config data: 10,000 x 2 KB = 20 MB. Tiny; it fits in memory on every config server.
  • Polling every 30 s would be 50,000 / 30 = about 1,700 requests per second, mostly returning "no change".
  • Long-poll watches instead: 50,000 open connections spread across, say, 10 fan-out servers is 5,000 connections each.
  • Change fan-out: one change to a shared key used by all instances means 50,000 notifications x 2 KB = 100 MB of traffic, fine if spread over a few seconds.

The scaling problem is fan-out and connection count, not storage.

API

PUT /v1/configs/{service}/{env}/{key} {"value": ..., "expected_version": 41, "comment": "raise timeout"} -> 200 {"version": 42} or 409 if someone else changed it first GET /v1/configs/{service}/{env}?since_version=41&wait_s=30 long-poll, returns changes or 304 POST /v1/configs/{service}/{env}/rollback {"to_version": 40} GET /v1/configs/{service}/{env}/history

Data model

  • config_entries: service, env, key, value, version, schema_id.
  • config_versions: append-only history with version, full diff, author, approved_by, comment, created_at (the audit trail).
  • flags: flag_key, rules (targeting by region, plan, user ID hash), rollout_percentage.
  • Secrets are not stored here; configs hold references to a secrets manager.

High-level design

mermaid
flowchart LR
  ADM[Admin UI / CLI / Git] --> API[Config write API: validate, approve]
  API --> DB[(Consistent store: etcd or PostgreSQL)]
  DB --> CH[Change stream]
  CH --> FO1[Fan-out server]
  CH --> FO2[Fan-out server]
  FO1 --> I1[Instance SDK + disk cache]
  FO2 --> I2[Instance SDK + disk cache]

How it works

  1. A change goes through the write API: schema validation (type, ranges), optional approval for production, and an optimistic concurrency check on expected_version.
  2. The store commits the new version; the change stream notifies fan-out servers, which keep the full current config in memory.
  3. Each instance's SDK holds a long-poll with its current version. When the version moves, it receives the changed keys, applies them atomically in memory, and writes them to a local disk cache.
  4. On startup, the SDK loads the disk cache first, then syncs. If the service is unreachable, the instance runs with the last known good config.

Safe rollout

Bad config is a common cause of outages, so treat config like code:

  • Validate before saving; reject a timeout of "30s" where an integer is expected.
  • Roll out progressively: a canary group of instances or a percentage gets the new version, health metrics are compared, then it widens.
  • One-click rollback to any previous version.
  • Feature flags evaluate locally in the SDK (a hash of user ID decides the rollout bucket), so evaluation adds no network call.

Bottlenecks and trade-offs

  • Push vs pull: long-poll or streaming gives seconds of latency with few wasted requests; plain polling is simpler but slower and wasteful. Push-based systems need connection management.
  • Consistency across instances: during rollout, instances run different versions for a short time; code must tolerate both old and new values.
  • Central store choice: etcd or ZooKeeper give watches natively but are not designed for tens of thousands of direct watchers with large values; the fan-out tier protects them.
  • Git-based config (config as code, changes through pull requests) adds review and history for free, at the cost of slower emergency changes; many teams combine Git for structure with a fast path for flags.

By level

Fresher: Explain storing settings centrally, versioning each change, and services picking up changes without redeploying. A fresher should explain why every change needs a version number.

Mid: Design versioned storage, watches through long polling, client caching, validation and rollback, and estimate connection and request load. Expect the polling versus watch arithmetic.

Senior: Cover progressive rollout with health checks, feature flag evaluation, multi-region replication, protecting the consensus store with a fan-out tier, secrets separation, and change governance. The senior answer makes sure a config outage cannot stop the applications.

Key points

  • Versioned, validated, audited writes with optimistic concurrency
  • Fan-out tier with long-poll watches; clients apply changes atomically
  • Clients cache last known good config on disk to survive outages
  • Progressive rollout and versioned rollback treat config like code
  • Data is tiny; fan-out and connection count are the scaling problem

Common mistakes

  • Making application startup depend on the config service being up
  • Storing secrets in plain configuration
  • Pushing changes to all instances at once without validation or canary
  • Polling every second from 50,000 instances

Follow-ups

  • How would you roll back a bad config within a minute?
  • How do you evaluate a feature flag for 5% of users consistently?
  • How would you keep configs in sync across three regions?

Tips

  • State that config outages must not cause app outages
  • Do the polling versus watch arithmetic
  • Mention validation and canary rollout as safety features

Evaluation rubric

  • Requirements cover versioning, audit, rollout and failure behaviour
  • Capacity math identifies fan-out as the challenge
  • Write path, distribution and client caching designed
  • Rollout safety and trade-offs discussed