Desired State Systems

concept
desired-statedeclarativereconciliationcontrol-theory

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

  1. User declares desired state
  2. System observes actual state
  3. System diffs desired vs. actual
  4. 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):

  1. Declarative over imperative — user states what, system figures out how
  2. Stateless over stateful — user need not track current state; simpler reasoning, testability, concurrency
  3. 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

SystemLoopUnderlying API
NixOSclosedOS packages and config (xettel)
Reactopenbrowser DOM
Terraformclosedcloud infrastructure
Kubernetesclosed, continuouscontainer orchestration (xettel)
GitOps for device fleetsclosedphysical 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).

Sources