Desired State Systems
A desired state system wraps a mutable, imperative interface with a declarative one. The user specifies what should be; the system observes actual state, computes the diff, and reconciles (Jenco).
Pattern
- User declares desired state
- System observes actual state
- System diffs desired vs. actual
- System reconciles — applies minimal changes to reach desired state
The reconciliation may run once (open-loop) or continuously (closed-loop). Applying the same desired state repeatedly always yields the same result — the operation is idempotent.
Three perspectives
The same abstraction can be viewed from different angles (Jenco):
- Declarative over imperative — user states what, system figures out how
- Stateless over stateful — user need not track current state; simpler reasoning, testability, concurrency
- Immutable over mutable (value over reference semantics) — state is treated as a value; if something changed, it is a new value
Properties of declarative interfaces
Stateless (user need not track state), less control (no direct manipulation), simplified concurrency (multiple actors without conflicts), optimization-friendly (system can reorder operations), encapsulated (complexity hidden) — Jenco.
Examples
| System | Loop | Underlying API |
|---|---|---|
| NixOS | closed | OS packages and config (xettel) |
| React | open | browser DOM |
| Terraform | closed | cloud infrastructure |
| Kubernetes | closed, continuous | container orchestration (xettel) |
| GitOps for device fleets | closed | physical devices (bib) |
Connection to control theory
Closed-loop desired state systems are feedback control systems. The controller pattern is the concrete implementation: watch, diff, reconcile. Relevant concepts: hysteresis (preventing oscillation), dead band (xettel), perpetual disequilibrium (the system never settles, and that’s fine).