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…

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.


Print Share Comment Cite Upload Translate
APA
Kamini Kamal | Sciencx (2024-03-29T11:42:26+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 2024-03-29T11:42:26+00:00,<https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/>
VANCOUVER
Kamini Kamal | Sciencx - » Understanding the Retry Pattern. [Internet]. [Accessed 2024-03-29T11:42:26+00:00]. Available from: https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/
CHICAGO
" » Understanding the Retry Pattern." Kamini Kamal | Sciencx - Accessed 2024-03-29T11:42:26+00:00. 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: 2024-03-29T11:42:26+00:00]
rf:citation
» Understanding the Retry Pattern | Kamini Kamal | Sciencx | https://www.scien.cx/2023/02/17/understanding-the-retry-pattern/ | 2024-03-29T11:42:26+00:00
https://github.com/addpipe/simple-recorderjs-demo