Kafka
Consumer Config
heartbeat.interval.ms
session.timeout.ms
Kafka Consumer Settings

Kafka heartbeat.interval.ms vs session.timeout.ms in consumer config

Codemia Knowledge Hub ·

heartbeat.interval.ms controls how often a consumer sends heartbeats to the group coordinator. session.timeout.ms controls how long the coordinator waits without a heartbeat before it declares the consumer dead and rebalances the group. The heartbeat interval is normally set to about one third of the session timeout.

heartbeat.interval.ms: how often the consumer checks in

heartbeat.interval.ms is the expected time between heartbeats to the consumer coordinator when using Kafka's group management. Heartbeats keep the consumer's session alive, maintain its membership in the consumer group, and support proper rebalancing.

Heartbeats show that a consumer is still connected and working without waiting for the longer session.timeout.ms. A shorter interval allows quicker failure detection and faster rebalancing.

session.timeout.ms: when the consumer is declared dead

session.timeout.ms is how long the coordinator waits for a heartbeat before considering the consumer dead. When that happens, the group coordinator rebalances the group and redistributes the consumer's partitions among the remaining consumers.

This timeout matters when consumers run long tasks or the system is under high load: a value that is too short can cause premature rebalancing.

The one-third rule

Keep a sensible ratio between the two. Typically heartbeat.interval.ms is set to one third of session.timeout.ms, so the consumer gets about three chances to heartbeat within each session timeout and failures are still detected promptly.

ConfigurationDefault ValueRecommended PracticeDescription
heartbeat.interval.ms3000 msOne-third of session.timeout.msDetermines how frequently the Kafka Clients sends heartbeats to the broker. Ensures it's active.
session.timeout.ms45000 ms (10000 ms before Kafka 3.0)Based on system load and nature of tasksUsed by the broker to detect if the consumer has failed. Larger values are preferable in systems with high loads or large tasks.

Tuning advice

  1. Balance the interval: a very low heartbeat.interval.ms adds network traffic and can lead to quick timeouts on heavily loaded systems, while a very high value delays rebalancing when a consumer fails.
  2. Start from the defaults: begin with Kafka's defaults, then adjust based on workload and how stable your consumers are in practice.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design