Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Over years, how do flaky tests affect an engineering organisation, and what policies would you put in place?

Over years, flaky tests erode trust: engineers learn that a red build probably means nothing, start rerunning and merging on red, and eventually miss real failures. They also waste CI capacity and slow delivery through reruns and waiting. The policies I would put in place are to track the flake rate as a visible metric, quarantine flaky tests with an owner and a deadline, budget time for fixing them, and above all design test infrastructure, containers, clocks, ids and ports, so tests are deterministic by default.

Why this question is asked

At the scale of a whole engineering organisation, flaky tests stop being an annoyance and become a cultural force. They decide whether people believe the build, how long it takes to ship, and whether a real bug gets caught or rerun away. Interviewers ask this at the most senior level because the answer is about systems and incentives, not about any single test. In this answer, we will look at how flakiness damages trust and what it costs in time and money, then go through the policies that work, and finish with the part that matters most in the long run: making determinism the default in the test platform itself.

1How Flaky Tests Erode Trust

A test exists to give a signal: green means the change is safe, red means something is wrong. A flaky test breaks that contract, and the damage spreads beyond the test itself. The first time a build fails for no reason, an engineer investigates for twenty minutes. The fifth time, they rerun without looking. After a few months, the team's habit is to rerun every red build once before reading the failure, and some people merge with a red build because 'that one is always flaky'.

At that point, the whole suite has lost value, not just the flaky tests. A real regression that fails the build is rerun, fails again, and is still dismissed as 'CI being CI'. A typical story is a race condition in payment code that ships to production after its test had failed intermittently for weeks, because everyone had learned to ignore that test. The cost of flaky tests is not the reruns; it is that the organisation stops listening to its own safety net.

2What Flakiness Costs in Time

The direct cost can be estimated with simple numbers, and putting numbers on it is usually what wins the budget to fix it. Suppose an organisation runs 3,000 builds a day, 4 percent fail for flaky reasons, a rerun takes 25 minutes of CI time, and the engineer loses 15 minutes to the context switch and the wait.

Text
flaky builds per day = 3,000 x 0.04 = 120
CI time lost per day = 120 x 25 min = 3,000 min (50 agent hours)
engineer time per day = 120 x 15 min = 1,800 min (30 hours, about 4 engineers full time)
delay per affected PR = 25 min or more before it can merge

Four engineers' worth of time every day is a team the organisation pays for and never sees. On top of that, reruns delay merges and deployments, so the lead time for changes grows, and teams compensate by batching changes into bigger, riskier deployments. These indirect costs are harder to count but usually larger.

3Policy 1: Make the Flake Rate a Visible Metric

What is not measured gets normalised. The platform collects test results from every CI run and computes, per test and per team, how often a test failed and passed on the same commit. The organisation-level number, the share of builds that fail for flaky reasons, goes on the same dashboard as build time and deployment frequency, and each team sees its own tests.

Visibility changes behaviour quickly. Teams that see their name next to the top flaky tests fix them, and new flaky tests are caught within days instead of months. The metric also lets leadership see whether investment in test reliability is paying off.

4Policy 2: Quarantine With Ownership, and Budget Time to Fix

A flaky test must not keep breaking everyone's builds, but it must not be forgotten either. The policy is that a test above a flake threshold is moved to quarantine: it no longer blocks merges, it still runs in a non-blocking job so data keeps flowing, and it gets an owning team and a deadline, for example two weeks. At the deadline it is fixed, deliberately deleted with a note on what coverage is lost, or escalated. The quarantine list is public and kept short.

None of this works without time. If fixing flaky tests competes with roadmap work and always loses, the quarantine fills up. So I would budget it explicitly, for example by making test reliability part of each team's regular maintenance allocation, and by treating a quarantined test past its deadline like any other operational issue the team owns.

Step throughLifecycle of a flaky test under the policy
  1. CI detects fail-then-pass on the same commitRecorded per test and team
  2. Flake rate above the threshold?
    YesMove to quarantineNoKeep tracking
  3. Quarantine: non-blocking job, owner, deadlineStill runs, so data keeps flowing
  4. Owner reproduces and finds the root causeRepeat runs, random order, added load
  5. Product bug or test bug?
    YesFix the product, keep the testNoFix the test, often in the shared platform
  6. Back in the blocking buildOr deleted on purpose, with the coverage gap noted

