Quick revision
The short answer
I would set the policy by what a lost record costs in each class. Metrics and logs value availability, so unclean election may be enabled with replication factor 3 and min.insync.replicas of 1 or 2. Payments never use unclean election: replication factor 3, min.insync.replicas=2, acks=all, and an offline partition is an incident where we restore the lost replica. CDC and compacted reference topics also avoid unclean election, because it silently diverges them from the source table; if it was unavoidable, we re-snapshot from the source. The runbook detects offline partitions through OfflinePartitionsCount, finds the replicas and their lag, decides with the topic owner, records the decision and reconciles, and topic policies enforce each class's settings.
What to remember
In this answer, we defined four classes: metrics and logs where unclean election may be allowed, payments where it never is, and CDC and compacted reference topics where it is avoided because it silently diverges them from their source and must be followed by a re-snapshot. Each class has matching replication factor, min.insync.replicas and acks settings. The runbook detects offline partitions, identifies the class and replicas, decides with the owner, records the decision and reconciles, and topic policies plus audits enforce the settings so the decision is never made under pressure.
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.
I would set the policy by what a lost record costs in each class. Metrics and logs value availability, so unclean election may be enabled with replication factor 3 and min.insync.replicas of 1 or 2. Payments never use unclean election: replication factor 3, min.insync.replicas=2, acks=all, and an offline partition is an incident where we restore the lost replica. CDC and compacted reference topics also avoid unclean election, because it silently diverges them from the source table; if it was unavoidable, we re-snapshot from the source. The runbook detects offline partitions through OfflinePartitionsCount, finds the replicas and their lag, decides with the topic owner, records the decision and reconciles, and topic policies enforce each class's settings.
Why this question is asked
With 800 topics, nobody can make good durability decisions one topic at a time, and certainly not at three in the morning during an outage. A platform needs a small number of classes, each with settings that match the data's value, and a runbook that turns an offline partition into a predictable procedure. Interviewers ask this to see whether we can design policy, not just tune configs, and whether we understand how unclean elections affect different kinds of data differently. In this answer, we will recap what unclean leader election trades, define the four classes and their settings, explain why CDC and compacted topics need special care, write the offline-partition runbook, and make the policy enforceable.
1A Quick Recap of What Unclean Election Trades
When every in-sync replica of a partition is lost, Kafka must choose. With unclean.leader.election.enable=false, the default, the partition stays offline until an in-sync replica returns, so no committed record is lost but writes and reads stop. With it set to true, an out-of-sync replica may become leader, so the partition is available again quickly, but records that only the lost replicas held are gone, and later records reuse their offsets.
Two related settings decide how often we reach that choice. min.insync.replicas, with producers using acks=all, sets how many replicas must have a write before it is acknowledged; a value of 2 means a single surviving replica cannot accept writes alone and fall far ahead of the others. Replication factor sets how many replicas could survive at all. Together they decide whether an ISR collapse is likely and how much data is at stake.
2Four Classes and Their Settings
Metrics and logs are high-volume and individually low-value. A gap of a few thousand data points is barely visible, while a partition that refuses writes can back up agents across the fleet. For them availability wins: unclean election may be enabled, replication factor 3, and min.insync.replicas of 1 or 2 depending on how much the team cares about loss during routine failures.
Payments and other financial events are the opposite. A lost event means money that cannot be traced, so unclean election is never allowed. Replication factor 3, min.insync.replicas=2, acks=all and idempotent producers, with replicas spread across zones. An offline payments partition is an incident: we restore the lost replica, from the broker or from backups, rather than give up data, and upstream services buffer or retry in the meantime.
CDC streams, change data capture from databases, and compacted reference data look less critical than payments but have their own trap, described next. Their policy is also no unclean election, with the same replication settings as payments, plus a documented way to rebuild them from the source.
| Class | Unclean election | RF / min ISR / acks | Offline partition |
|---|---|---|---|
| Metrics and logs | allowed | 3 / 1 or 2 / 1 or all | elect unclean, note the gap |
| Payments, financial | never | 3 / 2 / all | incident, restore replica |
| CDC streams | avoid | 3 / 2 / all | wait; if forced, re-snapshot |
| Compacted reference | avoid | 3 / 2 / all | wait; if forced, rebuild from source |
3Why CDC and Compacted Topics Need Care
A CDC topic is a stream of every change to a database table: insert row 42, update row 42, delete row 17. Consumers apply these changes in order to keep a copy of the table, a search index or a cache. If an unclean election drops a range of records, consumers miss some changes. The source table has the update, the copy does not, and nothing in the stream tells anyone. The copies silently diverge, and they stay wrong until the same row changes again, which for some rows is never.
Compacted reference topics have the same problem in a stronger form. They keep only the latest value per key and are often read from the start to rebuild state. If the lost range held the latest value of some keys, the topic now holds an older value for them, and every future bootstrap rebuilds wrong state. So for both kinds, waiting is preferred; if an unclean election was unavoidable, the repair is to re-snapshot: CDC tools such as Debezium can take a fresh snapshot of the affected tables, and reference data can be republished from its source system, overwriting the stale values.
4The Runbook for an Offline Partition
The runbook starts with detection: an alert on OfflinePartitionsCount above zero for longer than a short grace period. The on-call engineer then identifies the partition, its topic and class, its replicas, which brokers are down, and how far behind each surviving replica is, using kafka-topics.sh --describe --unavailable-partitions and replica lag information.
Next comes the decision, and the class answers most of it. For metrics, the engineer runs the unclean election and notes the gap. For payments, CDC or reference data, the engineer works on restoring the failed broker and contacts the topic owner, who decides whether waiting longer is acceptable. If an unclean election is approved, the decision is recorded with the lost offset range, and a reconciliation task is opened: re-snapshot for CDC, republish for reference data, compare with the ledger for payments.
- OfflinePartitionsCount above 0alert after a short grace period
- Identify topic class, replicas, lag
kafka-topics.sh--describe --unavailable-partitions - Class allows unclean election?YesElect unclean, record the gapNoRestore the failed replica
- Restore possible in acceptable time?YesWait, keep producers bufferingNoOwner approves unclean election
- Record decision and lost offset rangein the incident ticket
- Reconcile: re-snapshot, republish or compare with ledger
6 steps in order. Play them, or step through them one at a time.
Every unclean election ends with reconciliation, never with silence.
5Making the Policy Enforceable
A policy that lives only in a document drifts. The class should be recorded as metadata for every topic, for example in the topics-as-code repository or a catalogue, with an owner. The settings for each class are then enforced at creation and on every change, using a server-side policy class configured with create.topic.policy.class.name and alter.config.policy.class.name, or validation in the pipeline that creates topics. A payments topic with unclean election enabled, or min.insync.replicas=1, is rejected before it exists.
Then we audit: a regular job compares every topic's actual config with its class and reports differences. Combined with the runbook, this means the hard decision was made calmly, once, by the people who own the data, and the on-call engineer only has to follow it.
6Follow-up questions
Why not simply disable unclean election everywhere?
Because for metrics and logs it would turn rare broker failures into long outages for data nobody would miss. Different data has different costs of loss and unavailability, and one setting for all of them is wrong for some. Classes let us be strict where it matters and available where it does not.
How does min.insync.replicas reduce the chance of needing an unclean election?
With min.insync.replicas=2, a partition stops accepting acks=all writes when only one replica is in sync. So no record can be acknowledged on a single replica, and when that last replica fails, the others are not behind on acknowledged data. It prevents the situation where one replica races ahead alone.
Does Eligible Leader Replicas change this policy?
It can reduce how often we face the choice. KIP-966 lets the controller elect a replica known to hold all committed data even after the ISR shrank, avoiding some offline partitions without data loss. The classes and runbook still apply for the cases it does not cover; check whether it is enabled in your version.
7Conclusion
In this answer, we defined four classes: metrics and logs where unclean election may be allowed, payments where it never is, and CDC and compacted reference topics where it is avoided because it silently diverges them from their source and must be followed by a re-snapshot. Each class has matching replication factor, min.insync.replicas and acks settings. The runbook detects offline partitions, identifies the class and replicas, decides with the owner, records the decision and reconciles, and topic policies plus audits enforce the settings so the decision is never made under pressure.
Open with
I would define classes by what a lost record costs and set unclean election and replication together for each. For metrics and logs, availability matters more than a few lost records, so unclean election can be enabled, with replication factor 3 and min.insync.replicas of 1 or 2.
Then, if they want more
For payments it is never allowed: replication factor 3 across zones, min ISR 2, acks=all, idempotent producers, and an offline partition is an incident where we restore the lost replica rather than lose data.
CDC streams and compacted reference topics also avoid unclean election, for a subtler reason: a lost range means consumers miss changes, so their copies silently diverge from the source table, and a compacted topic could keep an old value forever.
If an unclean election was unavoidable there, we re-snapshot from the source, for example with a Debezium snapshot, or republish the reference data. The runbook starts from an alert on OfflinePartitionsCount, identifies the topic class, its replicas and their lag, and then follows the class: unclean for metrics, otherwise restore and involve the topic owner, who approves any unclean election.
We record the decision and the lost offset range, and always reconcile afterwards. Finally I would store the class as topic metadata and enforce the settings with create and alter topic policies, so nobody makes this call from scratch at 3 a.m.
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 documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
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 "Define a policy per class for unclean leader election and the related replication...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-internals/d09435b135/