RepositoryRust
MA

madsim-rs/madsim

Magical Deterministic Simulator for distributed systems in Rust.

1.2kstars
76forks
28issues
0views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: deterministic

#1 Repository of the week

1
TINIX TRENDING·Topic: deterministic

#1 Repository of the week

1
TINIX TRENDING·Topic: deterministic

#1 Repository of the week

MadSim

Crate Docs CI

Magical Deterministic Simulator for distributed systems.

Deterministic Simulation Testing

MadSim is a Rust async runtime similar to tokio, but with a key feature called deterministic simulation.

The main idea is borrowed from FoundationDB and sled simulation guide. Your code should be able to deterministically execute on top of a simulator. The simulator will amplify randomness, create chaos and inject failures into your system. A lot of hidden bugs may be revealed, which you can then deterministically reproduce until they are fixed. If your system can survive such chaos, you will have more confidence in deploying your system in the real world.

However, implementing deterministic simulation is difficult. All I/O-related interfaces must be mocked during the simulation, and all uncertainties should be eliminated. This project is created to make that easy.

A part of the implementation of this crate is inspired by tokio-rs/simulation.

See also the blog posts for a detailed writeup:

Usage

Add the following lines to your Cargo.toml:

[dependencies]
madsim = "0.2"

If your project depends on the following crates, replace them by our simulators:

[dependencies]
tokio = { version = "0.2", package = "madsim-tokio" }
tonic = { version = "0.5", package = "madsim-tonic" }
etcd-client = { version = "0.4", package = "madsim-etcd-client" }
rdkafka = { version = "0.3", package = "madsim-rdkafka" }
aws-sdk-s3 = { version = "0.5", package = "madsim-aws-sdk-s3" }

[dev-dependencies]
tonic-build = { version = "0.5", package = "madsim-tonic-build" }

If your dependency graph includes the following crates, replace them by our patched version:

[patch.crates-io]
quanta = { git = "https://github.com/madsim-rs/quanta.git", rev = "948bdc3" }
getrandom = { git = "https://github.com/madsim-rs/getrandom.git", rev = "8daf97e" }
tokio-retry = { git = "https://github.com/madsim-rs/rust-tokio-retry.git", rev = "95e2fd3" }
tokio-postgres = { git = "https://github.com/madsim-rs/rust-postgres.git", rev = "4538cd6" }
tokio-stream = { git = "https://github.com/madsim-rs/tokio.git", rev = "ab251ad" }

When built normally, these crates are identical to the original ones.

To run your code on the simulator, enable the config madsim:

RUSTFLAGS="--cfg madsim" cargo test

Now you have gotten rid of tokio/tonic and you are in the simulation world!

We provide a set of APIs to control the simulator. You can use them to kill a process, disconnect the network, inject failures, etc. Check out the documentation and search for the madsim feature to learn more usages.

Projects

  • MadRaft: The labs of Raft consensus algorithm derived from MIT 6.824 and PingCAP Talent Plan.
  • RisingWave: A distributed SQL database for stream processing that uses MadSim for deterministic testing.

License

Apache License 2.0

Similar Projects

Discover other similar projects and AI models.

RepositoryRust
spacedriveapp/spacedrive

Spacedrive is an open source cross-platform file explorer, powered by a virtual distributed filesystem written in Rust.

39.6k
Nov 25, 2026
RepositoryRust
pingcap/talent-plan

open source training courses about distributed database and distributed systems

11.1k
Nov 2, 2026
RepositoryRust
MaterializeInc/materialize

The live data layer for apps and AI agents. Create up-to-the-second views into your business, just using SQL

6.4k
Nov 27, 2026
RepositoryRust
paradigmxyz/reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust

5.9k
Nov 30, 2026
RepositoryRust
sweetpad-dev/sweetpad

xcodebuild for humans and agents: build, run, debug, and test iOS, macOS, tvOS, watchOS, and visionOS apps from your terminal.

1.9k
Dec 2, 2026
RepositoryRust
ThousandBirdsInc/chidori

The agent framework where every run is durable, replayable, and resumable by default.

1.4k
Nov 16, 2026
RepositoryRust
obeli-sk/obelisk

Durable & Deterministic Workflow Runtime

769
Nov 26, 2026
RepositoryRust
logannye/rosalind

Reusable genomic evidence for research and analysis tools: exact read evidence, portable datasets, and managed analyzers.

280
Oct 25, 2026
RepositoryRust
fzakaria/rewindvm

Deterministic Linux VMs you can scrub, rewind and fork. Find and replay flaky builds and tests.

244
Nov 29, 2026