AI Engineer Portal
Your personal operating system for career transition.
Exercise
Implement graceful degradation with fallback tiers
Implement Graceful Degradation with Fallback Tiers
Production AI services fail in partial ways: the primary LLM provider might be rate-limited, the secondary might be slow, and the semantic cache might have a miss. A well-designed system handles these failures without completely breaking user-facing functionality.
The key pattern is explicit degradation tiers — a ranked list of response strategies, from best to worst.
What to build
Implement a DegradationManager that:
- Takes an ordered list of
ResponseTierobjects:name: str,handler: async callable,timeout_seconds: float,is_acceptable: bool. serve(request: dict) -> DegradedResponse— tries tiers in order, returns the first success. If a tier fails (exception or timeout), log and move on.DegradedResponsehas:content: str,tier_used: str,is_degraded: bool,latency_ms: int,tiers_attempted: list[str].- If all tiers fail, return a
DegradedResponsewith the staticULTIMATE_FALLBACK_MESSAGE,is_degraded=True. get_stats() -> dict— return call counts and success rates per tier.
Test with three tiers
- Tier 1 (primary LLM): Fast, high quality,
is_acceptable=True— but times out on first calls. - Tier 2 (cached): Returns a cached response.
is_acceptable=False(degraded). - Tier 3 (template): Returns a static template.
is_acceptable=False(degraded).
Constraints
- Standard library + asyncio only.
- Each tier must respect its
timeout_secondsusingasyncio.wait_for.
Api Async / hard / Step 12 of 23
Async and provider control
Make waiting behavior explicit. Timeouts, retries, and concurrency limits matter more than squeezing everything into one helper.
- - Uses async boundaries coherently
- - Makes timeout and retry decisions legible
- - Would be maintainable under provider instability
- - Is timeout behavior explicit?
- - Is retryable failure separate from terminal failure?
- - Would logs reveal what actually timed out?
Practice
Generate a variation
Generate a new exercise variation to deepen understanding or practice a related concept.
Attempt history
Recent submissions
Before you submit, decide what a strong answer should make obvious to the reviewer.
No attempts yet.