6 steps in order. Play them, or step through them one at a time.

5Policy 3: Deterministic by Default

The most effective long-term policy is to remove the causes in the platform, so individual teams do not have to rediscover them. Most flaky tests come from a handful of sources: real time, shared data, fixed ports, external services and timing guesses. Each of these can be made deterministic by default in the shared test infrastructure.

For time, application code takes a java.time.Clock bean, and the shared test configuration provides a fixed or controllable clock, so nothing depends on the real date or time zone. For data, the shared builders generate unique ids and tenants for every test, so tests cannot collide even when they run in parallel. For infrastructure, Testcontainers with random ports and approved images replaces shared databases and fixed port numbers, and HTTP dependencies are stubbed with WireMock on dynamic ports instead of calling real sandboxes. For asynchronous code, the shared library includes Awaitility helpers and a lint rule that rejects Thread.sleep() in test code.

When the defaults are deterministic, a new engineer who follows the templates writes reliable tests without knowing why, and the flake rate stays low as the organisation grows. That is the real goal: not heroic clean-up campaigns every year, but a platform where flaky tests are hard to write.

Common sources of flakiness and the platform default that removes them
SourceDefault in the test platform
Real time and time zonesInjected Clock bean, fixed clock in tests, UTC on CI
Shared test dataBuilders that create unique ids and tenants per test
Shared databases, fixed portsTestcontainers with random ports and approved images
Real external servicesWireMock on dynamic ports, contract tests
Sleeps and timing guessesAwaitility helpers, lint rule against Thread.sleep
Test orderRandom class and method order on CI, seed logged

6Follow-up questions

Would you ever allow automatic retries?

Only as a temporary cushion with full reporting: every retried failure is recorded as a flake against the test and its team. Silent retries hide real concurrency bugs and hide the trend, so they would never be the policy on their own.

How do you get teams to care about tests they did not write?

Ownership has to be clear, usually by the code the test covers rather than by who wrote it, and the metric must be visible per team. When a team's name is next to its flaky tests and it has budgeted time to fix them, it cares. Fixing causes in the shared platform also helps every team at once, which builds goodwill for the policy.

What would you report to the leadership team?

Three numbers over time: the share of builds failing for flaky reasons, the CI and engineering time that represents, and the size and age of the quarantine list. Together they show the cost, the trend and whether teams are keeping up.

7Conclusion

In this answer, we saw that flaky tests damage an organisation mainly by destroying trust in the build, which leads people to rerun and merge on red until real failures are missed. They also cost large amounts of CI and engineering time and slow delivery. The policies that work are a visible flake rate metric, quarantine with an owner and a deadline, and explicit time budgeted for fixes. The most durable policy is a test platform that is deterministic by default, with injected clocks, unique ids, containers on random ports, stubbed external services and condition-based waiting.

What to say in the interviewAbout 90 seconds aloud

Open with

The biggest effect of flaky tests over years is on trust. Each false red build teaches engineers that red probably means nothing, so they start rerunning before reading, then merging on red, and eventually a real failure gets dismissed as flaky and ships.

Then, if they want more

The second effect is cost. With, say, 3,000 builds a day and 4 percent flaky, that's 120 reruns daily, about 50 agent hours, and roughly four engineers' worth of lost time, plus longer lead times and bigger batched deployments. So I'd set three policies.

First, measure: collect results from every run, compute fail-then-pass rates per test and per team, and put the build-level flake rate on the same dashboard as build time and deployment frequency.

Second, quarantine with ownership: a test over a threshold stops blocking merges but keeps running, and gets an owning team and a deadline, after which it's fixed, deleted on purpose, or escalated. And teams get budgeted time for this, otherwise quarantine becomes a graveyard.

Third, and most important long term, make the test platform deterministic by default: an injected Clock with fixed clocks in tests, builders that generate unique ids and tenants, Testcontainers on random ports, WireMock instead of real sandboxes, Awaitility instead of sleeps, and random test order on CI. Then new tests are reliable without heroics. I'd avoid silent retries entirely.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Over years, how do flaky tests affect an engineering organisation, and what policies...": https://scrivio-interview-library.netlify.app/java/integration-testing/a5b36d1527/