Skip to content
Design7 min readUpdated 3 Nov 2026

Shadow

Shadow has two jobs. It gives developers and agents a place to work that looks like production, built from a sanitized copy of production data that keeps moving forward. And it gives them a repeatable way to check a change: run the current build and the candidate from the same starting state, with the same inputs, and compare what each did. Keeping the two jobs apart matters, because a world that keeps moving cannot also be the fixed starting point of an experiment.

Shadow is a design. The pieces it builds on exist: separate dev and prod configuration, seeding and provisioning steps, graph and Service instrumentation, trace propagation and nightly backups. Publishing bases, the workspace lifecycle and the comparator are not built. Capture and replay is the build design for recording operations and running them again.

Shadow's design. A trusted materializer reads approved production data, sanitizes it under a versioned policy and publishes immutable base revisions. A developer or agent forks a workspace from a base. A verification run pins one base and runs the baseline and the candidate from the same state with the same inputs, with one effect policy per operation, then three checks give one result. None of it is built yet.BASESProduction dataapproved stores onlyTrusted materializerreads, sanitizes under a versionedpolicy, and validatesImmutable base revisionsr41 · r42 · r43shadow-current names the latestaccepted baseA design: publishing bases, workspacesand the comparator are not built.WORKSPACES AND RUNSWorkspaceforked from one base: isolated, writableresources with their own credentials,lease and expiryVerification runpins one base until it ends, and runs bothbuilds from the same state with the sameadmitted inputsbaseline buildcandidate buildBuilds are named by content hash,so uncommitted changes count too.forkpinCHECKSOne effect policy per operationREAL_SHADOWRECORDEDSIMULATEDDENYAPPROVED_SANDBOXThree checkscontract assertionsbaseline against candidateproduction evidenceOne resultpassed, assertion failed, policy blocked,capture incomplete, provisioning failedor measurement failed
A moving copy of production to work in, and fixed starting points to compare a baseline and a candidate; the two jobs stay apart.

Bases, workspaces and runs#

  • Base. A trusted materializer reads approved production data, sanitizes it under a versioned policy, validates it and publishes an immutable base revision. shadow-current names the latest accepted base.
  • Workspace. A developer or agent forks one base into isolated, writable resources with its own credentials, lease and expiry. There are two trust tiers, dev and prod, and a workspace is a dev instance, not a third environment.
  • Run. A verification run pins one base until it ends. Exploratory work can refresh from a newer base; a run cannot.

A run fixes everything that decides its result:

(next_state, observations, effect_intents)
    = Run(artifacts, initial_state, admitted_inputs; dependency_policy, nondeterminism_control)

Artifacts are every build involved: client, services, framework, configuration and migrations, identified by content hash, because a Git commit does not capture uncommitted changes. Initial state covers every store that takes part. Dependency policy says which effects really happen. Nondeterminism control says which clocks, random values and orderings are recorded or simulated.

To compare two builds, fork both from the same base, give them the same input, and keep the next base publication outside both runs. Yesterday's traffic replayed against today's base is a production-shaped test, not a reproduction of yesterday: reproducing a past failure needs the past state or a recording of the boundary.

Three ways to run#

ProfileState and dependenciesWhat a pass means
Live ShadowReal isolated stores and approved sandbox dependenciesThe change works in a production-shaped world
Controlled replayA pinned base or recorded boundaries, fixed inputs and controlled orderingThe result repeats, within the stated fidelity
Performance and faultsReal dependencies at representative capacity, with injected faultsThe system holds its targets and recovers, for this topology and workload

Where effects stay real#

Every operation in a run gets exactly one policy, chosen before the run starts:

PolicyEffect
REAL_SHADOWRuns against a verified, isolated workspace resource
RECORDEDReturns the recorded result of a matching operation
SIMULATEDRuns a named, versioned model with stated limits
DENYBlocks the effect and reports it
APPROVED_SANDBOXRuns against an external sandbox that was explicitly approved

Several layers may observe the same call, but only one substitutes its result. A call with no matching record fails the run; it never falls through to a real dependency. Safety comes from the workspace's authority, not from the HTTP method: an isolated insert can be safe, while an idempotent write to production is never within a dev workspace's rights. Recorded model answers test orchestration, not model quality.

Isolating each store#

