Video in progress
Can a long GC pause in one service turn into an incident across the whole distributed system? Through what mechanisms, and how do you protect against it?
Yes. During the pause the instance sends no heartbeat, requests time out and clients retry; as a result leader election, a Kafka rebalance and a retry storm begin. The protection is making timeouts and retries resilient to pauses, and shortening the pauses themselves.
📖 Answer
In one incident a 3-second Full GC started a chain like this: it was kicked out of the Kafka consumer group, the rebalance stopped the other consumers too, upstream services retried 3 times each after their timeouts, the load went up 4 times, and the neighboring instances also fell into Full GC.
The usual mechanisms:
- Heartbeats and leases. Kafka (
session.timeout.ms,max.poll.interval.ms), ZooKeeper/etcd leases, Hazelcast/Akka clusters. If the pause is longer than the lease, the node is considered "dead". - Two leaders. The old leader comes out of the pause, still thinks it is the leader and keeps writing. Without fencing tokens, data gets corrupted.
- Retry amplification. 3 retries at each layer is 27 times across 3 layers.
- The load balancer. An instance that fails the health check is removed, the load goes to the others, and they get heavy too.
The layers of protection:
- The pauses themselves: the maximum pause from the GC log, switching the collector if needed, heap headroom.
- Matching timeouts to the pause: session/lease timeouts noticeably larger than the worst pause you have seen, but still acceptable for detection time.
- Retries: a budget (for example, no more than 10% of requests), exponential backoff with jitter, and at only one layer.
- Circuit breakers and load shedding protect the neighboring instances.
- A fencing token or a versioned write for leadership.
A chaos test is useful for checking: freeze an instance with kill -STOP for 5 seconds and then kill -CONT. This imitates a GC pause very well and shows where the system breaks.
Sign up to mark studied questions and save your progress.