This is a continuation of a series of articles
on Azure services from an operational engineering perspective with the most
recent introduction to Azure Function core tools with the link here. This article discusses Azure Functions best
practices.
When we want code to be triggered by events,
Azure Functions become very useful because it is a compute-on-demand
experience. It extends the existing Azure App Service platform with
capabilities to implement code triggered by events occurring in Azure, in
third-party service, and in on-premises systems. Functions can be built to be
reactive, but they are also useful to process data from various data sources.
Functions are hosted in environments that like VMs are susceptible to faults
such as restarts, moves or upgrades. Functions may also have the same
reliability as the APIs it invokes. But functions can scale out so that they
never become a bottleneck. The article details some of the best practices for
designing and efficient function apps.
A function app must have a proper
hosting plan. There are three basic
plans available which include: Consumption plan, Premium plan, Dedicated (App
Service) plan. Function apps work on both Linux and Windows so the hosting
plans are generally available (GA) on both. The hosting plan chosen determines
the following behaviors:
-
How the function
app is scaled based on demand and how instances allocation is managed
-
The resources
available to each function app instance
-
The support for
advanced functionality, such as Azure Virtual Network connectivity
Functions provide a limited range of
options to switch hosting plans so proper choice at the time of function
creation matters.
Functions require a storage account to
be associated with a function app. The
storage account connection helps the functions to manage triggers and log
entries. It is also used when dynamically scaling out the function apps. Proper
configuration helps with the reliability and the performance of the function
apps.
There are settings that determine
whether the function application is run from the Azure Files endpoint or from
the file servers. ARM templates with proper settings are available for
Consumption plan, Dedicated plan, Premium plan with VNET integration and
Consumption plan with a deployment slot.
Large data sets require special
handling. For this purpose, extra storage can be mounted as a file share.
A solution can comprise of multiple
functions. Their deployment can be authored via a DevOps release. All functions
in a function app are deployed at the same time. When the functions are run
from a deployment package, it can be deployed directly to production and reduce
cold start times.
Continuous deployment is required for source
control solution. A warmup trigger can reduce latencies when new instances are
added. Deployment downtimes can be minimized, and rollbacks can be enabled when
using deployment slots. These are some strategies for successful deployments.
Several design principles can come
helpful to writing reliable robust functions. These include avoiding long
running functions, planning cross function communication, writing functions to
be stateless, and writing defensive functions.
No comments:
Post a Comment