FastAPI BackgroundTasks lost on server restart
warningavailabilityUpdated Mar 25, 2026
Technologies:
How to detect:
Tasks submitted to FastAPI BackgroundTasks are executed in-memory without persistence. If the server restarts, crashes, or is redeployed before task completion, all pending background tasks are lost.
Recommended action:
Use FastAPI BackgroundTasks only for lightweight, non-critical tasks like sending emails. For critical tasks (RAG document ingestion, billing operations), use robust task queues like Celery or Dramatiq with Redis/RabbitMQ broker. These provide persistence, retries, and survive restarts. Architecture: FastAPI produces tasks -> Redis/RabbitMQ brokers -> Celery worker consumes.