Skip to content

Serverless geo-replicated event-based architecture sample for Azure Friday

License

Notifications You must be signed in to change notification settings

ealsur/serverlessazurefriday

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Serverless geo-distributed event-based architecture with Azure Cosmos DB and Azure Functions

Serverless geo-distributed event-based architecture sample

Video

This repository was part of an Azure Friday episode, you can view it below:

Watch the Azure Friday episode

This repository contains a sample architecture that can be deployed across multiple regions and leverage Azure Cosmos DB's Multi master and Change feed features to achieve:

  • Local writes on all Azure Function regions
  • Real-time notifications provided by the Change feed
  • Real-time data migration across Cosmos containers.

Local writes

Multi Master enables all Azure Cosmos account regions to be read and write enabled. If you deploy an Azure Function App like the one in the DistributedAPI project, you will notice that the HTTP Trigger Functions are using the PreferredLocations and UseMultipleWriteLocations attributes in the Cosmos DB Output and Input bindings. The first one can define a list of comma-separated region names you want the binding to connect to preferably, and the latter tells the binding that we want to take advantage of the Multi Master feature.

You can see that in both bindings, we are using a placeholder as value as PreferredLocations. That means that we can set this value on an environment variable and the code will pick it up automatically, which also enables us to deploy the same code in multiple regions and make it work locally.

Real-time notifications

The repository contains a sample of how to use the Cosmos DB Trigger and the SignalR Output Binding. This mix lets the Azure Function wake up whenever there are new changes happening in the Azure Cosmos container's Change Feed and send them to Azure SignalR, which will use WebSocket connections to push these events to any connected clients.

Real-time data migration

Finally, mixing the Cosmos DB Trigger with the Cosmos DB Output Binding, allows for online data migration between two Azure Cosmos containers; whenever there are new events on one container, they will be copied to another one, which might even have a different partition key. On this case, it is important the use of LeaseCollectionPrefix on the Trigger, which will enable multiple triggers to share the same leases container and work in parallel.

References

About

Serverless geo-replicated event-based architecture sample for Azure Friday

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages