State & ArchitectureBaseline · Widely

Deterministic Command Logs & Time-Travel Debugging

Mental Model

In-place state mutations erase the causal history that triggered a UI bug, making production corruption irreproducible. Recording every user intent as a serializable command in an append-only log enables deterministic replay, Undo/Redo, and bug-report time-travel debugging.

Interactive Simulator

Deterministic Command Log & Time-Travel Replay

Trace how pure commands append to an immutable log and replay deterministically to any cursor index.

Command Log [0..2]
Checkpoint @0
Derived State (2 items)
Step 1 / 3: 1. Capture Pure Command

Timestamp and UUID are computed at dispatch time so the command object is 100% deterministic.

log.push({ seq: 2, type: 'ADD_ITEM', id: 'itm_9', ts: 1731770002 });
Internal State / Memory
logLength
3
cursor
2
itemCount
2

Under the Hood

Event sourcing treats current UI state as a pure left-fold (reduce) over an ordered log of immutable commands starting from initialState. Replaying the exact sequence on another machine produces bit-identical state only if reducers remain deterministic.

  1. Pure command objects: Serialize { type, payload, timestamp, seq } without class instances, functions, or DOM nodes.
  2. Deterministic reducers: Read Date.now() or crypto.randomUUID() at command creation time, never inside the reducer, so replay never diverges.
  3. Checkpoint snapshots: Pair the log with periodic CRDT or structural-sharing checkpoints every $N$ commands so scrubbing to index 10,000 skips replaying from zero.
TS
type Cmd = { type: 'ADD'; delta: number } | { type: 'SET'; value: number };

function replay(commands: Cmd[], targetIndex: number, initial = 0): number {
  let state = initial;
  for (let i = 0; i <= targetIndex; i++) {
    const cmd = commands[i];
    state = cmd.type === 'ADD' ? state + cmd.delta : cmd.value;
  }
  return state;
}

Problem Genealogy

  • 2014–2016 (Elm Architecture & Redux DevTools): Introduced time-travel debugging by keeping actions pure and serializable, though storing unbounded action histories leaked hundreds of megabytes in long sessions.
  • 2018+ (Design Tools & Multiplayer Editors): Combined bounded command logs with periodic snapshots and inverse patches for sub-millisecond scrubbing.

Production Pitfalls

Production Pitfall
  • Browser tab hits 2 GB OOM after 4 hours in a canvas editor: Retaining every mouse-move command and full-document snapshot in memory leaks unbounded heap; coalesce continuous gestures and cap log length with periodic checkpoints.
  • Time-travel replay produces different state than live session: Calling Math.random() or reading window.innerWidth inside the reducer breaks determinism on replay.
When Not to Use
  • When not to use client event sourcing: For simple CRUD forms, ephemeral hover/scroll UI, or high-frequency 120 Hz pointer streams without coalescing, storing an append-only command log wastes heap memory and CPU on replay.

Connections & Logical Next Steps

State & ArchitectureDeterministic Command Logs & Time-Travel Debugging
What This Unlocks
Leaf concept