Understanding the Retry Pattern

What is the retry pattern — and how to implement it in a microservices architecture?While dealing with a cloud environment, we come across software, hardware, and network errors which ultimately led to delays, timeouts, and failures in the system. In c…


This content originally appeared on Bits and Pieces - Medium and was authored by Kamini Kamal

What is the retry pattern — and how to implement it in a microservices architecture?

While dealing with a cloud environment, we come across software, hardware, and network errors which ultimately led to delays, timeouts, and failures in the system. In case of transient failures such as network loss, temporary unavailability of a microservice, timeouts, etc, which are self-recoverable and temporary, we have the option to retry and check if the requests are served.

Retry mechanism

Strategies for implementing Retry mechanism

  1. Fixed Delay: Setting a fixed interval to send retry requests every time we get an error. For example, RetryDelay(i) = 100 [ms] for each subsequent retry.
  2. Incremental Delay: Incrementally increasing the delay with each retry. For example, RetryDelay(i) = 100*i [ms] which increases for subsequent requests.

3. Exponential BackOff: Exponentially setting the delay based on the requirement of the system. For example, RetryDelay(i) = t = 100 * 2 ^(i-1) [ms]

Considerations

  1. Errors should be transient, temporary, and recoverable.
  2. The delay or backoff strategy to be used depends on the requirements of the microservice.
  3. Randomization/Jitter between the retries can be introduced to distribute traffic more evenly in healthy instances.
  4. It is safe to retry on the idempotent requests to trace the errors.

Ways to implement Retry mechanism

  1. Library to be shared among microservices
💡 Besides creating a library for the retry logic, you can also use an open-source toolchain like Bit for sharing and managing the retry logic as reusable components making it easier to share, version, and test the code. Moreover, you can also integrate the retry logic with other reusable components from the Bit ecosystem, and update the code more easily across multiple microservices. Find out more here, and here.

Creating one common library and sharing among the services can be a way to reuse the logic. In this case, the services will decide which retry strategy to follow at the application runtime.

2. Ambassador Sidecar pattern on each individual microservices

In this case, each microservice can implement its own retry logic and deploy it as a sidecar. The individual microservices are responsible for the maintenance of the logic as there is no shared instance for the retry implementation.

Each individual microservice can have its own ambassador sidecar for the retry logic

Accounting the failures and monitoring the requests

The requests sent to different services can be subject to different policies and the application should log the details of faults and failing operations. At times, the monitoring tools might get flooded with failure alerts, we need a mechanism to log early failures. It is best to log early failures as informational entries and only the failure of the last of the retry attempts as an actual error.

If a service is constantly busy or failing possibly because the allocated resources got exhausted, it is high time to scale out the service.

References

Summary

In this article, we learned about the Retry pattern and also the ways to implement it on the microservices architecture. We will continue exploring more in future articles.

Thank you ❤️ for reading this article, feel free to Subscribe, clap👏🏻 and share it.

Build Apps with reusable components, just like Lego

Bit’s open-source tool help 250,000+ devs to build apps with components.

Turn any UI, feature, or page into a reusable component — and share it across your applications. It’s easier to collaborate and build faster.

Learn more

Split apps into components to make app development easier, and enjoy the best experience for the workflows you want:

Micro-Frontends

Design System

Code-Sharing and reuse

Monorepo

Learn more:


Understanding the Retry Pattern was originally published in Bits and Pieces on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Bits and Pieces - Medium and was authored by Kamini Kamal


Print Share Comment Cite Upload Translate Updates
APA

Kamini Kamal | Sciencx (2023-02-17T14:31:30+00:00) Understanding the Retry Pattern. Retrieved from https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/

MLA
" » Understanding the Retry Pattern." Kamini Kamal | Sciencx - Friday February 17, 2023, https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/
HARVARD
Kamini Kamal | Sciencx Friday February 17, 2023 » Understanding the Retry Pattern., viewed ,<https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/>
VANCOUVER
Kamini Kamal | Sciencx - » Understanding the Retry Pattern. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/
CHICAGO
" » Understanding the Retry Pattern." Kamini Kamal | Sciencx - Accessed . https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/
IEEE
" » Understanding the Retry Pattern." Kamini Kamal | Sciencx [Online]. Available: https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/. [Accessed: ]
rf:citation
» Understanding the Retry Pattern | Kamini Kamal | Sciencx | https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.