KatInterview

Build a Fast Pipeline for a Million-Test Suite Under Ten Minutes

System DesignModel answer
MediumModel answerSystem Designcontinuous-integrationshardingscheduling

Last updated

Design a CI pipeline that compiles a code change and executes roughly one million tests, returning results in ten minutes, while justifying sharding, caching, flakiness and cost decisions.

You own the test infrastructure for a very large monorepo. The test suite contains about 1,000,000 tests. When an engineer submits a change, your pipeline must compile it, execute the tests, and report which ones failed. A complete run must finish within 10 minutes of wall-clock time.

Design this pipeline. Do not simply list components: for each major decision, explain the alternatives you considered and why you chose what you did.

Given

  • Roughly 1,000,000 tests per full run.
  • A hard 10-minute wall-clock budget for a full run.
  • Per-test durations, submission rate and cost limits are not provided. Either ask about them or state explicit assumptions and carry them through your numbers.

Questions you may want to raise with the interviewer

  • Does the 10 minutes include compilation and machine startup, or only test execution?
  • Is the duration distribution mostly fast unit tests, or is there a long tail of slow integration tests? Is historical timing data available?
  • Must every change run every test, or may the system run only the tests a change could affect?
  • Are tests hermetic? How common are flaky tests?
  • What is the peak number of changes per hour, and is there a spending cap?

What to cover

  1. A capacity estimate tying test count, durations and the time budget to the number of executors and machines.
  2. How tests are partitioned and scheduled so no shard overruns, including very long tests and slow machines.
  3. How build outputs reach thousands of executors quickly, and what is reused between runs.
  4. Running everything versus running a selected or cached subset, and how you catch regressions that selection misses.
  5. Handling flaky tests, executor failures and retries without blowing the budget.
  6. Cost versus latency (warm pool versus autoscaling) and the metrics that prove you are meeting the target.

Hints

Hint 1

Start with arithmetic: total test-seconds divided by the time left for execution gives the minimum parallelism. Then add headroom for startup, stragglers and retries.

Hint 2

Think about scheduling as a bin-packing or work-queue problem. Use historical durations to balance shards, and consider pulling work dynamically instead of assigning fixed shards up front. Decide what to do with tests longer than a single shard's budget.

Hint 3

Most of the cost and latency win comes from not redoing work: content-addressed build caching, cached test results keyed by input hash, and dependency-based test selection with a periodic full run as a safety net.