StoreHow a workspace gets its own copyWatch out for
PostgresA real restore or clone, or an isolated database with all required stateAn overlay schema with search_path does not merge base rows; sequences, constraints, grants and row-level security need explicit handling
R2Immutable base objects plus the workspace's own writes and deletionsNever read through to production on a miss
D1 and KVSeparate seeded resourcesAn empty local store is not the base
Durable ObjectsAn isolated namespace, with stored state exported and restored by the applicationMemory, live sockets and pending alarms cannot be cloned
Queues and workflowsWorkspace-owned names and IDsEither run the producer or inject its recorded event, never both
Memgraph and ClickHouseAn isolated instance or a verified access scopeRebuilding a projection does not test its original ingestion
ClientsSeeded local database, cache and pending work, with fresh workspace sessionsNever copy production refresh tokens, device keys or notification destinations

A shared dev resource can be fine for functional work, but it cannot support a claim about uncontended performance.

Publishing a base#

Only the materializer may read production. It publishes in five steps:

  1. Take a consistent snapshot of each source and note its position.
  2. Transform it under the privacy and schema policy into a staging base.
  3. Where change data capture is used, apply committed changes up to a later position, saving progress together with the applied changes.
  4. Validate integrity, relationships, schema, policy and checkpoint completeness.
  5. Publish the base and move shadow-current to it in one step, keeping the previous base if anything failed.

Start with snapshots; add change data capture only when freshness really requires it, because logical replication does not copy DDL or sequences and a lagging slot retains WAL. A base across several stores is a vector of source positions, not one global transaction. Deletions survive rebuilds, so an old snapshot can never bring back removed data, and a changed sanitization policy creates a new base.

Checking a change#

Three checks work together:

CheckPurpose
Contract assertionsStored state, authorization, invariants, visible output and approved effects meet the requirement
Baseline against candidateThe same state and input reveal regressions, or confirm an approved change
Production evidenceCaptured behaviour adds realism and known edge cases

Production can contain a bug, so matching the baseline is never enough on its own. Comparators may ignore only fields declared nondeterministic; they never hide ordering, authorization or duplicate effects. A result is one of passed, assertion failed, policy blocked, capture incomplete, provisioning failed or measurement failed. A denied dependency that did nothing is not a pass, and neither is a missing trace.

Existing tools keep their roles: Kotlin tests, Karate, Playwright, Maestro, k6 and Worker runtime tests each cover their own layer, and Shadow supplies the state, inputs and comparison around them.

Example: send, retry, reconnect#

One base holds two fresh workspace users, a conversation and some history. Baseline and candidate each get writable copies. The run covers sending a message, storing it, delivering it in real time and creating a push intent; real push delivery is denied.

  1. Send one message with idempotency key k.
  2. Let the database commit it.
  3. Lose the acknowledgement after the commit.
  4. Reconnect and retry the same send with k.
  5. Read the stored state, the real-time output and the push intent, without injecting the downstream event a second time.

The assertions: one stored message, one stable message ID, one visible message, and no effect outside the workspace. A build that stores two rows fails; the fixed build stores one. The failure is kept as a capsule: build, base and assertion versions, the workload and key, where the fault was injected, the causal journal, the state difference and trace references. The capsule rebuilds the starting state and reproduces the failed assertion, so it can become a regression test.

Clients and live updates#

A user journey goes from an action through local and graph state, backend effects and delivery to what is drawn on screen, so backend replay alone is not enough. Client runs pin the client and service builds, the device and its seeded local data, and cover offline sends, restarts, reconnects, stale caches, denied permissions and notification taps. Android, iOS, web and desktop are checked separately; the same semantics do not mean the same timing.

A clean start does not test an update. To verify a live update, start work on the old revision, update, and check state migration, new admissions, stale callbacks and draining. Rollback has to handle migrated data, not only old code.

Agents#

An agent proposes a change, selects the graph scopes it affects and runs the same tasks a person would. Unknown dynamic paths, shared schemas, auth, configuration and serialization widen the scope; the absence of observed traffic does not prove there is no dependency. A fast corpus runs while editing, larger journeys at checkpoints, and full release profiles before a release.

Acceptance belongs to the product requirement and its approved assertions. A candidate cannot pass by re-recording mocks, weakening a comparator, changing expected output or deleting a failing capsule; changing the oracle is a separate, reviewed action. Recorded content is untrusted input, including text later shown to an agent, and can never authorize commands or change acceptance rules. Agents work through Conductor and the workspace kernel, not through a second runner.

Privacy#

Classify fields before anything is exported, and keep only what a test needs. Transforms must preserve the equality, relationships and formats a test depends on; hashing a value does not anonymize a person. Workspaces get fresh credentials. Capsules carry an access scope, a policy version and a retention period: pinning a capsule keeps a useful case within policy, not forever, and deletion requests reach bases, raw artifacts, catalogs and old snapshots.