Scientist — A Library For Refactoring Critical Paths

How Scientist Works — Credits to Ioana Iordachi

Example

I created a small project in Java where I mimic a database which retrieves data and returns us a Product.

Scenario

I retrieve a product based on its ID. We want to retrieve products using 2 code paths (V1 and V2).

Setup Scientist

Since we’re using Java we can use the Java wrapper of Scientist — Scientist4J.

<dependency>
<groupId>com.github.rawls238</groupId>
<artifactId>Scientist4JCore</artifactId>
<version>0.4</version>
</dependency>
Experiment<Product> experiment = new Experiment<>("product", true);
Supplier<Product> currentCodePath = () -> productRest.getProductsV1(1);
Supplier<Product> newCodePath = () -> productRest.getProductsV2(1);

Product experimentResult = experiment.runAsync(currentCodePath, newCodePath);

Metrics

All we care about at this stage are the metrics. These give us insight about the results of the new code path. This way we can check if it is working according to our expectations (meaning the new code path gives us the exact same result as the existing one).I created a unit test where I run these seperate code paths a 100 times.

Code Examples

The full unit test (which mimics the behavior of a client calling an endpoint a 100 times)

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store