Replace a slow database query with a new one and verify both return the same data under real traffic before switching over.
Rewrite an authentication method and confirm the new version matches the old one on a percentage of live requests.
Instrument two versions of a pricing calculation to catch any edge-case differences before fully deploying the new logic.
Gradually roll out a refactored API endpoint by running the new code on 10% of traffic and monitoring for mismatches.
Requires adding the 'scientist' gem to your Gemfile and implementing a custom Publisher class to record results.
Scientist is a Ruby library that helps developers safely replace or rewrite parts of their application without risking breakage for real users. The core idea is that you wrap your existing code in a "control" block and your new replacement code in a "candidate" block. When a user triggers that code path, the library runs the old code as normal and returns its result to the user, but it also quietly runs the new code in the background, compares the two results, and records whether they matched. This approach lets you test new code under real production conditions without affecting anyone's experience. If the new code produces different results, you find out through your monitoring and logging tools rather than through user complaints. The library records timing data for both paths, captures any exceptions that occur in the candidate block (without letting them reach users), and lets you publish the comparison results wherever you want, such as a metrics service or a database. You can control how often the candidate code actually runs, which is useful when starting out and wanting to test only a small percentage of traffic. You can also define rules for ignoring certain known mismatches, specify custom comparison logic when the default equality check is not appropriate, and clean up the recorded values to strip out details you do not need to store. The library is designed specifically for read-only code paths, meaning places in your application that look up and return data rather than writing or changing data. The README includes guidance on how to handle situations involving data writes safely. Scientist was created by GitHub and is available as a Ruby gem. Ports of the same concept exist in many other programming languages including Python, Java, Go, JavaScript, and others, each listed in the README.
← github on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.