Day 30 — Durable Jobs and Artifacts
Today Mosaic survives process death.
Run the durability examples
Section titled “Run the durability examples”cd rust/rust-ai-engineeringcargo run -q -p mosaic-db --example transactional_runcargo run -q -p mosaic-db --example durable_jobcargo run -q -p mosaic-artifacts --example content_addressedCommit state and event together
Section titled “Commit state and event together”When a run changes state, persist the new state and corresponding event in one transaction. Otherwise a
crash can leave current state saying completed while replay has no terminal event—or the reverse.
Lease, do not merely dequeue
Section titled “Lease, do not merely dequeue”A worker claims a job until lease_expires_at, periodically renews, and completes with an ownership
token. If it dies, another worker may reclaim after expiry. Completion from a stale lease is rejected.
Idempotency keys bind logical operations to outcomes. They do not make every external API idempotent; for uncertain effects, reconcile target state before retry.
Store large data outside rows
Section titled “Store large data outside rows”Content-addressed artifacts use a digest as identity and store metadata in the database. Verify bytes on read, scope access by tenant, and retain relationships between original, normalized, derived, and model output artifacts.
Crash drill
Section titled “Crash drill”Inject failure:
- after job claim;
- after provider result but before event commit;
- after artifact write but before database link;
- during lease renewal;
- after external write returns an unknown outcome.
For each, state the recovery owner and whether replay, retry, garbage collection, or reconciliation is correct.
Completion proof
Section titled “Completion proof”Run the same logical request twice with one idempotency key, restart between attempts, and prove one durable run and one externally visible outcome.
Deep references: Durable jobs, SQLx transactions, and Databases and content addressing.