moonpool ~
GitHub →
$ the sim book

The Sim Book

A guide to building and testing distributed systems with moonpool, a deterministic simulation framework for Rust.

Moonpool takes ideas from FoundationDB, TigerBeetle and Antithesis and puts them in one set of Rust crates. You write your system once against provider traits. In production the traits are backed by TokioProviders: real TCP, a real disk, a real clock. In tests the same code runs inside a simulator that is deliberately worse than production: partitions, torn writes, slow machines, reboots, all driven by one seed. No #[cfg(test)]. No mocks. No Sim* copies of your types.

The book has six parts and an appendix:

  • Part I explains why simulation testing exists and what moonpool offers. You can read it without any code.
  • Part II covers the foundations: determinism, the provider pattern, and the split between the system under test and the test driver.
  • Part III builds a simulation step by step: processes, workloads, the SimulationBuilder, chaos, assertions, events, metrics and debugging.
  • Part IV wires existing applications (axum, tonic, hyper) into the simulator and takes the same code to production and to the browser.
  • Part V covers the raw network layer and the typed RPC crate built on it.
  • Part VI covers multiverse exploration and the crash-aware journal built on top of the simulator.
  • The Appendix holds the reference tables: assertions, crates, configuration, faults, the calibration tool and the xtask runner.

If you are new, start with The Case for Simulation. If you already know why you want simulation, jump to Why Moonpool Exists for the feature tour, then to Your First Simulation. AI agents working on a moonpool codebase should read the Guide for AI Agents.

Index

This page is a map of the book. Each entry links to one chapter and says what it covers.

Quick Start Routes

Question Start here
I am a coding agent and I must add a simulation harness Guide for AI Agents
What is moonpool? The Case for Simulation, then Why Moonpool Exists
What is new in moonpool? State of Moonpool
How do I write my first simulation? Your First Simulation
How can one code base run in production and in simulation? Same Code in Production and Simulation
How do providers work? The Provider Pattern
How do I add faults? Chaos in Moonpool
How does my code mark a place where a fault is interesting? hint!: Naming Fault Sites and Buggify
How do I get a different fault mix on each seed? Swarm Testing: Masks and Budgets
How do I simulate slow machines and gray failures? CPU Time and Gray Failures
How do I take down a whole rack? Correlated Outages and Self-Crashes
How do I use assertions? Assertions: Finding Bugs
A seed failed. What now? Debugging a Failing Seed
How do I test an existing app (axum, tonic, hyper)? Using moonpool-sim Standalone
How do I ship this to production? Using Providers in Production
How do processes call each other? Typed RPC with moonpool-rpc
I need a durable log A Crash-Aware Journal
How does multiverse exploration work? Multiverse Exploration
Which knobs exist and what are their defaults? Configuration Reference and Fault Reference

Foreword

Part I: Why Simulation Testing

Part II: Foundations

Part III: Building Simulations

Part IV: Simulating Existing Applications

Part V: Raw Network Simulation

Part VI: Building on Top

Appendix