InterviewHubPRO
Section Overview
Q3

Question 3 of 65

Part 1: Candid Experience, Architecture & Intro (1 - 5)

5%
Python & FastAPI•Part 1: Candid Experience, Architecture & Intro (1 - 5)

Describe a severe Python backend performance bottleneck you resolved.

How to Explain in an Interview:

  • Problem: In a FastAPI ingestion API, request latency jumped from 40ms to 4.2 seconds under heavy load.
  • Root Cause: A developer used synchronous requests.get() and called json.loads() on a 25MB payload inside an async def route, which blocked the AsyncIO Event Loop and froze all other concurrent requests.
  • Fix: Switched to non-blocking httpx.AsyncClient, offloaded heavy JSON parsing to a thread pool with asyncio.to_thread(), and upgraded to orjson (Rust-based fast serializer), dropping response times back to 35ms.
python
# Non-blocking HTTP client with thread-offloaded JSON deserialization:
import httpx
import asyncio
import orjson

async def fetch_and_parse(url: str):
    async with httpx.AsyncClient() as client:
        response = await client.get(url)
        # Offload CPU-heavy parsing away from the main event loop:
        return await asyncio.to_thread(orjson.loads, response.content)