What does session.timeout.ms control?
Solution and explanation
What it controls
session.timeout.ms is how long the group coordinator waits **without receiving a heartbeat** from a consumer before declaring it dead, removing it from the group and triggering a rebalance. Default: **45 seconds** (Kafka 3.0+; 10 s before).
Heartbeats are sent by a background thread, so this detects **process crashes, network partitions and frozen JVMs**, not slow processing (that is max.poll.interval.ms).
Trade-off
| Value | Pros | Cons |
|---|---|---|
| short (10 s) | failures detected quickly, partitions reassigned fast | GC pauses or brief network blips cause unnecessary rebalances |
| long (60+ s) | tolerant of pauses | a crashed consumer's partitions sit unprocessed longer |
The value must lie between the broker's group.min.session.timeout.ms (6 s) and group.max.session.timeout.ms (30 min).
Static membership
With group.instance.id set, a consumer that restarts (e.g. a Kubernetes pod during a rolling deploy) and rejoins **within** session.timeout.ms gets its old partitions back **without a rebalance**. Teams often raise the session timeout to 1–5 minutes with static membership.
group.instance.id=payment-consumer-0 # stable per pod, e.g. StatefulSet name
session.timeout.ms=120000
heartbeat.interval.ms=10000
Clean shutdown
consumer.close() sends a LeaveGroup request so the rebalance starts immediately rather than after the timeout (static members do not send it, by design).
Summary
session.timeout.ms is the heartbeat silence after which a consumer is considered dead; balance fast failure detection against false alarms, and use static membership to avoid rebalances on restarts.
