Is it recommended to run azure function for long time

Sneha N. Patil 45 Reputation points
2025-03-05T07:30:30.2666667+00:00

Hi team,

We are developing a function for data migration from an SQL database to Azure Blob Storage. We intend to run the migration for 5 hours daily. Our Azure Function is hosted on the Premium plan, which allows us to configure the timeout. However, I'm uncertain whether the function should run continuously for the entire 5 hours or if it should be triggered periodically, such as every 15 minutes with a timeout of 10 to 14 minutes.
Could you please help me to know which is efficient approach?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,515 questions
{count} votes

Accepted answer
  1. Sai Prabhu Naveen Parimi 320 Reputation points Microsoft External Staff
    2025-03-06T06:37:29.37+00:00

    Sneha N. Patil,

    Thank you for your insightful questions regarding the cost implications of long-running Azure Functions on a Premium V3 App Service Plan. I appreciate your curiosity and interest in understanding Azure’s pricing model in depth.

    While it is correct that in dedicated compute tiers (such as Premium V3), the cost is based on the number of VM instances rather than execution time, long-running functions can still result in higher costs and inefficiencies due to the following reasons:

    1. Resource Consumption

    A long-running function monopolizes VM resources, potentially limiting the capacity for other applications or functions running on the same instance. If additional workloads require processing, you may need more powerful or additional VM instances, increasing costs.

    1. Scaling and Overhead

    Although the Premium Plan does not enforce automatic scaling for Azure Functions, a continuously running function can impact your scaling strategy. If other workloads need to run in parallel, this could lead to additional instances being allocated, indirectly increasing costs.

    1. Failure and Retries

    If a long-running function fails after several hours, you may need to restart the entire process, leading to wasted compute time and operational inefficiencies. Breaking down the workload into smaller executions minimizes the risk of losing significant processing time.

    Alternative Approach

    Instead of running a single function continuously for 5 hours, it would be more efficient and reliable to trigger it periodically in smaller, manageable batches (e.g., every 15–20 minutes). This approach:

    • Reduces failure risks and prevents large reprocessing efforts.
    • Improves monitoring, debugging, and system responsiveness.
    • Optimizes resource usage while ensuring cost-effectiveness.
    • Reference: Durable Functions for Long-Running Workflows

    I hope this explanation provides clarity. Please feel free to reach out if you have any further questions!


1 additional answer

Sort by: Most helpful
  1. Abiola Akinbade 24,015 Reputation points
    2025-03-05T07:47:24.2633333+00:00

    Hello Sneha N. Patil,

    Thanks for your question.

    Simply put, It is best to run periodically with functions.

    Instead of running the function for a full 5 hours non-stop, it’s better to process the data in smaller batches, triggering the function every say for example 15-20 minutes or depending on your app requirements.
    If a 5-hour function fails, you might have to restart everything.

    See relevant links to assist you:

    Azure Functions best practices

    Azure function timeout

    Durable Functions

    You can mark it 'Accept Answer' and 'Upvote' if this helped you

    Regards,

    Abiola


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.