Quizzesasync def vs def — How FastAPI Runs Your Endpoints — Concept Check
intermediate
fastapi

async def vs def — How FastAPI Runs Your Endpoints — Concept Check

Questions on async def vs def — How FastAPI Runs Your Endpoints. def endpoints run in a thread pool (blocking code is safe); async def runs on the event loop (huge concurrency, but one blocking call freezes everyone). The wrong combination is FastAPI's #1 performance bug.

7 minutes 7 questions Pass at 70%
Time Limit
7 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

7 questions on async def vs def — How FastAPI Runs Your Endpoints — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A FastAPI service using async def endpoints is experiencing performance issues under load. What is a likely cause?

    • ABlocking calls inside async def freeze the event loop
    • BInsufficient CPU cores for async operations
    • CIncorrect HTTP method used in endpoints
    • DToo many threads in the thread pool
  2. 2.Which of the following is true about async def endpoints in FastAPI?

    • AThey allow high concurrency by overlapping awaits
    • BThey are always faster than def endpoints
    • CThey automatically optimize blocking calls
    • DThey run in a thread pool by default
  3. 3.A developer changes a def endpoint with blocking I/O to async def without changing the I/O calls. What happens?

    • AThe service becomes faster due to async def
    • BThe endpoint becomes non-functional
    • CThe event loop is blocked, slowing the service
    • DThe thread pool handles the blocking I/O
  4. 4.Which scenario would benefit most from using async def in FastAPI?

    • AA simple dictionary return
    • BBlocking I/O operations
    • CAwaitable I/O operations
    • DA CPU-intensive task
  5. 5.A FastAPI endpoint using async def is freezing under load. What should you check first?

    • AIf the thread pool size is adequate
    • BIf the HTTP method is correct
    • CIf the endpoint is CPU-bound
    • DIf all I/O calls are awaitable
  6. 6.What happens when a blocking call is made inside an async def endpoint?

    • AThe blocking call is automatically optimized
    • BThe event loop is blocked, affecting all requests
    • CThe blocking call is handled by a separate thread
    • DThe event loop continues processing other requests
  7. 7.In FastAPI, when should you use def instead of async def?

    • AWhen handling blocking I/O operations
    • BWhen using awaitable I/O operations
    • CFor all types of operations for consistency
    • DWhen the endpoint is CPU-bound