July 6, 2023

Runtime Configuration Reloading in Azure

IT Tips & Insights: A Softensity Software Engineer walks through some functions in Azure App Configuration.

By Paweł Ruciński, Software Engineer 

Azure App Configuration

Any application needs a way to store its configuration properties. And to access its own database. And the secret information for user authentication. And so on, and so on. There are multiple ways to do this on Microsoft Azure Cloud. One of them is to use the Azure App Configuration service. As docs says: 

“Azure App Configuration provides a service to centrally manage application settings and feature flags.”

It provides a wide range of functionalities, starting with storing simple key-value entries. Applications can access those values by using a dedicated NuGet package and providing a connection string/access key. Another important functionality is sending events on each value change.

Event Grid

Whenever a configuration value will be changed, we want to reload the internal configuration dictionary within application runtime. To be able to do this, we need an event broker. Again, as docs says:

“Event Grid is a highly scalable, serverless event broker that you can use to integrate applications using events.”

In our scenario, we need an Azure App Configuration subscription inside the Event grid, which will be an endpoint to notify about any key-value changes. Then we will be able to attach applications to this subscription to receive events at runtime.

Azure Functions

Each application needs its own hosting platform. There are plenty of them to use, including Azure Functions. 

“Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs. Instead of worrying about deploying and maintaining servers, the cloud infrastructure provides all the up-to-date resources needed to keep your applications running.”

Working with Functions is devoid of thinking too much about infrastructure. This means developers can focus more on providing value for the product, and less on struggling with things they usually don’t like.

Design

For this short exercise we will use Azure Functions as a hosting platform. Within Azure Function App we will define two functions (you can think about it as a web endpoint). The first one will be a webhook for reacting on events coming from Event Grid, which originally comes from Azure App Configuration service.

This way, we can have multiple hosting platforms connected to the same configuration source, even written in different technologies. The only requirement is to implement Event Grid listener.

Example

After setting up all resources on the Microsoft Azure Platform, we need an Azure Function implementation to react on events coming from the Event Grid. There is a dedicated trigger for Event Grid Events.

With this in place, we are ready to react on each event that will come from Event Grid. First of all we should filter by event type equal to “Microsoft.AppConfiguration.KeyValueModified”. Later we should only react to an event that was triggered by changing the Sentinel key that we recognize.

After all those validations, we can set cached configurations dirty and try to refresh all configuration values.

Sources:

https://learn.microsoft.com/en-us/azure/azure-app-configuration/concept-app-configuration-event

https://learn.microsoft.com/en-us/azure/azure-app-configuration/howto-app-configuration-event

https://learn.microsoft.com/en-us/azure/azure-functions/event-grid-how-tos

https://learn.microsoft.com/en-us/azure/azure-functions/functions-event-grid-blob-trigger?pivots=programming-language-csharp

About

My name is Paweł Ruciński. I have been a .NET backend developer for about 9 years. I’m mainly interested in Azure Cloud technology and microservices architecture. I have experience working with Service Fabric or Azure Functions, but I also know some basics of Docker and  Kubernetes.

Join Our Team

BACK TO MAIN PAGE

Let’s Talk