Serverless computing is a relatively newer development in the cloud computing space. In the normal computing scenario, program code resides either on the server or the client. Serverless computing changes this paradigm, with stateless code, i.e. code that does not require any infrastructure.
Customers only have to pay for the compute resources used by the code during the short time that it takes for executing the code, (usually a few seconds or milliseconds) which is very cost effective. These code snippets that perform specific tasks are called functions.
Azure Functions is the serverless computing service on the Azure platform that provides Function as a Service (FAAS) feature to customers. Azure Functions is very tightly integrated with Azure Cosmos DB.
Cosmos DB triggers are procedural codes that run automatically when a database event such as insert, update or delete occurs.
There are three ways in which Azure Functions can be used with Azure Cosmos DB for serverless computing:
- Cosmos DB Trigger: This option is for invoking an Azure Function based on changes in Cosmos DB container. When a change is made to a container in Cosmos DB, the Cosmos DB change feed stream is sent to the Cosmos DB trigger, the trigger then invokes the Azure function.

- Input Binding: Once input binding is created; Cosmos DB trigger can be used to invoke a function. When the function executes, data is read from Cosmos DB container.

- Output Binding: If a function is bound to an Azure Cosmos DB container using output binding, data is written to the container when the function executes.

Currently, only SQL API is supported for all three of the above options.
One thought on “Serverless Database Computing: Azure Cosmos DB Triggers and Azure Functions”