Dev.to AI 🤖 Ai 👁 0 📖 1 min read

Retry Logic: 10 of 30 Calls OK, Then 30 of 30

Retries look like a free win: if a request fails, try again. I tested what they actually cost with a real Node.js run, and the bill is bigger than it looks. Full run in this Short: https://youtu.be/Ck7Pm2pR_aY

Retries look like a free win: if a request fails, try again. I tested what they actually cost with a real Node.js run, and the bill is bigger than it looks. Full run in this Short: https://youtu.be/Ck7Pm2pR_aY

The setup

A server that fails 2 of every 3 requests, and a client making 30 calls. First with plain fetch, no retries.

Without retries

30 plain fetch calls came back 10 ok, 20 failed. That matches the server's failure rate: with no retry logic, you inherit it. Two thirds of the calls simply fail.

With 3 tries

With up to 3 attempts per call, all 30 calls eventually succeeded: 30 of 30 ok. But the server saw 90 hits instead of 30, and the whole run took 4.6 seconds. Every retried call is another request the server has to absorb, and the wait between tries is time your caller spends blocked.

The rule

Retries trade reliability for load and latency. They fix the caller's view of the world while making the server's worse. If the server is failing because it is overloaded, blind retries push it further over. Use them with a cap, a delay, and a clear idea of which failures are worth retrying. Not tested here: backoff strategies, timeouts, and retrying against a recovering server, all of which change the numbers.

Watch the run

The real terminal output is in the Short: https://youtu.be/Ck7Pm2pR_aY (narration is AI-generated; the test output is from a real run). The full video is here: https://youtu.be/vgoOmh39738

Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.