Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

Kafka Fault Tolerance

Kafka's fault tolerance mechanisms ensure data durability and service availability during failures.


Fault tolerance mechanisms at the application, cluster, and infrastructure layersFault tolerance mechanisms at the application, cluster, and infrastructure layersApplication LayerCluster LayerInfrastructure LayerProducer RetriesConsumer RebalancingReplicationLeader ElectionController FailoverRack AwarenessCross-Cluster Replication

Leadership and ISR membership before, during, and after a broker failureLeadership and ISR membership before, during, and after a broker failureBefore FailureDuring FailureAfter RecoveryB1 (Leader)B2 (ISR)B3 (ISR)B1 (OFFLINE)B2 (Leader)B3 (ISR)B1 (ISR)B2 (Leader)B3 (ISR)B1 failsB1 recovers
PhaseAction
DetectionController detects broker offline (session timeout)
ElectionController elects new leader from ISR
RecoveryReturning broker catches up as follower
ScenarioImpactMitigation
ISR drops below min.insync.replicasacks=all producers fail with NOT_ENOUGH_REPLICASSet RF and min.insync.replicas for your failure budget
ISR emptyPartition unavailable until a replica catches upMonitor ISR shrinkage
Unclean electionPotential data lossDisable unclean election

For complete Raft consensus mechanics, election protocols, and metadata recovery, see KRaft Deep Dive.

KRaft controller quorum replicating metadata to votersKRaft controller quorum replicating metadata to votersController QuorumC1 (Leader)C2 (Voter)C3 (Voter)Raft consensusAutomatic failoverMajority required (2/3)replicatereplicate
  1. Leader controller fails
  2. Remaining voters detect failure (heartbeat timeout)
  3. New election triggered
  4. Voter with most up-to-date log wins
  5. New leader resumes metadata operations

Distribute replicas across failure domains to survive rack/zone failures. For complete topology design including network architecture and multi-datacenter layouts, see Topology.

Partition replicas distributed across three racksPartition replicas distributed across three racksRack 1Rack 2Rack 3B1(P0 Leader)B2B3(P0 Replica)B4B5(P0 Replica)B6Partition 0 replicas spreadacross all three racksSurvives entire rack failure
# Broker configuration
broker.rack=rack1
# Replica placement
replica.selector.class=org.apache.kafka.common.replica.RackAwareReplicaSelector

For detailed ISR mechanics, acknowledgment levels, and min.insync.replicas behavior, see Replication.

# Maximum durability
acks=all
retries=2147483647
delivery.timeout.ms=120000
enable.idempotence=true
# Ordering guarantee
max.in.flight.requests.per.connection=5
# Replication
default.replication.factor=3
min.insync.replicas=2
unclean.leader.election.enable=false
# Durability (optional overrides)
# log.flush.interval.messages=10000
# log.flush.interval.ms=1000

Durability note

The flush settings above are disabled by default (log.flush.interval.messages and the scheduler interval default to Long.MAX_VALUE). Explicit flush settings are not required for durability and reduce throughput.

  • acks=all requires the ISR size to be ≥ min.insync.replicas, otherwise the write is rejected.
  • With acks=all, the system can lose up to RF - min.insync.replicas brokers without losing committed data.
  • acks=1 can acknowledge data that is not yet replicated; a leader failure can lose recent records.
ConditionResult
Unclean leader election enabledAcknowledged data can be lost
acks=1 and leader fails before followers replicateAcknowledged data can be lost

Durability Table (Unclean Election Disabled)

Section titled “Durability Table (Unclean Election Disabled)”
acksmin.insync.replicasRFMax broker failures without losing acknowledged data
1130 (leader failure can lose recent records)
all132
all231
all253

MechanismConfigurationDefault
Session timeoutbroker.session.timeout.ms9000
Heartbeat intervalbroker.heartbeat.interval.ms2000

Broker heartbeat constraints

The controller enforces broker.heartbeat.interval.msbroker.session.timeout.ms / 2. The session timeout is configured on controllers; the heartbeat interval is configured on brokers.

ClientSettingDefault
Producerrequest.timeout.ms30000
Consumersession.timeout.ms45000
Consumerheartbeat.interval.ms3000

Terminal window
# Check offline partitions
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --unavailable-partitions
# Check under-replicated
kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --under-replicated-partitions
# Force leader election (if ISR available)
kafka-leader-election.sh --bootstrap-server kafka:9092 \
--election-type preferred \
--topic my-topic \
--partition 0

Data Loss Risk

Unclean leader election can result in data loss. Use only when availability is critical.

Terminal window
# Temporarily enable unclean election
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type topics \
--entity-name my-topic \
--alter \
--add-config unclean.leader.election.enable=true
# Trigger election
kafka-leader-election.sh --bootstrap-server kafka:9092 \
--election-type unclean \
--topic my-topic \
--partition 0
# Disable unclean election
kafka-configs.sh --bootstrap-server kafka:9092 \
--entity-type topics \
--entity-name my-topic \
--alter \
--delete-config unclean.leader.election.enable

MetricConditionSeverity
OfflinePartitionsCount> 0Critical
UnderReplicatedPartitions> 0 for 5minWarning
UnderMinIsrPartitionCount> 0Critical
ActiveControllerCount≠ 1Critical
health-check.sh
#!/bin/bash
# Check for offline partitions
OFFLINE=$(kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --unavailable-partitions 2>/dev/null | wc -l)
if [ "$OFFLINE" -gt 0 ]; then
echo "CRITICAL: $OFFLINE offline partitions"
exit 2
fi
# Check for under-replicated
UNDER_REP=$(kafka-topics.sh --bootstrap-server kafka:9092 \
--describe --under-replicated-partitions 2>/dev/null | wc -l)
if [ "$UNDER_REP" -gt 0 ]; then
echo "WARNING: $UNDER_REP under-replicated partitions"
exit 1
fi
echo "OK: Cluster healthy"
exit 0

PracticeRationale
Use RF ≥ 3Survive multiple failures
Set min.insync.replicas = 2Ensure durability with acks=all
Disable unclean electionPrevent data loss
Enable rack awarenessSurvive rack failures
Regular failover testingValidate recovery procedures
Monitor ISR shrinkageDetect issues early