Track: APIs and back end · Lesson 37 of 41 · 15 min
Resilience: timeouts, retries, caching and graceful degradation
What happens when a dependency is slow or down: timeouts, retries, circuit breakers, stale caches and graceful degradation — scenarios for QA.
Dependencies always fail
The payment gateway, the shipping service, search, recommendations — sooner or later each one responds slowly or not at all. The question isn't "will it fail" but "what will the user see".
Failure scenarios
| Scenario | How to simulate | Expected |
|---|---|---|
| Service doesn't respond | A mock returning 503 or a stopped container | A clear message; the rest of the page works |
| Service is slow | A mock with a 30 s delay | Our timeout fires in reasonable time; the UI doesn't hang |
| Intermittent errors | A mock that returns 500 every other time | Limited retries with backoff, no duplicate actions |
| Invalid response | A mock with broken JSON | The error is handled, not a 500 for the user |
| Network drops mid-request | Offline throttling in DevTools | State isn't corrupted; the user can retry |
How to substitute dependencies is covered in test data and environments.
Timeouts
Every call to an external service has a timeout. Without one, a single slow service eats all the server's threads and everything goes down. The check: a mock with a very long delay — the request must fail within a defined time instead of hanging for minutes.
Retries
- Only safe operations are retried: reads, or idempotent requests with a key.
- The pauses between attempts grow (exponential backoff) — otherwise retries finish off an already overloaded service.
- The number of attempts is limited.
A dangerous defect: retrying a non-idempotent POST /payments → a double charge. How to check it is in the automation track.
Circuit breaker
If a service keeps failing, a "breaker" temporarily stops calling it and immediately returns a fallback, then tries again after a while. For QA: after a series of errors, calls to the service stop (visible in the logs), and after recovery they resume on their own.
Caching
| Risk | Check |
|---|---|
| Stale data | Change a price in the admin panel — how long does the user see the old one? Does that match the requirement? |
| Someone else's data from the cache | Pages with personal data are never cached and shared across users |
| The cache hides an outage | The service is down but data is "there" — will monitoring notice? |
| Cold start | After the cache is cleared, the system still handles the load |
Graceful degradation
A good system loses features piece by piece: recommendations are down — the catalog works; search is down — there's navigation; the shipping service is down — you can still choose store pickup. For each critical page, ask: which dependency should it still work without? — and test that.
Spotting these problems in production goes together with performance testing and monitoring.
Key takeaways
- Every external call has a timeout; a slow dependency must not hang the system.
- Only safe or idempotent operations are retried, with backoff and an attempt limit.
- For every page, decide which dependencies it must still work without.
Check yourself
1. Why can't you simply retry any failed request?
2. What does a circuit breaker do after a series of service errors?
3. Which caching problem is the most dangerous?