Reputation: 1
I am implementing the server side of my app in azure functions. I usually make a lot of smaller private functions(e.g parsing data) to keep my code clean and improve usability and readability but working in azure functions is making me wonder what are the best practices in the current scenario.
Should I make smaller private functions and do they incur additional cost when called from my main http trigger functions or should I put all code in the http trigger function? The latter seems like a very unintuitive approach.
Upvotes: 0
Views: 282
Reputation: 29711
You pay for each invocation, that is when the trigger is fired. The amount is based on time and memory usage. It is up to you whether you want to have a 300 line function method or a smaller with which class other private methods as they don't play a role in pricing. A single, large method won't consume more resources/increase the costs than several smaller methods.
Azure Functions consumption plan is billed based on per-second resource consumption and executions. Consumption plan pricing includes a monthly free grant of 1 million requests and 400,000 GB-s of resource consumption per month per subscription in pay-as-you-go pricing across all function apps in that subscription.
and
Functions are billed based on observed resource consumption measured in gigabyte seconds (GB-s). Observed resource consumption is calculated by multiplying average memory size in gigabytes by the time in milliseconds it takes to execute the function. Memory used by a function is measured by rounding up to the nearest 128 MB, up to the maximum memory size of 1,536 MB, with execution time calculated by rounding up to the nearest 1 ms. The minimum execution time and memory for a single function execution is 100 ms and 128 mb respectively. Functions pricing includes a monthly free grant of 400,000 GB-s.
Upvotes: 1