JavaScript · Async JavaScript · Tech Lead · Architecture
Design resilience for a JS client that depends on flaky upstream APIs (timeouts, retries, backoff, idempotency).
Short Interview Answer
Combine timeouts, bounded exponential backoff with jitter, idempotency keys for safe retries, circuit breaking, and clear user-facing degradation.
Detailed Explanation
Specify per-request timeouts (AbortController). Retry only idempotent/safe operations or those with idempotency keys. Use exponential backoff + jitter to avoid thundering herds. Circuit breakers stop hammering a failing dependency; bulkheads isolate critical flows. Surface partial UI with stale-while-revalidate where acceptable. Centralize HTTP policy in one client (not ad-hoc per call). Observe with metrics (success rate, p95 latency, retry counts). Document which errors are retryable. At lead level, align with backend SLAs and rate limits, and decide UX for offline/queueing.
Interview Tip
Name jitter and idempotency — strong lead signals.
Common Mistake
Blindly retrying POST that creates duplicates.