Build a FastAPI service with Pydantic request validation, retry logic, timeout handling, and robust error handling.
Asked in the Hands-on + System Design stage. Implement the service logic as a dependency-free function so it can be tested without running FastAPI.
process_request(request, downstream_results) accepts a request dictionary and a deterministic list of simulated downstream outcomes. Return a dictionary containing status_code, attempts, and either body or detail. Validate target_url, payload, max_retries, and timeout_seconds; retry timeouts, HTTP 429, and 5xx responses.
def process_request(request, downstream_results):