Below is a reference design for a “config-as-data” system where configuration is treated like an API: strongly typed, validated, safely rolled out, and fully auditable.
1) Core principles / requirements
Typed + schema-governed : every config document conforms to a versioned schema.
Safe change lifecycle : propose → validate → approve → rollout (progressive) → monitor → finalize/rollback.
Separation of control-plane and data-plane : authoring/validation vs fast distribution.
Immutability + traceability : configs are versioned; audit logs are append-only and tamper-evident.
Deterministic evaluation : overrides/merges and constraints produce a single effective config for a given target.
2) Data model
2.1 Entities
Schema
schema_id (e.g., payments-routing)
schema_version (semver, e.g., 2.1.0)
definition (JSON Schema / protobuf / CUE / etc.)
compatibility_policy (backward/forward rules)
deprecation metadata
Config document
config_id (stable name, e.g., payments-routing/default)
schema_id, schema_version
spec (the actual config payload)
metadata (owner, description, labels)
Release
Immutable snapshot of one or more config documents
release_id (monotonic or UUID)
created_by, created_at
change_summary, links to tickets
status (draft/validated/approved/rolling_out/completed/rolled_back)
Target / Scope
Hierarchy: global -> org -> env -> region -> cluster -> service -> instance
A request for config resolves via precedence rules + merges (e.g., global defaults overridden by env/service)
2.2 Versioning strategy
Config docs are immutable per version (content-addressed hash recommended).
New edits produce a new version; “current” is a pointer per scope/target.
Prefer schema evolution with compatibility checks:
Backward compatible: adding optional fields, widening enums carefully, etc.
Breaking changes require major version + migration plan.
3) Schemas
3.1 Choices
JSON Schema : good for JSON/YAML configs, UI forms, server-side validation.
Protobuf : strong typing, codegen, good for binary/stream distribution.
CUE : powerful constraints/templating; can output JSON; strong validation.
(Often: JSON Schema for authoring + protobuf/typed structs in services.)
3.2 Schema features you want
Required/optional, bounds, regex, enums
Cross-field constraints (e.g., min <= max)
Default values (careful: define where defaults are applied—server vs client)
Schema metadata: owners, SLO impact tags, “risky field” labels for rollout policy
3.3 Example (abridged JSON Schema)
json Copy code
{
"$id": "schemas/payments-routing/2.1.0",
"type": "object",
"required": ["strategy", "routes"],
"properties": {
"strategy": { "enum": ["weighted", "failover"] },
"routes": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["provider", "weight"],
"properties": {
"provider": { "enum": ["adyen", "stripe"] },
"weight": { "type": "integer", "minimum": 0, "maximum": 100 }
}
}
}
}
}
4) Validation pipeline (multi-layer)
Validation should be staged, fast-to-slow, and reproducible.
4.1 Static validation (always)
Schema validation : structure and types.
Semantic validation (business rules):
Use CEL/OPA/Rego/custom validators.
Example: weights must sum to 100 when strategy=weighted.
Compatibility validation
New schema version compatible with previous (if required).
New config version compatible with currently deployed readers (clients).
4.2 “Contextual” validation (target-aware)
Validate against the effective config for a target after merge/overrides.
Ensure required fields are satisfied post-merge.
Enforce environment-specific constraints (prod stricter than dev).
4.3 Runtime safety checks (pre-rollout)
Dry-run evaluation : compile/render templates, resolve references (secrets, IDs).
Dependency checks : referenced resources exist (queues, topics, accounts).
Policy checks (OPA):
“Prod changes require 2 approvals”
“Risky fields require canary”
“No changes during freeze window”
4.4 Testing hooks (high leverage)
Golden tests : fixed inputs → expected effective config outputs.
Simulation : run config through a service-specific validator binary/container.
Replay : validate against a sample of production targets (e.g., top 50 clusters).
5) Rollout safety / delivery
5.1 Control plane vs data plane
Control plane (authoring, validation, approvals, release orchestration)
Data plane (fast read path for clients; caches; edge distribution; agents)
5.2 Release mechanics
Releases are immutable snapshots.
A rollout assigns release_id to targets progressively.
5.3 Progressive delivery patterns
Pick one (or support multiple):
Canary by target slice : 1% instances → 10% → 50% → 100%
Ring-based : dev → staging → small prod ring → full prod
Region-by-region : with hold points between regions
Feature-flag hybrid : config shipped everywhere but activated per cohort
5.4 Health gates + auto-rollback
Define per-config “impact metrics” (service error rate, latency, business KPIs).
Rollout controller watches metrics during each step.
If guardrails breached:
Stop rollout
Auto-rollback pointer to previous release
Emit incident/audit events
5.5 Client update model
Push (preferred for fast rollback): long poll / streaming / pubsub
Pull : clients poll with ETag/If-None-Match
Always include:
release_id, config_version, schema_version
TTL / refresh interval
Signature (see security)
5.6 Consistency and blast radius controls
Atomic pointer flip per target set (transactional update).
Hard limits:
max rollout rate
max number of targets per step
require manual approval for “high risk” diffs
6) Audit logs (who/what/when/why) + tamper evidence
6.1 What to log (events)
Schema events: create/update/deprecate
Config events: create/update/archive
Validation results: pass/fail + validator version + messages
Approval events: who approved, policy satisfied
Release events: created, promoted, rolled out, paused, rolled back
Read events (optional, expensive): who/what accessed sensitive configs
Admin events: permission changes, key rotations, policy edits
6.2 Audit record shape (example)
event_id (UUID)
timestamp (UTC)
actor (user/service principal), auth_context (MFA, IP, device)
action (e.g., release.promote)
resource (schema/config/release id)
before_hash, after_hash (or full diff reference)
reason / ticket link
policy_decisions (OPA decision ID + inputs hash)
correlation_id (tie together PR/build/release)
signature / chain pointer
6.3 Tamper-evident storage
Write audit logs to an append-only store (e.g., WORM/S3 Object Lock, or an immutable log system).
Add hash chaining :
each record includes prev_hash; periodic checkpoints signed with KMS.
Strict retention and access controls (separate from config write permissions).
7) Security and access control
Strong authn: SSO + MFA for humans; mTLS/OIDC for services.
Authz: RBAC/ABAC (by schema/config scope + environment).
Separate roles: author, approver, releaser, auditor.
Secrets: don’t store plaintext secrets in config; store references to a secrets manager.
Sign distribution payloads (JWS) and/or serve via mTLS; verify client-side.
“Break glass” path: time-bound elevated access, heavily audited.
8) Operational concerns
High availability read path (data plane): caches, regional replicas, CDN if needed.
Low-latency evaluation : precompute effective configs per target or cache merge results.
Schema registry availability : clients may need schema for validation/debug; keep backward versions.
Migration tooling : auto-transformers between schema versions.
Diff UX : show semantic diffs (not just JSON text), highlight risky fields.
Backfill : when schema changes add new required fields, enforce defaults or migration.
9) Suggested architecture (concrete)
Storage:
Config versions + releases: Postgres (metadata) + object storage for blobs, or all-in Postgres with JSONB + hashes.
Audit log: append-only (WORM S3) + searchable index (e.g., OpenSearch).
Validation:
JSON Schema validator + CEL/OPA policy engine
Optional: service-provided “config validator” container run in CI
Delivery:
Config gateway (read API) + edge cache
Optional agents in clusters that watch for updates and write to local filesystem
Rollout controller:
Maintains rollout state machine, integrates with metrics (Prometheus, Datadog), supports auto-rollback.
10) End-to-end workflow (what “good” looks like)
Author change (UI/API/PR) → creates a draft release .
System runs validation suite (schema + semantic + policy + dry-run).
Approvals collected per policy (e.g., 2-person rule for prod).
Rollout controller deploys to canary ring; monitors guardrails.
Progressive rollout continues; on breach → automatic rollback + audit trail.
Completed release becomes “current”; all artifacts (diffs, decisions, approvals, metrics) remain queryable for audits.
If you share your constraints (number of services/targets, expected QPS for reads, whether configs are per-request or per-process, regulatory needs like SOX/HIPAA, and your preferred schema language), I can propose a more concrete component diagram and the exact data tables / APIs.