Choosing between Azure container apps and App service for background task app

Dipanshu Juneja 20 Reputation points
2025-04-25T15:02:01.51+00:00

I currently have a Fastapi app which runs a Fastapi BackgroundTask in one of the endpoint that was earlier deployed using Google cloud run with the CPU always allocated setting which was working well. Now I want to deploy this on Azure and I'm wondering how should I deploy this app on Azure in a way that it does autoscale based on traffic but also guarantees that the background task which is started after a response is returned from server, is completed before the inactive instance (which is not receiving further requests) is shut down. Based on my understanding so far, instead of Azure container apps, I should be using Azure app service for this. So, can I say if I want the behavior of google cloud run cpu always allocated, the similar alternative is Azure app service but if I want the behavior of google cloud run cpu allocated only during request processing option, the alternative is azure container apps?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,755 questions
{count} votes

Accepted answer
  1. Prabhavathi Manchala 1,215 Reputation points Microsoft External Staff Moderator
    2025-04-25T19:25:24.4333333+00:00

    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.

    https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal#configure-general-settings

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.