Hi Dipanshu Juneja,
Your FastAPI app runs a background task after sending a response. On Google Cloud Run, the task finished fine because the instance stayed active. On Azure, you still want auto-scaling, but need to make sure background tasks finish before the instance shuts down.
In Azure Container Apps, the CPU turns off after a request, unless always-on is set. This makes using background tasks like FastAPI’s background task risky, as the instance might shut down before the task finishes.
Azure App Service (in Premium Plan or above) keeps the app running consistently, supports background tasks, and behaves similarly to Cloud Run with CPU always allocated.
Use Azure App Service
if your FastAPI app
requires background tasks to finish after the request, ensuring the tasks run without interruption. It keeps the app active with the always-on setting
, ensuring CPU availability
after the request. Additionally, it supports auto-scaling
and works well with both container-based
and code-based
FastAPI deployments.
Background jobs guidance - Azure Architecture Center | Microsoft Learn
Please accept as "Yes" if the answer provided is useful, so that you can help others in the community looking for remediation for similar issues.
Let me know if you have any further Queries.