Menu

1 / 2

How a REST Client Should Handle 503 Service Unavailable: Retries with Backoff in Spring

DEV Community: java·Moises Gamio·15 days ago
#7YvPSIfO
#devtojava#devto#dev#retry#server
Reading 0:00
15s threshold

Your nightly job sends 50,000 articles to a partner's API, in batches of 1,000. At batch 23, the API answers 503 Service Unavailable . What should your client do? Give up, and the data is incomplete. Retry immediately, and you make an overloaded server even slower. This post shows how a REST client should handle a 503: which errors to retry, how long to wait, and how Spring Framework 7 does it with one annotation.

What a 503 Means

The HTTP status code 503 Service Unavailable says that the server can't handle the request right now , but probably will later. Common causes:

The server is down for scheduled maintenance.

The server is overloaded by too much traffic.

A service the server depends on, such as a database or another API, is failing.

The server may add a Retry-After header that says how long to wait. The important word is temporarily : a 503 is an invitation to try again later, not a final answer.

The Client Can't Control the Server

Business-to-business ( B2B ) integrations are a typical case.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.