Why Azure Functions ?
Technical reasons
Data type format.
Get a JSON format to send to a database receiving a JSON format. A Web Service could return data in JSON format and Azure Function could easily act as intermediary in order to send data to a database (using semi-structured data type like Azure Cosmos DB).Process file uploads.
Process files into or out of a Blob Storage container. We can use a blob trigerred function to validate, transform and process files into the main system as they’re uploaded : Azure Functions Scenarios | Microsoft LearnReal-time stream & event processing.
Process data in near real-time as the hot path, the store it in Cosmos DB for use in an Analytics dashboard. Function can also use low-latency event triggers (like Event Frid) and real-time outputs like SignalR to process data in near real-time : Azure Functions Scenarios | Microsoft LearnMachine learning and AI.
Can be used to infer on models. Also, can connect to other services to help process data and performother AI-related tasks (like text summarization) : Azure Functions Scenarios | Microsoft LearnRun scheduled tasks.
Run code based on a cron schedule we define like analyze data for duplicate entries every 15 minutes to avoid multiple communications between systems : Azure Functions Scenarios | Microsoft LearnBuild a scalable web API.
HTTP endpoint can run function code that can connect to other services directly or by using binding extensions. Can also use an HTTP trigerred function endpoint as a webhook integration (like Github webhooks) - so we can process data from Github events for example : Azure Functions Scenarios | Microsoft LearnBuild a serverless workflow.
Used as compute component is a serverles workflow and can create long-running orchestrations using the Durable Functions extension : Azure Functions Scenarios | Microsoft LearnRespond to database changes.
Process where we might need to log, audit or perform some other operation when stored data changes and function triggers provide a good way to get notified of data changes : Azure Functions Scenarios | Microsoft LearnCreate a reliable message systems.
Use with Azure Messaging to create advanced event-driven messaging solutions. So, use triggers on Azure Storage queues as a way to chain a series of function executions or a Services Bus queues : Azure Functions Scenarios | Microsoft Learn
Cost reasons
In some cases, we are only billed for the time our function code runs (Consumption plan).
Existing different hosting plans : validate the service limits : Azure Functions scale and hosting | Microsoft Learn
Consumption plan : As default plan, Scale automatically & only pay for compute resources when functions are running.
Premium plan : Only charged for each instance allocated in the minimum instance count regardless if functions are executing or not. Automatically scales based on demand using pre-warmed workers which run apps with no delay after being idle and connects to virtual networks (See how to integrate function app in VNET - Use private endpoints to integrate Azure Functions with a virtual network | Microsoft Learn).
Dedicated plan : Best for long-running scenarios where Durable Functions can’t be used and need to consider an App Service Plan in
when we have underutilized VMs that are already running other App Service instances;
when predictive scaling and costs are requires.