Search code examples
circuit-breakerresilience4j

Resilience4j Retry: Should you create singleton of Retry or create new one for every request?


As the title suggests, how should I implement Retry for multiple requests? I noticed that for every Retry, you must specify some Retry ID.

// Create a Retry with default configuration
Retry retry = Retry.ofDefaults("id");

How does the ID affects the execution? Will it affect concurrent requests using the same Retry ID?


Solution

  • A single instance is sufficient. It won't affect concurrent requests. You can use the name of the service (backend system) which you want to protect as the ID, for example.