Giter VIP home page Giter VIP logo

serverlessazurefriday's Introduction

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

serverlessazurefriday's People

Contributors

ealsur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.