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.
Defaults and recommended values
| Configuration | Default Value | Recommended Practice | Description |
heartbeat.interval.ms | 3000 ms | One-third of session.timeout.ms | Determines how frequently the Kafka Clients sends heartbeats to the broker. Ensures it's active. |
session.timeout.ms | 45000 ms (10000 ms before Kafka 3.0) | Based on system load and nature of tasks | Used by the broker to detect if the consumer has failed. Larger values are preferable in systems with high loads or large tasks. |
Tuning advice
- Balance the interval: a very low
heartbeat.interval.msadds network traffic and can lead to quick timeouts on heavily loaded systems, while a very high value delays rebalancing when a consumer fails. - Start from the defaults: begin with Kafka's defaults, then adjust based on workload and how stable your consumers are in practice.
Related reading
- Difference between idempotence and exactly-once in Kafka Stream
- Difference between Kafka and ActiveMQ
- Difference between kafka and nifi
- Difference between Kafka async and Kafka sync acks=0?
- Difference between KTable and local store
- Difference between 'metric.reporters' and 'kafka.metrics.reporters' properties in Kafka
- Difference between request.timeout.ms and timeout.ms properties of Kafka producer
- Difference between retention configuration offsets.retention.minutes and log.retention.minutes
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.