Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Microservices: Azure Cosmos DB to rule them all!

Microservices: Azure Cosmos DB to rule them all!

A presentation about Azure Cosmos DB and how to build Microservices with this service and CQRS/ES patterns.

Talk made during the Global Azure Bootcamp 2019 in Rennes.

Video (French) - 1h22 to 2h10 : https://www.youtube.com/watch?v=PLi-XmvtPVs

Sylvain PONTOREAU

April 27, 2019
Tweet

More Decks by Sylvain PONTOREAU

Other Decks in Programming

Transcript

  1. 4 http://sylvain.pontoreau.com Meet the Team Microsoft Engineer Paris TypeScript co-organizer

    Sylvain PONTOREAU Azure App Engineer @spontoreau https://www.linkedin.com/in/spontoreau
  2. What is Azure Cosmos DB • Cloud Database: https://azure.microsoft.com/en-us/services/cosmos-db/ •

    Released in may 2017 • Based on Document DB • Multi-model • Globally distributed • High availability • Mathematically viable: https://azure.microsoft.com/en-us/blog/azure-cosmos-db-pushing-the-frontier-of-globally-distributed-databases/ • JavaScript engine embedded
  3. • Open source https://github.com/Azure/azure-cosmos-js • Written in TypeScript • NPM

    Package • Documentation https://docs.microsoft.com/en-us/javascript/api/@azure/cosmos $ npm install @azure/cosmos Node.js SDK
  4. const { database} = await client .databases .create({ id: databaseId

    }); const { container } = await database .container .create({ id: containerId }); const client = new CosmosClient({ endpoint: myEndpoint, auth: { masterKey: myKey } }); CosmosClient, Database & Container
  5. const querySpec: SqlQuerySpec = { query: "SELECT root.firstName root.lastName FROM

    root WHERE root.email = @email", parameters: [{ name: "@email", value: "[email protected]" }] }; const { result } = await container .items .query(querySpec) .toArray(); const item = await container .item(id); const { body: readDoc } = item.read(); Querying
  6. const person = { firstName: "Sylvain", lastName: "PONTOREAU", email: "[email protected]"

    }; const { body } = await container .items .create(person); if(body !== undefined) { console.log(body.id); } const item = await container .item(body.id); const { body: readDoc } = item.read(); readDoc.email = "[email protected]"; await item.replace(readDoc); await item.delete(); Persistence
  7. Data Driven Development Domain Driven Design Domain Driven Development !=

    Data structure MCD CRUD Behavior Bounded Context Event
  8. CQRS GetOrderById Query UpdateProduct Command GetProducts Query DeleteOrder Command …

    … Dispatcher Dispatcher QueryHandler CommandHandler Validation Plugin Monitoring Plugin Telemetry Plugin … Eventual consistency
  9. Consistency • All system nodes needs to manipulate exactly the

    same data at the same time. Availability Partition tolerance • Requests must succeed. • Node failure must not create a complete system failure. A distributed system can only guarantee 2 constrains at the same time, not 3 Eventual consistency?
  10. CQRS & Event Sourcing GetOrderById Query UpdateProduct Command GetProducts Query

    DeleteOrder Command … … Dispatcher Dispatcher QueryHandler CommandHandler Projection Projection Aggregate State Events
  11. Cosmos DB as an Event Store Read Enpoint Write Enpoint

    Event Store Projector Read DB publish trigger persist query