# Parallel Run: Compare Gen 1 and Gen 2 Outputs | gen2.dev

> A parallel run feeds Gen 1 and Gen 2 the same inputs and compares the outputs. How to set one up, what to compare, and when to trust the new system.

Source: https://gen2.dev/guide/parallel-run/

---

Field Guide

# Parallel run: trust Gen 1 until the differences are explained

Give both systems the same inputs, compare what comes out, and keep using the old answer until every difference has an explanation.

![Slide: the same requests go to Gen 1 and Gen 2, the answers are compared, and every difference is explained.](https://gen2.dev/img/parallel-run.png)

Nobody knows everything Gen 1 does. The specification, if there is one, is out of date. The tests cover what somebody thought of. The real definition of correct behavior is whatever the old system does with production inputs, including the cases nobody remembers adding.

A parallel run uses that fact. Both systems get the same inputs. Gen 1's answer is the one that counts. Gen 2's answer is recorded and compared. Gen 2 earns trust by agreeing with Gen 1, or by disagreeing for a reason somebody has written down.

## Three names for nearly the same thing

Term

What runs

What the user sees

Parallel run

Old and new, on the same inputs, results compared

The old result

Shadow traffic

A copy of live requests is sent to the new system

The old result; the copy's response is discarded or compared

Dark launch

New back-end behavior is called from real user activity

Nothing new

Martin Fowler defines the last one: "Dark launching a feature means taking a new or changed back-end behavior and calling it from existing users." Its usual purpose is to see how the new code behaves under real load before anyone depends on it. He also describes the comparing variant, in which "The old and new code can both be called and their results checked," while only one answer goes back to the interface.

Fowler notes that people use these terms loosely. What matters is which question is being asked. A dark launch asks whether Gen 2 can carry the load. A parallel run asks whether it gives the right answers. Most Gen 2 projects need both. How the copy of each request is made, and how to keep it from acting on the real world, is covered in [shadow traffic](https://gen2.dev/guide/shadow-traffic/).

## How it works

1.  **Pick the comparison point.** A function, an endpoint, a nightly batch, a report. It needs clear inputs and an output that can be compared.
2.  **Send the same input to both.** Call both in the same code path, or copy the request to Gen 2 on the side.
3.  **Return Gen 1's result.** Always. Gen 2 can be wrong, slow or down, and no user finds out.
4.  **Contain Gen 2's failures.** Exceptions and timeouts in the new path are caught and recorded. They never reach the caller.
5.  **Compare and record.** Log each mismatch with the input and both outputs. Record timings for both paths.
6.  **Explain every difference.** Each mismatch is one of three things: a bug in Gen 2, a bug in Gen 1, or a difference that is acceptable. Fix the first, decide what to do about the second, and write down the third.
7.  **Ramp up.** Start with a small share of traffic and increase it. The comparison costs something in production.
8.  **Set the exit condition before starting.** For example: no unexplained mismatches for two full business cycles. Then switch, and remove the comparison code.

## A real example: GitHub's Scientist

GitHub released Scientist 1.0 in February 2016. Its README describes it as "A Ruby library for carefully refactoring critical paths." The announcement names a multi-year rewrite of GitHub's permission code as one of the projects it was used on, and makes the case that tests are not enough for work like that: only production data shows how the code really behaves.

An experiment wraps two blocks. The existing code is the control. The new code is the candidate. According to the README and the announcement, a run then:

-   Returns the control's result to the caller, every time.
-   Decides whether to run the candidate at all, so an experiment can be enabled gradually.
-   Runs the two in random order, to avoid ordering effects.
-   Measures the duration of each.
-   Compares the two results.
-   Records exceptions raised by the candidate instead of raising them.
-   Publishes all of it. What happens next is left to the team; GitHub sent timings to its metrics system and stored mismatches for inspection.

It also comes with a blunt warning. The README says: "Scientist is only safe for wrapping methods that aren't changing data." The announcement adds: "we only use Scientist on read operations."

Stripe later used Scientist to check the read paths of a large data migration, comparing reads from the old table and the new one in production. That migration is covered in [dual write and data migration](https://gen2.dev/guide/dual-write/).

## The same idea for a whole service: Twitter's Diffy

Scientist compares two blocks of code inside one application. Diffy compares two running services from the outside. Its README says: "Diffy finds potential bugs in your service using running instances of your new code and your old code side by side." InfoQ reported on September 18, 2015 that Twitter had open sourced it.

Diffy is a proxy. It sends each request it receives to both versions and compares the responses. Its answer to the noise problem is a third instance. Two instances run the known-good code, called primary and secondary, and one runs the candidate. Differences between primary and secondary can only be noise, such as timestamps and random values. Differences between primary and candidate are compared against that baseline, and only what exceeds it is reported as a possible regression.

The repository was archived on July 2, 2020 and is no longer maintained by Twitter. The three-instance design is the part worth copying.

## The hard part is side effects

Running a read twice is harmless. Running a write twice is not. Two charges, two emails, two shipments.

There are three ways through:

-   **Compare only reads.** This is the Scientist rule, and it covers more than it seems to. Most business logic can be arranged as "work out what to do" followed by "do it."
-   **Compare the decision, not the action.** Have both systems calculate the invoice, the price or the permission. Compare the calculations. Only Gen 1 acts.
-   **Give Gen 2 somewhere safe to write.** Its own data store, with outbound email, payments and partner calls stubbed out. Then compare the resulting state at the end of the day.

The third is the classic parallel run for batch and financial systems. It is also the most expensive, because Gen 2's data has to start in step with Gen 1's and stay there.

## When not to use it

-   **Calls have side effects you cannot isolate.** Running twice would charge, send or write twice.
-   **Gen 2 is supposed to answer differently.** Every difference will be noise.
-   **Traffic is too low to exercise the paths that matter.** Recorded cases and tests tell you more.
-   **Doubling the load is not affordable.** Sample, or use [shadow traffic](https://gen2.dev/guide/shadow-traffic/) on a slice.

## Where it goes wrong

**Too much noise.** Timestamps, generated identifiers, ordering and rounding all produce mismatches that mean nothing. If nobody filters them, the report becomes unreadable and people stop looking. Normalize or ignore known differences, deliberately, one rule at a time. Diffy's second copy of the old code is a way to measure that noise instead of guessing at it.

**Mismatches that nobody owns.** A dashboard is not a process. Someone has to triage the differences every week, and the count has to trend toward zero.

**Fixing Gen 2 to match Gen 1's bugs without deciding to.** Sometimes the old behavior is wrong and other systems depend on it. Reproducing it can be the right call. It should be a recorded decision, not an accident.

**No end date.** A parallel run means paying for two systems. Without an exit condition it turns into [running two systems](https://gen2.dev/guide/running-two-systems/) for good.

**Comparing only the common cases.** Month-end, year-end, leap days and the one customer on the old contract show up on their own schedule. The run has to last long enough to meet them.

## How to tell it fits

A parallel run is worth the cost when the logic is complex and poorly documented, when a wrong answer is expensive, and when the outputs can be compared mechanically. Billing, permissions, pricing, tax, reporting and search ranking are typical.

It is a poor fit when the output is mostly side effects, when Gen 2 is meant to behave differently on purpose, or when the piece is so small that reading the code is faster.

## Checklist

-   Gen 1's result is always the one returned.
-   A failure in Gen 2 cannot reach a user.
-   Every mismatch is logged with enough detail to reproduce it.
-   Known, accepted differences are listed in writing.
-   Nothing with a side effect runs twice.
-   The exit condition was agreed before the run began.
-   The comparison code is deleted after the switch.

A parallel run is the evidence that makes [cutover](https://gen2.dev/guide/cutover/) a small step. It pairs naturally with a [strangler fig](https://gen2.dev/guide/strangler-fig/), slice by slice, and with [branch by abstraction](https://gen2.dev/guide/branch-by-abstraction/) inside a single codebase. Then read the [Digg v4 case file](https://gen2.dev/cases/digg-v4/) and ask what a few weeks of shadow traffic would have shown before launch day.

## Sources

1.  [Jesse Toth - Scientist: Measure Twice, Cut Once (GitHub Blog, February 3, 2016)](https://github.blog/developer-skills/application-development/scientist/)
2.  [github/scientist - README](https://github.com/github/scientist) - what an experiment does, and the warning about code that changes data
3.  [Martin Fowler - Dark Launching (April 29, 2020)](https://martinfowler.com/bliki/DarkLaunching.html)
4.  [Steve Smith - Application Pattern: Verify Branch By Abstraction (October 14, 2013)](https://www.stevesmith.tech/blog/application-pattern-verify-branch-by-abstraction/)
5.  [Jacqueline Xu - Online migrations at scale (Stripe, February 2, 2017)](https://stripe.com/blog/online-migrations) - Scientist used to verify read paths during a data migration
6.  [twitter-archive/diffy - README](https://github.com/twitter-archive/diffy) - what Diffy does, how it separates noise, and the July 2, 2020 archive notice
7.  [Abel Avram - InfoQ news report on Twitter open sourcing Diffy (September 18, 2015)](https://www.infoq.com/news/2015/09/twitter-diffy)

Last updated November 29, 2026.

## Field Guide

-   [Rewrite vs refactor](https://gen2.dev/guide/rewrite-vs-refactor/)
-   [The 7 Rs](https://gen2.dev/guide/seven-rs/)
-   [Characterization tests](https://gen2.dev/guide/characterization-tests/)
-   [Estimating a rewrite](https://gen2.dev/guide/estimating-a-rewrite/)
-   [Strangler fig pattern](https://gen2.dev/guide/strangler-fig/)
-   [Monolith to microservices](https://gen2.dev/guide/monolith-to-microservices/)
-   [Lift and shift](https://gen2.dev/guide/lift-and-shift/)
-   [Second-system effect](https://gen2.dev/guide/second-system-effect/)
-   [Branch by abstraction](https://gen2.dev/guide/branch-by-abstraction/)
-   [Anti-corruption layer](https://gen2.dev/guide/anti-corruption-layer/)
-   [Parallel run](https://gen2.dev/guide/parallel-run/)
-   [Shadow traffic](https://gen2.dev/guide/shadow-traffic/)
-   [Dual write and data migration](https://gen2.dev/guide/dual-write/)
-   [Expand and contract](https://gen2.dev/guide/expand-and-contract/)
-   [Data migration tools](https://gen2.dev/guide/data-migration-tools/)
-   [The cutover](https://gen2.dev/guide/cutover/)
-   [Feature flags and dark launches](https://gen2.dev/guide/feature-flags-and-dark-launches/)
-   [Big-bang cutover](https://gen2.dev/guide/big-bang-cutover/)
-   [API versioning](https://gen2.dev/guide/api-versioning/)
-   [Running two systems](https://gen2.dev/guide/running-two-systems/)
-   [Killing Gen 1](https://gen2.dev/guide/killing-gen-1/)
-   [Rewriting a mobile app](https://gen2.dev/guide/rewriting-a-mobile-app/)
-   [Selling a rewrite](https://gen2.dev/guide/selling-a-rewrite/)
-   [AI-written code](https://gen2.dev/guide/ai-written-code/)

## Should we rewrite it?

Sixteen questions about your system. A recommendation, and the reasoning behind it.

[Start the questions](https://gen2.dev/should-we-rewrite/)
