Context
Pricing logic lived in two places: TypeScript services that serve the product, and Rust services that do heavy computation. Every formula change meant two implementations and a slow drift between them.
Approach
- Moved the formulas into a single Rust crate with a small, pure API.
- Rust services call it natively. TypeScript services call the same crate compiled to WebAssembly.
- Passed data across the WASM boundary as columnar typed arrays rather than per-row objects, which keeps the call cheap for large batches.
- Added a parity test that runs the same inputs through both consumers and fails if the outputs differ.
What I learned
Not everything belongs in WASM. Formulas that must run inside a MongoDB aggregation pipeline still have to be expressed in the pipeline language, so the crate is the source of truth for the logic, and the pipeline version is checked against it.