Implement graceful degradation handlers based on these patterns. Example 1 - Vector DB Timeout: Scenario: Pinecone query exceeds 500ms timeout Degradation: Fall back to keyword search with BM25 Code: ```python async def query_with_fallback(query: str): try: return await asyncio.wait_for(vector_search(query), timeout=0.5) except asyncio.TimeoutError: logger.warning("Vector search timeout, using BM25 fallback") return keyword_search(query) ``` Example 2 - LLM Rate Limit: Scenario: OpenAI returns 429 rate limit error Degradation: Switch to smaller model with exponential backoff Code: ```python @retry(stop=stop_after_attempt(3), wait=wait_exponential(min=1, max=10)) async def generate_with_fallback(prompt: str): try: return await call_gpt4(prompt) except RateLimitError: return await call_gpt35(prompt) ``` Now implement degradation for: Scenario: {{failure_scenario}} Service: {{service_name}} SLA Requirements: {{sla_requirements}}
Few-Shot Graceful Degradation Implementation
U
@
Pattern-based graceful degradation implementation with fallback strategies
30 copies0 forks
Details
Category
CodingUse Cases
Fault tolerance codingResilience patternsError handling
Works Best With
claude-sonnet-4-20250514gpt-4o
Created Shared