QA Interview Hub · Knowledge base · Quizzes · Українська

System Design › CI/CD, parallelization and sharding

Feedback speed and cost

Speeding up a pipeline starts with measuring, not with adding shards. Time is broken down into runner startup, dependencies, data and login, slow tests and environment waits. Overhead is multiplied by the number of shards, so a prebuilt image with browsers is often cheaper than new machines. Cheap levers are maxFailures and cancelling outdated runs; PR feedback time is judged by p95.

System design · CI and parallelism

The pipeline got 4 minutes longer and nobody knows why. Where exactly does the time go?

Last month a run took 15 minutes, now 19. The team proposes adding shards, because that is quick to do. But a Senior must talk not only about speed but also about money and about where the real bottleneck is: the four minutes might have come from dependency installation, new slow tests or an overloaded staging, and in none of these cases will new machines help as much as it seems. This lesson covers how to break time down, when to add machines and what they cost.

How it works and why. Pipeline time consists of parts, and each has its own lever. So the first step is measuring, not deciding. GitHub Actions shows the time of each job step, and Playwright can show the slowest tests. Only then do you choose where to invest.

Where to look for time in a pipeline

Runner start and dependenciesnpm cache, a ready image with browsersData and loginAPI instead of UI, storageStateThe tests themselvesthe slowest: rewrite or move to APIWaiting for the environmenta health check instead of sleepReport and artifactsblob reports, only what is needed
Figure 1. Measure first, then choose a lever: without measuring the wrong thing gets optimised.
  • Runner start and dependencies. An npm cache (cache: npm in setup-node caches downloaded packages, not node_modules) and a ready image with browsers. The Playwright documentation does not recommend caching browser binaries: the gain is minimal, so a mcr.microsoft.com/playwright container with a tag matching the @playwright/test version is better.
  • Data and login. The API instead of the UI, storageState instead of logging in in every test.
  • Slow tests. Find the longest tests and rewrite or move them to the API. reportSlowTests in the config lists the slowest files; individual tests are visible in the report.
  • Waiting for the environment. A health check before the start, not sleep: sleep either waits needlessly or does not wait enough.

Example: fixed costs against cost. Suppose 8 shards of 15 minutes, 50 merges a day, 3 minutes of overhead per shard:

8 machines x 15 min x 50 merges = 6000 machine-min a day
Overhead: 3 min x 8 x 50       = 1200 (about 20%)
If an image cuts it to 1 min:    -800 a day

In GitHub Actions each job is billed separately and rounded up to the minute, so 8 shards are 8 separate charges for time, and the overhead is not shared between them. Two conclusions follow. First: a prepared image is cheaper than new shards, because it cuts both time and cost. Second: the cost of sharding grows with their number, while the time gain is nonlinear. Concrete prices depend on the plan and the runner type, so they are taken from the current documentation, not from memory.

When to add machines and when not. If tests run into a shared staging (the DB, request limits), adding shards will not speed up the run but will only increase timeouts. First the bottleneck must be found.

When to add machines

Typical

Add shards without measuring

The bottleneck is the shared staging DB. New shards add timeouts, not speed, and the cost grows.

Better

Find the bottleneck first

They saw the time goes on installation and login. An image and storageState removed it without new machines.

Figure 2. Parallelism helps only where the bottleneck is the tests themselves and the environment can take it.

Two cheap optimisations that need no machines. The first: fail fast. The maxFailures option stops the run after N failures, and on a PR that saves minutes when something basic (login) is broken. The second: cancel outdated runs. When a new commit appears in a PR, the previous run is no longer needed by anyone:

export default defineConfig({
  maxFailures: process.env.CI ? 10 : 0,
  reportSlowTests: { max: 20, threshold: 30_000 },
});
concurrency:
  group: pr-${{ github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

The condition in cancel-in-progress limits cancellation to PR runs, so runs on main are not cut off. The config above: maxFailures on CI, and zero means no limit locally.

Limits and alternatives. Optimisation has a downside: an overly aggressive maxFailures hides part of the failures, and the PR author sees only the first ones, fixes them and then the rest surface. Cancelling runs suits a PR but not release runs. The strategy «fewer tests on a PR, the full suite on main» saves money but moves defect detection later, and that is a deliberate trade-off to be stated out loud. For PR feedback time look at the percentile (p95), not the mean: the rare slow runs create the feeling of a slow CI.

Common mistakes.

  • Adding shards without measuring: the wrong thing gets optimised and the cost grows.
  • Using sleep instead of a readiness check: the test either waits too long or fails because the environment is not ready.
  • Not cancelling outdated runs: money goes on a result nobody reads any more.
  • Caching browser binaries and spending time maintaining it instead of a ready image.
  • Talking about speed and staying silent about cost: for a Senior the answer is incomplete.

Check yourself

8 shards, 3 minutes of overhead on each, 50 merges a day. How many machine-minutes a day go to overhead, and what does an image that cuts it to 1 minute change?

Answer

3 x 8 x 50 = 1200 machine-minutes a day. With the image 1 x 8 x 50 = 400, a saving of 800 a day without new machines and without changing the tests. That is cheaper than adding shards, which multiply the overhead.

Shards were added and the time did not drop, only timeouts appeared. What is the likeliest cause and what to do?

Answer

The bottleneck is not the tests themselves but the shared environment: the DB or staging limits cannot take more parallel sessions. Confirm it by measuring, then scale the environment, give each shard its own, or reduce the load (data through the API, fewer calls), instead of adding machines.

In an interview. Junior: Before adding machines I look for the bottleneck: dependency installation, login through the UI, the slowest tests or an overloaded environment. Parallelism helps only when the environment can take the load. Middle/Senior: I break pipeline time down into start, data and login, the tests themselves, waiting for the environment and the report, and take a lever for each. I count the cost: overhead multiplies by the number of shards, so a prepared image is cheaper than new machines. I add maxFailures and cancelling of outdated runs. The metric: p95 of PR feedback time and the cost of a run in machine-minutes, not only the average time.

More articles in this chapter