Skip to content

Commit 9bd84ff

Browse files
committed
PB-2395: add a page about retry strategy.
1 parent 096770c commit 9bd84ff

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

get-started/retry.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Retry strategy
2+
3+
For any request that you want to retry automatically, we recommend that you do
4+
so using a jittered exponential backoff algorithm.
5+
6+
## Overview
7+
8+
Any request you make has the possibility to fail for a variety of reasons. It
9+
is your responsibility to decide what to do when this happens. When encountering
10+
transient errors, you will typically want to retry the request. This requires
11+
some care to do correctly as incorrect retry strategies may cause many requests
12+
to be (re)sent in a short amount of time. To mitigate this
13+
[thundering herd problem](https://en.wikipedia.org/wiki/Thundering_herd_problem),
14+
we recommend you implement retries with jittered truncated exponential backoff.
15+
16+
## Jittered truncated exponential backoff algorithm
17+
18+
Here is an example of algorithm that implements the recommended retry strategy:
19+
20+
1. Send a request.
21+
22+
2. Upon retryable failure, wait 1 + `jitter` seconds before retrying.
23+
24+
3. Upon retryable failure, wait 2 + `jitter` seconds before retrying.
25+
26+
4. Upon retryable failure, wait 4 + `jitter` seconds before retrying.
27+
28+
5. Upon retryable failure, wait 8 + `jitter` seconds before retrying.
29+
30+
6. And so on, with a delay of min(2^n + `jitter`, `max_backoff`) seconds
31+
at each iteration.
32+
33+
7. After `deadline` seconds, stop retrying the request.
34+
35+
The `jitter` value must be picked randomly at each iteration. In this example,
36+
it could be a fractional value between 0 and 1 second.
37+
38+
The `max_backoff` value defines the maximum time to wait between retries. You
39+
should pick the highest value your use case can support. If you have no specific
40+
latency requirements, 2^6 (64) seconds should be reasonable in most situations.
41+
42+
The `deadline` value defines how long to keep retrying automatically until you
43+
cancel the request. You should pick a value appropriate to your use case. One
44+
way to think about it is "how long to keep trying until we need to involve a
45+
human?". For example, if you are fetching a tile to display in an interactive
46+
process, there is probably no point retrying for 3 minutes as the user will
47+
have given up or retried manually before that point. On the other hand, if the
48+
request is an automated upload of a dataset, it may be reasonable to retry for
49+
several hours before giving up and alerting a human operator.
50+
51+
## Permanent failues
52+
53+
Some failures are permanent and there is no point in retrying the request that
54+
triggered them (e.g. if you received an HTTP 403 response because you are not
55+
allowed to perform a certain action, retrying will not help). It is your
56+
responsibility to verify the exact response code semantics based on our
57+
documentation before deciding whether to retry.
58+
59+
## Further information
60+
61+
If you have questions about this topic or need assistance in picking appropriate
62+
values in the above algorithm when implementing clients for our systems, you are
63+
welcome to contact us.
64+
65+
You can also find further information in the following references:
66+
67+
* [Wikipedia: Exponential Backoff](https://en.wikipedia.org/wiki/Exponential_backoff#Truncated_exponential_backoff)
68+
* [Google SRE Book: Adressing Cascading Failures: Retries](https://sre.google/sre-book/addressing-cascading-failures/#retires)
69+
* [AWS: Exponential Backoff And Jitter](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/)
70+
* [Google Cloud IAM: Retry failed requests](https://docs.cloud.google.com/iam/docs/retry-strategy)
71+
* [Google: Building Secure and Reliable Systems: Mitigating Denial-of-Service Attacks: Client Retry Behavior](https://google.github.io/building-secure-and-reliable-systems/raw/ch10.html#client_retry_behavior)

0 commit comments

Comments
 (0)