---
title: "Isolate state before running tests in parallel"
description: "Give concurrent tests independent databases, services, or fixtures so they can share runner capacity without interfering with each other."
url: https://starsling.dev/ci-playbooks/techniques/isolated-parallel-tests
canonicalUrl: https://starsling.dev/ci-playbooks/techniques/isolated-parallel-tests
---

# Isolate state before running tests in parallel

Give concurrent tests independent databases, services, or fixtures so they can share runner capacity without interfering with each other.

## How to choose an approach

Compare the examples by repository setup, prerequisites, and risks before adopting one. Each company implemented this in its own environment; measure each change against your own baseline.

- **[DoorDash](https://starsling.dev/ci-playbooks/doordash#parallel-e2e)**: Use it when A browser or desktop suite runs on one worker while its tests share no files, ports or processes. Check before adopting: Parallel journeys are safe when each owns its state; a shared file, port or install step becomes a race. Measure the worker count on your own runner.
- **[Ramp](https://starsling.dev/ci-playbooks/ramp#test-databases)**: Use it when Tests run in parallel workers against one shared database or service, and adding workers leaves the job's time flat while the database is saturated. Check before adopting: Every extra database uses CPU and memory the test workers would otherwise get; Ramp saw slight regressions past its measured ratio, so keep the count that measured fastest.
- **[Shopify](https://starsling.dev/ci-playbooks/shopify#isolate-before-parallel)**: Use it when Tests run one at a time because they share ports, temporary files, accounts or database state. Check before adopting: More workers add load on shared external APIs; keep teardown observable and keep genuinely serial tests on a serial lane.
- **[Stripe](https://starsling.dev/ci-playbooks/stripe#isolate-parallel-test-state)**: Use it when A shared database, port or remote account forces the whole suite to run serially. Check before adopting: Keep intentionally shared-state tests in a serial lane, keep teardown reliable, and use isolated sandbox accounts for remote services.
- **[Uber](https://starsling.dev/ci-playbooks/uber#isolate-test-services)**: Use it when Independent integration suites collide on one port, database or container name, forcing serial execution. Check before adopting: Use collision-proof namespaces and guaranteed cleanup after every run. Separate data and image tags as well as ports, and use a protocol-level readiness probe in place of a fixed startup sleep.

## Apply this technique

````text
Evaluate and apply this CI technique to my repository: Isolate state before running tests in parallel.

Give concurrent tests independent databases, services, or fixtures so they can share runner capacity without interfering with each other.

Read the technique and its source-backed company examples: https://starsling.dev/ci-playbooks/techniques/isolated-parallel-tests.md

Inspect this repository’s CI workflows, build and test commands, dependencies, and recent run timings. Identify where this technique applies and explain the expected benefit using this repository’s evidence.
Measure a baseline from recent comparable runs: elapsed time, queue time, runner minutes and failures where available. If data is unavailable, say what cannot be measured.
Compare relevant company approaches, checking prerequisites, platform differences and tradeoffs. Rank applicable options by evidence, fit and measurable opportunity; do not present company results as predictions for this repo.
Recommend the smallest safe change, show what checks and fallback paths remain, and ASK ME WHICH CHANGE TO APPROVE BEFORE EDITING ANY FILES.
Only after approval, work on a new feature branch, make one reversible change, and open a reviewable pull request. Never merge or push to a default or protected branch.
Keep required checks, test coverage, deployment and release behavior intact. Validate the change and compare equivalent runs where possible; report limitations and what should be monitored after merge.
````

## How companies used this technique

Read what each company changed and follow the original sources.

### DoorDash: Run isolated end-to-end journeys in parallel

The packaged end-to-end suite ran 66 journeys on one worker. Each journey already had its own home directory, workspace, runtime and server port, so the PR set Playwright to three workers with fullyParallel. Global setup sweeps orphaned processes once and installs the Electron runtime once, before any worker starts.

Evidence: Source PR/commit evidence

Use it when: A browser or desktop suite runs on one worker while its tests share no files, ports or processes.

Before applying it: Parallel journeys are safe when each owns its state; a shared file, port or install step becomes a race. Measure the worker count on your own runner.

[Read more in the DoorDash playbook](https://starsling.dev/ci-playbooks/doordash#parallel-e2e)

[Primary source](https://github.com/doordash-oss/agentic-orchestrator/pull/139)

### Ramp: Give parallel test workers more databases

After the CPU change, raising the pytest-xdist worker count left the suite's time flat at first. Profiling showed the test database buckling under the load: it hit lock contention once more than 20 workers shared it. Ramp ran more test databases, measured the ratio of workers to databases, settled on about 12 workers per database, and tuned Postgres connection settings.

Evidence: Company-reported result or observation

Together with the faster CPUs, the database changes took Ramp to a ~70% speedup of the test suite two days in, a saving of about 30 minutes. ([Source](https://builders.ramp.com/post/faster-python-tests-part-two))

Use it when: Tests run in parallel workers against one shared database or service, and adding workers leaves the job's time flat while the database is saturated.

Before applying it: Every extra database uses CPU and memory the test workers would otherwise get; Ramp saw slight regressions past its measured ratio, so keep the count that measured fastest.

[Read more in the Ramp playbook](https://starsling.dev/ci-playbooks/ramp#test-databases)

[Primary source](https://builders.ramp.com/post/faster-python-tests-part-two)

### Shopify: Isolate tests before adding workers

The CLI end-to-end suite shared one development store. Shopify/cli#7279 gave each test its own store and each worker its own ports; #7309 then turned on fullyParallel and raised Playwright workers from one to five. The default branch runs the suite fully parallel with four workers.

Evidence: Source PR/commit evidence

The PR reports about 10 minutes with 5 workers, down from about 27 minutes with 1 worker. ([Source](https://github.com/Shopify/cli/pull/7309))

Use it when: Tests run one at a time because they share ports, temporary files, accounts or database state.

Before applying it: More workers add load on shared external APIs; keep teardown observable and keep genuinely serial tests on a serial lane.

[Read more in the Shopify playbook](https://starsling.dev/ci-playbooks/shopify#isolate-before-parallel)

[Primary source](https://github.com/Shopify/cli/pull/7309)

### Stripe: Give concurrent tests their own state

Stripe sync-engine gives each end-to-end test file its own Postgres container on a random port and enables file parallelism; webhook tests run in a separate sequential configuration because they share a remote endpoint. TaxJar, a Stripe company, made its remote transaction IDs unique per version and build so its WooCommerce 7.x and 9.x test lanes can run in parallel.

Evidence: Source PR/commit evidence

Use it when: A shared database, port or remote account forces the whole suite to run serially.

Before applying it: Keep intentionally shared-state tests in a serial lane, keep teardown reliable, and use isolated sandbox accounts for remote services.

[Read more in the Stripe playbook](https://starsling.dev/ci-playbooks/stripe#isolate-parallel-test-state)

[Primary source](https://github.com/stripe/sync-engine-fork/pull/124)

### Uber: Give concurrent suites their own services

SubmitQueue replaced shared manual service setup with a Compose stack per test context. Docker allocates an ephemeral host port and the test discovers it at runtime, so the suites run as separate parallel CI jobs. OPT88's resource-isolation step is adapted; the readiness and image-tag fixes on this page complete it.

Evidence: Source PR/commit evidence

The PR creates separate CI jobs for the suites and an isolated Compose project per test context. ([Source](https://github.com/uber/submitqueue/pull/41))

Use it when: Independent integration suites collide on one port, database or container name, forcing serial execution.

Before applying it: Use collision-proof namespaces and guaranteed cleanup after every run. Separate data and image tags as well as ports, and use a protocol-level readiness probe in place of a fixed startup sleep.

[Read more in the Uber playbook](https://starsling.dev/ci-playbooks/uber#isolate-test-services)

[Primary source](https://github.com/uber/submitqueue/pull/41)

## CI optimization is continuous work.

Apply this technique yourself, or use StarSling Runners for faster GitHub Actions and optional agent-driven optimization PRs, which teams on eligible paid plans can turn on.

[Get self-improving CI](https://starsling.dev/products/runners)

## Related techniques

### [Build the test database once for all workers](https://starsling.dev/ci-playbooks/techniques/coordinate-test-setup)

Have one parallel worker apply the schema while the others wait for it, so more workers stop repeating the same setup.

1 implementation · 1 company (Ramp)

### [Match test concurrency to the runner](https://starsling.dev/ci-playbooks/techniques/tune-test-workers)

Measure worker counts against available CPU and memory. More workers help only while the runner has capacity.

4 implementations · 4 companies (Anthropic, Mastra, OpenAI, Stripe)

### [Move unit tests to a parallel-by-default framework, gated on ten clean runs](https://starsling.dev/ci-playbooks/techniques/parallel-test-framework)

Migrate serial tests to a framework that runs them in parallel, and ship each package after ten green runs.

1 implementation · 1 company (DoorDash)

## Company Playbooks

### [Anthropic](https://starsling.dev/ci-playbooks/anthropic)

Run only affected tests

### [DoorDash](https://starsling.dev/ci-playbooks/doordash)

Run build and test in parallel, sharded across CI agents

### [Linear](https://starsling.dev/ci-playbooks/linear)

Benchmark the same job on faster hardware

### [Mastra](https://starsling.dev/ci-playbooks/mastra)

StarSling runners for the slowest test workflow

### [OpenAI](https://starsling.dev/ci-playbooks/openai)

Rank CI fixes by the minutes they save

### [Ramp](https://starsling.dev/ci-playbooks/ramp)

Move a CPU-bound test suite to a faster CPU

### [Shopify](https://starsling.dev/ci-playbooks/shopify)

Let an agent iterate against one CI metric

### [Spotify](https://starsling.dev/ci-playbooks/spotify)

Build arm64 on native arm64 runners

### [Stripe](https://starsling.dev/ci-playbooks/stripe)

Run only the tests a change can reach

### [Uber](https://starsling.dev/ci-playbooks/uber)

Build the merge-queue speculations most likely to be needed

## Related guides

Implementation guides for this technique.

### [Shard tests across parallel jobs](https://starsling.dev/best-practices/github-actions/shard-tests)

Split a long suite with a matrix and your test framework’s sharding support.

### [Cut repeated test setup](https://starsling.dev/best-practices/github-actions/cut-repeated-test-setup)

Move shared fixture work out of individual test cases and keep necessary cleanup.

### [Diagnose slow tests in CI](https://starsling.dev/github-actions/problems/slow-tests)

Check common causes in order and confirm each with workflow evidence.

### [Optimize Playwright tests](https://starsling.dev/github-actions/optimizations/optimize-playwright)

Choose trace and video retention and install the browsers your suite uses.

### [Make Vitest run mode explicit](https://starsling.dev/github-actions/optimizations/optimize-vitest)

Pin run mode to the test command and bound the job with a timeout.

### [Parallelize independent jobs](https://starsling.dev/github-actions/optimizations/parallelize-independent-jobs)

Run independent validation lanes concurrently and keep genuine job dependencies.
