Scientist is a Ruby library for carefully refactoring critical paths by running experiments that compare old and new code behavior in production.
The library solves the problem of safely refactoring mission-critical code paths where tests alone cannot guarantee correctness under real-world load. It works by wrapping the original code in a control block and the refactored code in a candidate block. When an experiment runs, it executes both paths, measures their performance, compares their results, and publishes the findings—but always returns the control result to users, ensuring no impact from untested changes. The tool randomizes execution order to avoid timing bias and can swallow exceptions from the candidate block without affecting the application.
Teams should adopt this tool when refactoring code that handles sensitive operations like permissions, payment processing, or other business logic where behavioral correctness is critical and production validation is necessary. It suits large applications where the cost of bugs is high and where load testing in staging environments may not capture real-world conditions. The library is most valuable when you have infrastructure to collect and analyze experiment results, since the default behavior publishes observations that need to be captured by a custom implementation.
Development on the project shows consistent maintenance with regular updates to the test suite and dependencies. The codebase demonstrates attention to edge cases, including handling of expensive setup operations and customizable comparison logic for both values and errors. Documentation is thorough, with clear examples of context management, result cleaning for privacy, and integration patterns for different use cases.