Scrivio Interview library
DesignAdvanced6 min read · updated 13 November 2026

A team has built a replicated metadata service in Java on top of a consensus library. It passes unit and integration tests, but it has never been tested under network partitions, clock jumps, process pauses or disk faults.

Design a fault-injection test programme that would give you confidence in its correctness: which faults to inject, how to inject them, and what to check.

First write down the safety properties, such as linearizable reads and writes, no acknowledged write lost and at most one leader per term, and the liveness we expect once faults heal. Then run randomised client workloads against a real test cluster while injecting partitions, packet loss and delay, process pauses, crashes, clock jumps and disk faults, record every operation's start, end and result, and check the history with a linearizability checker in the style of Jepsen's Knossos or Elle. Combine faults, run long, keep failing seeds as regression tests, and run a short suite in CI and the full suite before each release.

Why this question is asked

Unit and integration tests prove that a replicated service works when the network and the machines behave. Consensus systems almost never fail that way; they fail when a partition happens during a leader change, or a paused process wakes up believing it is still leader. Interviewers ask senior engineers to design a fault-injection programme because it shows they know what correctness means for such a system and how to look for bugs that only appear under adversarial timing. In this answer, we will define what to check, choose which faults to inject and how, design the workload and the checker, and make the programme repeatable.

1Start From the Properties, Not the Faults

Fault injection without a precise statement of correctness only finds crashes. We first write down the safety properties, things that must never happen, and the liveness properties, things that must eventually happen.

For a replicated metadata service, safety typically means: reads and writes are linearizable, meaning every operation appears to take effect at one instant between its start and its end, so a read never returns a value older than a completed write; no write that was acknowledged to a client is ever lost; and there is at most one leader per term. Liveness means: once faults heal and a majority can talk, the service elects a leader and serves requests again within a bounded time, say 10 seconds. Each property becomes something a checker can verify mechanically.

2Which Faults to Inject and How

We inject real faults into a real test cluster of, say, five nodes, using the same operating system tools that real failures resemble. Network partitions, including one-way drops where A can reach B but not the reverse, come from iptables rules. Delay, loss, duplication and reordering come from tc netem. Process pauses, which mimic long GC pauses and VM stalls, come from SIGSTOP and SIGCONT. Crashes come from kill -9 followed by a restart. Clock faults come from libfaketime or by changing the system clock, both slow skew and sudden jumps. Disk faults include a full disk, slow fsync and failing writes, injected with a fault-injecting filesystem or device mapper.

A nemesis process, a controller whose job is to cause trouble, schedules these faults during the run: every few seconds it picks a fault, applies it, waits, and heals it.

Faults and how to inject them
FaultToolBug it tends to reveal
Partition, one-way dropiptablestwo leaders, stale reads
Delay, loss, reorderingtc netemtimeouts treated as failures
Process pauseSIGSTOP / SIGCONTstale leader acting after lease expiry
Crash and restartkill -9, restartstate not fsynced before reply
Clock skew or jumplibfaketime, dateleases that trust wall clocks
Disk full, slow or failing fsyncfault filesystemacknowledged writes lost

3The Workload and the History Checker

While the nemesis runs, several client processes issue a randomised workload: reads, writes and compare-and-set operations on a small set of keys, so that operations contend. Every client records each operation's start time, end time and result in a history. An operation can end in three ways: ok, failed (definitely did not happen), or info (timed out, outcome unknown). Recording the unknown outcomes honestly is essential; a checker must allow them to have happened or not.

After the run, a checker searches for any order of operations consistent with both the history and the properties. Jepsen's Knossos checks linearizability for registers, and Elle checks transactional histories for isolation anomalies. If no valid order exists, the checker prints the smallest set of operations that cannot be explained, which is usually the start of the bug report.

