Why is random jitter applied to back-off strategies?

Will_of_fire picture Will_of_fire · Oct 25, 2017 · Viewed 7.3k times · Source

Here is some sample code I've seen.

int expBackoff = (int) Math.pow(2, retryCount);
int maxJitter = (int) Math.ceil(expBackoff*0.2);
int finalBackoff = expBackoff + random.nextInt(maxJitter);

I was wondering what's the advantage of using a random jitter here?

Answer

Dale Wilson picture Dale Wilson · Oct 25, 2017

Suppose you have multiple clients that send messages that collide. They all decide to back off. If they use the same deterministic algorithm to decide how long to wait, they will all retry at the same time -- resulting in another collision. Adding a random factor separates the retries.