Generate Resilient Service Wrapper

Back to prompts
Generate Resilient Service Wrapper
codingintermediateClaudeGPTGemini
automation

Create a defensive wrapper with retries, timeouts, and fallbacks for an unreliable external API or service.

Prompt
Act as a senior backend engineer specializing in resilient system design. I need to create a defensive wrapper/middleware for {{service_name|description}} to protect my automation pipeline against its instability.

CONTEXT & INPUTS:
- Target Service Signature/Code: {{target_code_or_signature}}
- Known Failure Modes: {{failure_modes}}
- Current Usage Pattern: {{usage_context}}
- Constraints/Language: {{language_and_constraints}}

INSTRUCTIONS:
1. Analyze the inputs and flag any missing critical information (e.g., lack of defined failure modes, ambiguous timeout requirements) before proceeding. Do not invent specific behaviors where inputs are unclear.
2. Generate a complete, production-grade wrapper implementation in {{language}} that includes:
   a. Configurable retry logic with exponential backoff and jitter.
   b. Explicit timeout handling per operation type.
   c. Circuit breaker pattern integration to prevent cascading failures.
   d. Structured logging for observability (include log levels and key metadata).
   e. A defined fallback strategy mechanism that I can configure based on success criteria.
3. Provide a usage example showing how to inject this wrapper into a standard call flow.
4. List the trade-offs of the implemented patterns and suggest metrics to monitor in production.

OUTPUT FORMAT:
Return a numbered list containing:
1. The Wrapper Implementation Code.
2. Configuration Block/Interface.
3. Usage Example.
4. Trade-offs and Monitoring Recommendations.

When to use this#

When integrating with a flaky third-party API or unstable internal service that causes intermittent failures in your automation workflows, and you need a production-ready client layer to handle retries, timeouts, and graceful degradation without scattering error-handling logic across every caller.

Tips#

  • Include the exact function signature, class method, or raw HTTP request/response snippet so the model can match types, headers, and serialization precisely.
  • Define the fallback behavior explicitly (e.g., ‘return stale cache’, ‘queue for async processing’, ‘fail loudly with specific error’) rather than letting the model choose a default strategy.
Table of Contents