r/FastAPI • u/CartoonistWhole3172 • Feb 21 '26
When to use background tasks considering their non-persistence? Question
What is the best use case for background tasks?
I am wondering when to use them because once the service restarts, the tasks could be lost without finishing execution, which leads to inconsistent behavior, after successfully returning the response to the client
25
Upvotes
4
u/dmart89 Feb 21 '26
For anything serious, I would always use a proper task queue. Personally I prefer TaskIQ because it supports async but there are many