Quick revision
The short answer
Building consensus in-house is rarely justified, because the bugs live in the parts that look easy, membership changes, log compaction and snapshots, disk error handling and restarts, and they can hide for years. I would steer the team to an existing coordination service such as etcd or ZooKeeper when the need is small metadata, leases and watches, or to a proven embedded Raft library such as Apache Ratis when the service must own its replicated log. If building is still justified, I would require a formal specification, deterministic simulation testing, fault injection with linearizability checks and independent review before production data, count the long-term ownership cost, and set gates: a written case, a non-critical pilot and a review date.
What to remember
In this answer, we weighed building consensus in-house against using a coordination service or embedding a library. Consensus is notoriously hard to get right, with bugs hiding in membership changes, snapshots, disk errors and restarts, so etcd or ZooKeeper suits small metadata and leases, and a proven library such as Apache Ratis suits a service that must own its log. If building is justified, it needs a formal specification, deterministic simulation, fault injection with linearizability checks and independent review, plus an honest count of long-term ownership cost, and gates: a written case, a non-critical pilot and a review date.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Building consensus in-house is rarely justified, because the bugs live in the parts that look easy, membership changes, log compaction and snapshots, disk error handling and restarts, and they can hide for years. I would steer the team to an existing coordination service such as etcd or ZooKeeper when the need is small metadata, leases and watches, or to a proven embedded Raft library such as Apache Ratis when the service must own its replicated log. If building is still justified, I would require a formal specification, deterministic simulation testing, fault injection with linearizability checks and independent review before production data, count the long-term ownership cost, and set gates: a written case, a non-critical pilot and a review date.
Background to this question
Every few years a capable team proposes writing its own consensus implementation. The motivation is usually reasonable: existing options look heavy, the team wants control, and the Raft paper makes the algorithm look approachable. Senior technical leaders are asked how they would handle this because the decision is less about the algorithm than about risk, cost and what the organisation can support for a decade. In this answer, we will look at why consensus is so hard to get right, compare the three options, set the conditions for building, count the long-term cost, and structure the decision so it is made on evidence.
1Why Consensus Is So Hard to Get Right
The core of Raft fits in a few pages, and a team can make a demo that elects leaders and replicates entries in a couple of weeks. That demo is perhaps a fifth of a production system. The rest is where the bugs hide: changing cluster membership while requests flow, compacting the log into snapshots and sending snapshots to slow followers, handling a disk that returns errors or silently loses an fsync, restarting with partially written files, and interacting with clients that retry after timeouts.
These bugs appear only under rare interleavings of faults, so ordinary tests pass for months. Well-funded, widely used implementations have shipped with data-loss bugs in exactly these areas, found years later by tools such as Jepsen. A metadata service that loses or duplicates entries corrupts everything built on it, so the cost of a hidden bug is large. That history is the main input to the decision.
2The Three Options
The first option is an existing coordination service. etcd, ZooKeeper and managed equivalents offer a small, strongly consistent key-value store with leases, watches and transactions. If the new service needs small metadata, leader election, locks and change notifications, it can use one of these as its source of truth and stay stateless itself. The cost is running the service, or paying for a managed one, and fitting within its limits, such as etcd's few gigabytes of data and modest write rate.
The second option is an embedded consensus library. When the service must own its replicated log, for example because it needs custom state machine logic, its own storage format or higher throughput than a coordination service gives, a mature Raft library provides the hard parts. In Java, Apache Ratis is the obvious candidate; in other ecosystems, etcd's raft library or similar. The team writes the state machine and the integration, not the protocol.
The third option is building from scratch. It offers full control and no external dependency, and it is justified only when the first two truly cannot meet the requirements.
| Option | Fits when | Main cost | Risk |
|---|---|---|---|
| Coordination service (etcd, ZooKeeper) | small metadata, leases, watches | operate or buy the service | low |
| Embedded library (e.g. Apache Ratis) | service must own its log | integration, learning the library | medium |
| Build in-house | both above proven insufficient | years of expert ownership | high |
3Conditions If We Build
If, after examining the options, building is justified, I would make the conditions part of the plan from day one rather than add them after an incident. A formal specification of the core protocol, written in TLA+ or a similar language and model-checked, catches design errors before code exists; it should cover membership changes and snapshots, not just the happy path.
Deterministic simulation testing runs the whole cluster, network, disks and clock inside one process under a seeded scheduler, so millions of fault interleavings can be explored and any failure replayed exactly. Fault injection on a real cluster, with partitions, pauses, crashes, clock jumps and disk faults, together with a linearizability checker on recorded histories in the style of Jepsen, catches what the simulation's models miss. And an independent review by people who have built or broken such systems before, inside or outside the company, should sign off before any production data is stored.
4Counting the Long-Term Cost
The visible cost is the build: perhaps two or three senior engineers for a year to reach production quality with the testing above. The larger cost comes after. Someone must be on call for a component whose failures are subtle, upgrades must be designed so mixed versions interoperate, observability must explain elections and lag, and every change needs the same level of testing.
The quietest risk is the bus factor, the small number of people who truly understand the code. If two engineers built it and one leaves, the organisation owns critical infrastructure that few can safely change. A coordination service or a widely used library spreads that knowledge across a community. When I compare options, I put this ownership cost over five years next to the cost of the alternatives, and the comparison is usually decisive.
5Setting Gates for the Decision
Rather than simply saying no, which loses the team's trust and may be wrong, I would set gates. First, a written explanation of the requirements and why existing services and libraries fail them, with measurements, for example a benchmark showing the write rate etcd cannot sustain. Second, if building proceeds, a pilot with non-critical data, with the specification, simulation testing and fault injection in place. Third, a review date, perhaps six months out, to reconsider with evidence from the pilot.
These gates turn an opinion into a decision the organisation can check. Often the first gate resolves it: writing down the requirements reveals that etcd or Ratis fits after all. When it does not, the team builds with the safeguards that make success likely.
- Need: small metadata, leases, watches?YesUse etcd, ZooKeeper or managedNoService must own its log
- Can a proven library meet the needs?YesEmbed it (e.g. Apache Ratis)NoWrite the case for building
- Case reviewed and accepted?YesBuild with spec, simulation, fault testsNoUse the closest existing option
- Pilot on non-critical dataindependent review before production
- Review date with pilot evidencecontinue, switch or stop
5 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Isn't using an existing service also a long-term commitment?
Yes, but one shared with a large community that finds and fixes bugs, documents operation and trains engineers who already know it. Owning a custom implementation means carrying all of that alone.
What if the existing options really are too heavy?
Then measure 'heavy': memory, latency, operational burden. An embedded library is often much lighter than a separate service, and managed offerings remove the operational load. Only if those also fail on measured requirements is building on the table.
How would you keep the team motivated if the answer is no?
Give them the hard, valuable part: designing the state machine, the API and the data model on top of a proven core, and owning the testing that proves the service correct. That is where the product's differentiation is, not in reimplementing Raft.
7Conclusion
In this answer, we weighed building consensus in-house against using a coordination service or embedding a library. Consensus is notoriously hard to get right, with bugs hiding in membership changes, snapshots, disk errors and restarts, so etcd or ZooKeeper suits small metadata and leases, and a proven library such as Apache Ratis suits a service that must own its log. If building is justified, it needs a formal specification, deterministic simulation, fault injection with linearizability checks and independent review, plus an honest count of long-term ownership cost, and gates: a written case, a non-critical pilot and a review date.
Open with
I'd start from the fact that consensus is notoriously hard to get right. The core algorithm looks small, but the bugs live in membership changes, log compaction and snapshots, disk error handling and restarts, and they can hide for years; mature, widely used implementations have had them.
Then, if they want more
So my default is not to build. If the service needs small metadata, leader election, leases and watches, I'd use an existing coordination service like etcd or ZooKeeper, or a managed equivalent, and keep our service stateless.
If the service has to own its replicated log, I'd embed a proven library, in Java probably Apache Ratis, and have the team write the state machine rather than the protocol.
If building is still justified, I'd set conditions up front: a formal specification of the core in TLA+ or similar, model-checked; deterministic simulation testing; fault injection on a real cluster with linearizability checks on recorded histories, like Jepsen; and an independent review before any production data.
I'd also count the long-term cost honestly: on-call expertise, upgrades, observability and the handful of people who understand the code. And I'd set gates: a written explanation of why existing options fail the requirements, with measurements, a pilot with non-critical data, and a review date to reconsider with evidence.
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 "As the senior technical leader, how do you weigh building consensus in-house against...": https://scrivio-interview-library.netlify.app/architecture/distributed-systems/2e104787c1/