GeezerVison is showing github.com — feat: add explanation for exponential backoff strategy with intended … · linuxgg/RxJava-Android-Samples@4b2180f
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: README.md +19Lines changed: 19 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -100,11 +100,30 @@ Cases demonstrated here: |
100 | 100 | 3. run a task constantly every 1s (same as above but there's no delay before the first task fires off) |
101 | 101 | 4. run a task constantly every 3s, but after running it 5 times, terminate automatically |
102 | 102 |
|
| 103 | +### Exponential backoff |
| 104 | + |
| 105 | +[Exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) is a strategy where based on feedback from a certain output we alter the rate of a process (usually reduce the number of retries or increase the wait time before retrying or re-executing a cetain process). |
| 106 | + |
| 107 | +It makes far more sense with examples, and RxJava makes it (relatively) simple to achieve such a strategy. |
| 108 | + |
| 109 | +#### retry (if error) with exponential backoff |
| 110 | + |
| 111 | +Say you have a network failure. A sensible strategy would be to NOT keep retrying your network call every 1 second. It would be smart instead (nay... elegant!) to retry with increasing delays. So you try at second 1 to execute the network call, no dice? try after 10 seconds... negatory? try after 20 seconds, no cookie? try after 1 minute. If this thing is still failing, you got to give up on the network yo! |
| 112 | + |
| 113 | +We simulate this behaviour using RxJava with the `retryWhen` |
| 114 | + |
| 115 | +#### "repeat" with exponential backoff |
| 116 | + |
| 117 | +Another variant of the exponential backoff strategy is to execute an operation repeatedly for a given number of times, but with delayed intervals. So you execute a certain operation 1 second from now, then you execute it again 10 seconds from now, then you execute the operation 20 seconds from now. After a grand total of 3 times you stop executing. |
| 118 | + |
| 119 | +Simulating this behavior is actually way more simpler than the retry mechanism. You can use a variant of the `delay` operator to achieve this. |
| 120 | + |
103 | 121 | ## Work in Progress: |
104 | 122 |
|
105 | 123 | Examples that I would like to have here, but haven't found the time yet to flush out. |
106 | 124 |
|
107 | 125 |
|
| 126 | + |
108 | 127 | ### Pagination |
109 | 128 |
|
110 | 129 | a. Simple pagination |
|