Features for FastAPIs
FastAPI features such as middleware and background work extend how requests are handled. Middleware wraps every request and response for tasks like logging, timing or CORS, while BackgroundTasks run small jobs after the response is sent, and heavier work is better moved to a queue such as Celery.
Stage: Data and Features · Part of the FastAPI roadmap · Last reviewed 19 November 2026
What to learn in Features
- Write HTTP middleware that adds a timing header to each response
- Configure CORSMiddleware with specific allowed origins
- Send an email or log entry after the response using BackgroundTasks
- Handle WebSocket connections for simple real-time messaging
- Decide when to use a task queue instead of background tasks
Features interview questions
What are BackgroundTasks good for and when are they not enough?
They run short jobs after the response is returned, such as sending a notification, in the same process. They have no retries, persistence or separate workers, so long or critical jobs should use a queue such as Celery or Arq.
What does middleware do compared with a dependency?
Middleware runs around every request and response and is unaware of the route, which suits logging, timing and headers. A dependency is attached to specific endpoints, can take parameters and its result is passed to the handler.
Where Features fits in the FastAPI roadmap
Features belongs to the Data and Features stage (intermediate level). Real application behaviour.
Other units in this stage
Back to the full FastAPI roadmap