Java
// one history entry per client operation (written as the run progresses)
{:process 3, :type :invoke, :f :cas, :value [1 4], :time 1204331}
{:process 3, :type :ok, :f :cas, :value [1 4], :time 1209875}
{:process 1, :type :invoke, :f :read, :value nil, :time 1210002}
{:process 1, :type :ok, :f :read, :value 1, :time 1210431} ; stale: 4 was already written
;; checker result => {:valid? false, :anomaly "read of 1 after cas 1->4 completed"}
Step throughOne fault-injection run
  1. Start a fresh five-node clusterknown version and config
  2. Start clients with a random workloadseeded, recorded
  3. Nemesis injects and heals faultspartitions, pauses, crashes, clocks, disks
  4. Heal everything, wait for recoverychecks liveness
  5. Check the historyKnossos or Elle style checker
  6. Valid?
    YesArchive the runNoSave seed and history as a regression case

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

Notice that the read began after the compare-and-set completed, yet it returned the old value. No legal order explains that, so the service has a stale-read bug, typically a node serving reads after it lost leadership.

4Combine Faults and Run Long

Single faults in isolation find the easy bugs. Most serious bugs appear when faults overlap with the system's own state changes: a partition during a leader election, a crash during a snapshot, a pause during a membership change, a clock jump while a lease is being renewed. So the nemesis should combine faults and target these moments, for example by triggering a membership change and then partitioning the new member.

Runs should also be long. A five-minute run explores a few dozen fault windows; an overnight run explores thousands. We schedule long soak runs regularly and treat any invalid history as a release blocker.

5Make It Repeatable

A bug we cannot reproduce cannot be fixed with confidence. Every run uses a recorded random seed for the workload and the nemesis schedule, and every failing run's seed, history and logs are saved. Once fixed, that seed becomes a regression case that must pass forever.

For everyday work, a short suite of a few minutes with the most valuable fault mixes runs in CI on every merge. The full suite, with long, combined runs, runs nightly and before every release. Over time this becomes the team's main evidence that the service is correct, much stronger than any number of hand-written integration tests.

6Follow-up questions

Why record operations that timed out?

Because their outcome is unknown, and the checker must consider both possibilities. If we dropped them, a write that did take effect would look like a phantom value appearing from nowhere, and if we counted them as failed, we would accuse the system of a bug it did not have.

Can we test without a real cluster, for example in one process?

Yes, deterministic simulation testing runs all nodes, the network and the clock in one process under a seeded scheduler, which explores far more interleavings and reproduces perfectly. It complements real-cluster testing, which still catches bugs in the real network stack, filesystem and operating system.

How do we know the programme is effective?

Plant known bugs, such as skipping an fsync or serving reads from followers, and confirm the suite catches each within a few runs. If a planted bug survives, the workload or the nemesis needs to be stronger.

7Conclusion

In this answer, we designed a fault-injection programme for a replicated metadata service. It starts from written safety and liveness properties, injects realistic faults with iptables, tc netem, SIGSTOP, kill -9, clock tools and disk faults while randomised clients record a full history, and checks that history with a linearizability or consistency checker. Combined faults and long runs find the bugs hidden around leader changes and snapshots, and saved seeds, a short CI suite and a full pre-release suite keep it repeatable.

What to say in the interviewAbout 80 seconds aloud

Open with

I'd start by writing down what correct means, because without that fault injection only finds crashes. For a metadata service, safety is linearizable reads and writes, no acknowledged write ever lost, and at most one leader per term; liveness is that once faults heal and a majority can talk, it recovers within a bounded time.

Then, if they want more

Then I'd run a real five-node test cluster with a nemesis that injects real faults: partitions and one-way drops with iptables, delay and loss with tc netem, process pauses with SIGSTOP and SIGCONT, crashes with kill -9 and restarts, clock skew and jumps with libfaketime, and disk faults like a full disk or slow fsync.

Meanwhile several clients run a randomised workload of reads, writes and compare-and-set on a few contended keys and record every operation's start, end and result, including unknown outcomes from timeouts. Afterwards a checker like Jepsen's Knossos or Elle verifies that some legal order explains the history.

I'd combine faults and target leader changes, membership changes and snapshots, because that's where most bugs hide, and do long soak runs. And I'd keep it repeatable: seeds and histories of failing runs become regression cases, a short suite runs in CI, and the full suite runs before every release.

About this answer

Last updated
13 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 official documentation for the version you use. 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 "Design a fault-injection test programme that would give you confidence in its...": https://scrivio-interview-library.netlify.app/architecture/distributed-systems/866a5b261e/