Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use ExponentialBackOffPolicy vs FixedBackOffPolicy when setting retry policy for a kafka consumer in a Spring boot app?

When to use ExponentialBackOffPolicy vs FixedBackOffPolicy when setting retry policy for a kafka consumer in a Spring boot app?

I see FixedBackOffPolicy as an implementation of BackOffPolicy that pauses for a fixed period of time before continuing and ExponentialBackOffPolicy as an implementation of BackOffPolicy that increases the back off period for each retry attempt in a given set.

Apart from this, FixedBackOffPolicy extends StatelessBackOffPolicy whereas ExponentialBackOffPolicy don't. In this aspect, Please help me understand, what are the appropriate use cases to prefer one over the other?

like image 787
Raj Avatar asked Jan 31 '26 04:01

Raj


1 Answers

It's pretty straightforward; FixedBackOffPolicy needs no state because you wait for the same interval between each retry, e.g. 5 seconds.

E.g. 5s, 5s, 5s, ...

With the ExponentialBackOffPolicy state is maintained between retries.

E.g. with an initial interval of 1s, a multiplier of 2.0 and max interval of 10s the retry intervals will be 1s, 2s, 4s, 8s, 10s, 10s, 10s, ...

With Kafka you need to be sure that the aggregate of the retry intervals is less than max.poll.interval.ms.

like image 184
Gary Russell Avatar answered Feb 01 '26 18:02

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!