Why my business simulator replays every run bit for bit
说明与用途
Ventute 通过事件驱动架构、控制非确定性来源以及将核心循环移至 Rust 并通过 PyO3 接口,实现业务模拟的逐位确定性重放。
问题
Ensuring deterministic replay of a business simulation so that each run can be debugged and trusted.
结果
Ventute now achieves deterministic, bit‑for‑bit replay of simulations, enabling reliable debugging and trust, while leveraging Rust for performance and Python for ease of use.
工作流
- Store every action as an event rather than saving state directly.
- Rebuild state by folding the event log from the beginning.
- Control sources of nondeterminism: wall clock time, randomness, iteration order, floating point.
- Move the hot simulation loop into Rust and expose it via PyO3.
- Run simulations on real threads in parallel while keeping the API async in Python with FastAPI.
- Use PostgreSQL (Neon) for storage and Redis for caching.
- Ensure every run produces the same answer regardless of thread completion order.
证据
Every action in Ventute is stored as an event. The state of a company is never saved directly. It is rebuilt by folding the event log from the beginning.
The hard part is making that true every single time. Wall clock time, randomness, iteration order and floating point all love to break replay quietly.
I moved the hot loop into Rust and call it through PyO3, so the simulations run on real threads in parallel while the API stays in async Python with FastAPI.
Three patterns from Ventute turned out to be useful on their own, so I published them on GitHub under m4xkushnir.
- 记录日期: 2026-10-17T15:41:20.860Z