Task: 2000 e2e tests must finish in 15 minutes
The task of 2000 e2e tests in 15 minutes is solved with a calculation, not by adding machines. For 2000 tests of 20 seconds that is about 45 slots without overhead, about 56 with three minutes of overhead and 64 with a margin for uneven shards. Overhead does not divide across machines, so data isolation, sharding and a review of the pyramid are needed, and cost is named as the price.
System design · Framework
The nightly run takes 11 hours, but a PR should get an answer in 15 minutes. Where to start?
A suite of 2000 e2e tests runs at night, and the team wants the same on every merge to main, but within 15 minutes. The first reaction: «let us add machines». It may work, or it may give nothing. This lesson shows how to take the task apart with the scheme «requirements, layers, solution, trade-offs, metrics» and where the benefit of parallelism ends.
Requirements and calculation. We start with numbers, otherwise the answer hangs in the air. Assumptions: an average test takes 20 seconds, the target is 15 minutes for the whole suite, a run on every merge. Part of those 15 minutes goes to overhead: container start, browsers, merging reports. Take 3 minutes, the rest goes to tests.
Given: 2000 tests x 20 s, target 15 min, overhead 3 min
Work: 2000 x 20 s = 40,000 s (~667 min)
For tests: 15 - 3 = 12 min
Slots: 667 / 12 = ~56
Margin: 8 machines x 8 workers = 64 slots
Without overhead it would be about 45 slots (40,000 / 900); that is a lower bound. With overhead about 56, and with a margin for uneven shards and retries we take 64. It is an estimate to be confirmed by a real run.
How it works and why. Run time is a fixed part (overhead) plus the work divided by the number of slots. The fixed part does not shrink when machines are added, and in money it multiplies: each machine pays for its start separately. So the gain from parallelism has a ceiling, while the cost grows almost linearly. Below is an ideal model (all shards equal, 8 workers per machine, 3 minutes of overhead):
| Machines | Slots | Time, min | Machine-minutes |
|---|---|---|---|
| 4 | 32 | ~24 | ~95 |
| 8 | 64 | ~13 | ~107 |
| 16 | 128 | ~8 | ~131 |
From 8 to 16 machines we win about 5 minutes but pay roughly a quarter more machine-minutes. The closer to the overhead, the less point in adding. Reality is worse than the model: shards are uneven and the workers of one machine compete for CPU.
Two ways to cut the time
More slots
Shards and workers. Quick to turn on, but you pay in money and in load on the environment, and the gain has a ceiling.
Less work
Move checks to the API level, remove duplicates, a faster setup. Slower to do, but cuts both time and cost.
Solution. The config and the run look like this:
export default defineConfig({
fullyParallel: true,
workers: process.env.CI ? 8 : undefined,
reporter: process.env.CI ? 'blob' : 'html',
});
// run one of 8 parts on a machine:
// npx playwright test --shard=3/8
- Test isolation. Each test creates its own data. Without it parallelism gives failures from conflicts, not speed.
- Sharding and reports. Each machine gets its part through
--shardand writes a blob report; a separate job merges them withmerge-reports. - Preconditions through the API and login through a saved
storageState, so no test spends seconds on the UI. - A prepared image with browsers and dependencies, to avoid paying minutes for installation on every machine.
- Reviewing the pyramid. Part of the 2000 e2e can move to the API level: that cuts both time and cost, unlike new machines.
Trade-offs. 64 parallel sessions may «knock over» a shared staging: the DB, request limits, data. Then there are more shards while the run does not get faster, only timeouts grow. The environment must be scaled too, or each shard given its own. There is an organisational price as well: eight machines (64 slots) on every merge is a CI budget someone has to approve.
Metrics. Pipeline time by p50 and p95, not the mean. The share of unstable tests, because retries eat the budget. Shard unevenness: the longest against the average. The cost of one run in machine-minutes. The 15-minute target must hold at p95, otherwise a queue for merging appears anyway.
Limits and alternatives. The calculation assumes equal test durations and balanced shards. By default Playwright splits the suite by the number of test groups, not by their time, so one shard with heavy tests can drag everything (see the lesson on workers and shards). If what matters is not the whole suite but a quick signal, the PR set can be narrowed (smoke and critical scenarios) and the full suite left for main. That is a different requirement: «15 minutes for everything» and «5 minutes for a signal» have different solutions.
Common mistakes.
- Counting without overhead: 667 / 15 = 45 slots looks neat, but then 18 minutes appear instead of 15.
- Adding shards without looking at the environment: the ceiling is there, not in the number of machines.
- Going parallel without data isolation: the time gain is bought with flakiness.
- Staying silent about cost: «just 64 slots» without a price is not an answer for a Senior.
- Not measuring after the changes: the 15-minute target stays an assumption.
Check yourself
One of the 8 shards has 20% more work than the others. What happens to the 15-minute target in the model above?
Answer
A balanced shard carries 667 / 64 ≈ 10.4 min of tests. With 20% extra that is ≈ 12.5 min, plus 3 min of overhead, about 15.5 min in total: the target is missed even with 64 perfectly chosen slots. The longest shard sets the time, so unevenness is a metric.
Why might the answer «take 16 machines instead of 8» not shorten the run?
Answer
Overhead does not divide across machines, and the shared environment (DB, limits) may already be at its edge. Extra sessions give timeouts, not speed, and the cost grows. First find the bottleneck and cut the work, then add slots.