Azure Functions:
This is a continuation of a series of articles on
Azure services from an operational engineering perspective with the most recent
introduction to Azure Functions with the link here. This article continues to discuss Azure
Functions best practices with focus on retry and error handling.
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 previous articles discussed the best practices
around security and concurrency. This article continues with some of the other
best practices such as availability and monitoring.
Intermittent failures can be overcome with retries. For example, a database may not be reachable within the limited timeout that is usually set for scripts. Nested commands can be called that might each take their own timeout. Such errors do not occur under normal conditions, so they escape the functional tests. If a limited number of retries were to be attempted, the code executes successfully, and the issue does not recur. Retry also has the side-effect that it reduces the cost of detection and investigation to other spurious errors from logs, incidents and false defects..
Error handling practices is important to avoid loss of data
or missed messages. The recommended error handling best practices include
enabling application insights, using structured error handling, designing for
idempotency, and implementing retry policies. For example, the top most level
of any function code should have a try catch and tge catch block should log
errors.
No comments:
Post a Comment