elastic / elastic-transport-js

Transport classes and utilities shared among Node.js Elastic client libraries
Apache License 2.0
4 stars 24 forks source link

Add exponential backoff to request retries #101

Closed JoshMock closed 1 month ago

JoshMock commented 1 month ago

Uses an exponential backoff algorithm that includes some jitter so that retries are not going to hammer several sequential requests at an Elasticsearch instance that might be failing or trying to catch up. Some random jitter is added to the backoff to ensure a more smooth distribution of retries.

A retryBackoff option is exposed on both the transport constructor and request function, but I'm not planning to document it. Exposing it is primarily to make unit testing easier. (Who would have guessed that testing code that uses time and random numbers would be frustrating?) That said, more advanced users might see value in providing their own backoff algorithm to meet their particular needs.

JoshMock commented 1 month ago

Pinging all my dynamic language friends for a review, mostly because it's interesting. :slightly_smiling_face:

JoshMock commented 1 month ago

Merging mostly so I can get this in before publishing the 8.14 client. We can continue to iterate on the implementation based on how this works, especially once Elastic Cloud SREs start to see a difference in retry handling from Kibana.