In enterprise projects, I generally avoid implementing retries directly in the user request, as it can increase response times and create a poor user experience.
My usual approach is:
The most important thing is to separate the API handling into a dedicated integration layer instead of calling external APIs directly from business microflows. This makes retries, logging, monitoring, and future maintenance much easier.
Kindly mark this as the accepted answer if it helps.
Hi Serina Delveen
what you asked is a full end to end implemetation lets divide it into 3 different section so it will be easy to understand, as per your 1st question
Retry Strategy
1.Use 3 retry attempts as the standard not too aggressive, not too passive. Lets say if it holds transactional data like payment ects, It is always better to combine taskqueue and schedulers bez due to 500 series error the system's particular server or node might be failed but the task action might be taken in that case your taskqueue will fail for sure so once the 3 time retry failed mark the status as failed due to server un reach or anything. later use a scheduler to pick those failed task and try again.[ Note: if you are using this make sure that the status is updated properly].
2.Always setup retry at +15s, +30s, +90s intervals and Only retry on transient errors HTTP 429, 500, 502, 503, 504, and timeouts.
3.Never retry on 400, 401, 403, 404 these are permanent failures, retrying wastes cycles.
Async Processing
Pending, Processing, Success, Failed, DeadLetter.Status = Pending AND NextRetryAt <= Now.Logging & Monitoring
RestIntegration) to separate API logs from app logs.INFO for success, WARNING for retry triggered, ERROR for max retries exhausted.Preventing Duplicate Transactions
X-Idempotency-Key).Circuit Breaker Pattern
CircuitBreakerState entity — State (Closed / Open / HalfOpen), FailureCount, OpenedAt.I hope this helps all your question, Need more help in designing this let me know , I can help