How would you use BackgroundTasks to run work after returning a 201?
What it tests: FastAPI deferred execution and failure modes. A strong answer injects BackgroundTasks, adds the task, returns 201, and notes same-process post-response execution with no persistence. Red flag: Treating it as a distributed queue like Celery.
What it tests: FastAPI request lifecycle and lightweight background work trade-offs. A strong answer injects BackgroundTasks, calls add_task with the email function and its arguments, returns 201 immediately, and explains that Starlette runs the task in the same process only after the response is sent. Limitations include no persistence across crashes or restarts, no built-in retries, and worker blockage during CPU-heavy work. Red flag: Confusing BackgroundTasks with a persistent broker like Celery or RQ.
Read the original → fastapi.tiangolo.com
- #fastapi
- #background-tasks
- #python
- #async
- #starlette
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.