How do you design timeouts across a 3-tier call chain (gateway, API, DB)?
AdvancedScenarioReleases & Reliability Patterns
Answer
Situation read → Timeouts must nest: each caller's timeout greater than the callee's timeout plus retries.
What I'd do →
- Start from the user-facing budget: gateway timeout 10s.
- API timeout to DB: query timeout 2s, with at most 1 retry, so worst case about 4s plus backoff.
- API request timeout: 8s, less than gateway's 10s.
- Propagate deadlines so downstream services stop work when the caller has given up.
- Measure p99.9 latency of each hop to make sure timeouts are realistic.
Why → Mis-nested timeouts cause wasted work and retries after the user has gone.
Interview tip → Draw the nested budget out loud.
More on Releases & Reliability Patterns
A canary at 10% shows a 0.3% higher error rate than stable. Promote or roll back?IntermediateA downstream service is slow, and your service's retries are making it worse.IntermediateYou need to roll out a risky database schema change with zero downtime.AdvancedA feature flag was turned on for 100% of users and caused errors. How do you handle it and prevent recurrence?BeginnerYour service calls five dependencies sequentially, and total latency is too high.IntermediateA third-party API you depend on has rate limits, and you're hitting them during peaks.Beginner