@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Azure tales: a real world CQRS and
ES Deep Dive
Andrea Saltarello
Solution Architect @ Managed Designs
https://twitter.com/andysal74
https://github.com/andysal
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Many thanks to our sponsors & partners!
GOLD
SILVER
PARTNERS
PLATINUM
POWERED BY
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Andrea Saltarello
• Solution Architect @ Managed
Designs
• Microsoft .NET MVP since 2003
• Microsoft Regional Director
• Author, along with Dino, of .NET:
Architecting Applications for the
Enterprise, di Microsoft Press
• Basically, a software architect eager
to write code ☺
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• CQRS/Event Sourcing recap
• CQRS/ES @ Azure: deployment blueprints
• Technology & economic considerations
Agenda
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
CQRS/ES RECAP
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Not the way to implement Event Sourcing, but a
working way to do it nonetheless
Demo app available on Github (GPL3): it is a real open
source project of which my company sells
customizations
There’s no silver bullet
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
A few fancy dressed blokes going for a jaunt
The (Relational) Lord of the Rings
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
It really became clear to me in the last couple of years that we
need a new building block and that is the Domain Event.
[Eric Evans]
An event is something that has happened in the past.
[Greg Young]
A domain event … captures the memory of something
interesting which affects the domain
[Martin Fowler]
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Instead of focusing on a system’s last known
state, we might note down every occurring
event: this way, we would be able to (re)build
the state the system was in at any point in time
just replaying those events
To cut a long story short: we’d end up
recording an event stream
Event Sourcing in a nutshell
JobOrderStarted InvoiceIssuedJobOrderExtended JobOrderCompleted
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
The (immutable) composition of:
• A (meaningful) name
• (Typed) Attributes
What’s an event, anyway?
InvoiceIssued
DateOfIssue
Customer
Price
ProjectStarted
DateOfStart
ProjectId
ProjectCompleted
DateOfCompletion
ProjectId
ProjectRegistered
DateOfRegistration
DateOfEstimatedCompletion
ProjectId
CustomerId
Price
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO
Event Stream
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Still, my users are more interested in knowing a job
order’s balance or whether an invoice has been paid.
(cit.)
That is, we need a way to produce an entity state
Event Stream vs. «My application»
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DDD’s Aggregates provide a convenient way to encapsulate event
management
Aggregate: A collection of objects that are bound together by a root
entity, otherwise known as an aggregate root. The aggregate root
guarantees the consistency of changes being made within the
aggregate.
[Wikipedia]
An aggregate is responsible for:
• encapsulating business logic pertaining to an “entity”
• generating events to have them available for saving
• replaying events in order to rebuild a specific state
Event Sourcing <3 DDD
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO
Aggregates
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
var aggr = repository.GetById<TAggr>(id); //Triggers [time travelling] event
replay
aggr.DoSomething(); //Biz logic + events
repository.Save(aggr); //Updates the event stream
Repository: Mediates between the domain and data mapping layers using a
collection-like interface for accessing domain objects. [DDD]
Aggregates vs. Events vs. Repos
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO
Time Travelling
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Still², my users are more interested in knowing a job
order’s balance or whether an invoice has been paid.
Quickly.
Ways to achieve that:
• Snapshots can help
• CQRS to the rescue: let’s have a database storing the usual «last
known system state» and use it as a read model
Event Stream vs. «My application»
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Acronym for Command Query Responsibility
Segregation
Basically, ad hoc application stacks for either “writing”
or reading:
• “Command” stack writes events and snapshots
• “Read” stack reads from eventually consistent, reading
purposes optimized database(s)
Enter CQRS
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO
Read Model
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
1. Application sends a command to the system
2. Command execution might alter the system’s state and
then raise events to state success/failure
3. Events are notified to interested subscribers (a.k.a.
handlers), such as:
• Workflow managers (a.k.a. «Sagas») which could execute more
commands
• Denormalizers, which will update the read model database
Note: command/event dispatch/execution will usually be
managed by a Mediator («bus»)
CQRS/ES in a nutshell
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Application
Layer
Snapshots
Event store
Read stack
Domain Layer
Ad-hoc DBHandlers
Command Event Data
Handlers
Model ServicesB
U
S
CQRS/ES at a glance
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO
Handlers
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
BLUEPRINTS
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Azure <3 CQRS: n-tiered
Back-endFront-end
Application
Layer
Snapshots
Event store
Read stack
Domain Layer
Ad-hoc DBHandlers
Command Event Data
Handlers
Model Services
A
S
B
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Front end:
• VM
• Web role
• App Service
• Docker
Back end:
• Worker role
• Service Fabric
• Docker
N-tiered deploy
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Azure <3 CQRS: full stack
App Service
Application
Layer
Snapshots
Event store
Read stack
Domain Layer
Ad-hoc DBHandlers
Command Event Data
Handlers
Model Services
A
S
B
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• VM
• Web role
• App Service
• Docker
• Service Fabric
Full stack deploy
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
A fine-grained deploy allows each “component” to be:
• Evolved
• Deployed
• Configured (e.g.: scaled)
Independently, thus having each one only consuming
the resources it really needs but it means having more
moving parts to manage
N-tiered vs. Full stack
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
TECHNOLOGY & ECONOMIC
CONSIDERATIONS
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
App Service Cloud Services Docker Service Fabric VM
PROs:
• PaaS
PROs:
• PaaS
PROs
• Deploy
• Scaling*
• Documentation/samples
PROs:
• Fault tolerance
• Load balancing
• Deploy
PROs
• (Usually) cheapest
monthly bill
• No new skiils needed
• Unparalled option set
CONs:
• .NET 4.5.1 only(*)
CONs: (?)
• Need for an orchestrator
CONs:
• Ad-hoc SDK
CONs:
• Management
Azure Compute smackdown
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
A 2 cores, 3.5 GB RAM, 60 GB disk compute unit costs:
• 75,92 EUR/month as a VM
• 94,11 EUR/month as an AppService
• 100,39 EUR/month as a Cloud Service (*)
• 338,80** - 564,47*** EUR/month as a Service Fabric
cluster
* 490Gb disk
**3 nodes
***5 nodes
From a billing perspective
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
An effective CQRS/ES implementation usually relies on
2 structural pillars:
• A mediator bus
• An event store
Well come on and let me know…
Should I stay build or should I go (shopping)? (demi
quote)
On a technology side…
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Rebus.net:
• is an open source, production tested bus for .NET. Source code is available
on Github, but usually Nuget packages will do.
• provides much-needed features such as:
– Fault tolerance
– Scalability
– Events’ scheduling
– Easy migration from on-premises to cloud
• requires:
– a transport protocol (e.g.: MSMQ, RabbitMQ, Azure Service Bus, Amazon Sqs, ...)
– an IoC container (e.g.: Autofac, Ninject, .NET Core ServiceProvider, StructureMap,
Unity, Windsor...)
– a storage (e.g.: MongoDB, RavenDb, SQL Server, ...)
Enter Rebus.net
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
DEMO
Configuration
Back to the Future
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
MementoFX NEventStore
https://www.nuget.org/packages?q=MementoFx
• FOSS
• DDD/ES stack
• Time travelling
• Alternative timelines
https://www.nuget.org/packages?q=NEventStore
• FOSS
• Event Store API only
• “CommonDomain” package available to support DDD
• Wide community + Slack channel
CQRS Application Frameworks
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
CosmosDB mLab VM
PROS:
• Multiple APIs (e.g.: DocumentDB,
MongoDB)
• PaaS
• Scalability/Georedundancy
PROS:
• PaaS
• Large ecosystem
PROS:
• Unparalleled configuration
options
CONS:
• Billing
CONS:
• Few instance sizes
CONS:
• Management
Event Store: a couple of options
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
• A CosmosDB database is billed on a per-collection basis, with
a 1 GB, 400 RU/sec collection costing 20.08 EUR/month
• A 3 “A2” VM MongoDB Linux cluster costs 146,82 EUR/month
(but we’d have to manage it)
• mLab’s dedicated cluster options:
From a Billing perspective
Size RAM Disk Monthly price
M1 1.7 GB 40 GB $200
M2 3.5 GB 60 GB $400
M3 7 GB 120 GB $800
M4 14 GB 240 GB $1,320
M5 28 GB 480 GB $2,450
M6 56 GB 700 GB $4,280
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
THANK YOU!
@ITCAMPRO #ITCAMP17Community Conference for IT Professionals
Q & A

More Related Content

PDF
The best of Hyper-V 2016 - Thomas Maurer
PDF
Docker adventures in Continuous Delivery - Alex Vranceanu
PDF
ITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream Projects
PDF
Provisioning Windows instances at scale on Azure, AWS and OpenStack - Adrian ...
PDF
ITCamp 2017 - Raffaele Rialdi - A Deep Dive Into Bridging Node-js with .NET Core
PDF
The fight for surviving in the IoT world - Radu Vunvulea
PPTX
ITCamp 2017 - Laurent Ellerbach - Bot. You said bot? Let's build a bot then...
PDF
The best of Windows Server 2016 - Thomas Maurer
The best of Hyper-V 2016 - Thomas Maurer
Docker adventures in Continuous Delivery - Alex Vranceanu
ITCamp 2017 - Raffaele Rialdi - Adopting .NET Core in Mainstream Projects
Provisioning Windows instances at scale on Azure, AWS and OpenStack - Adrian ...
ITCamp 2017 - Raffaele Rialdi - A Deep Dive Into Bridging Node-js with .NET Core
The fight for surviving in the IoT world - Radu Vunvulea
ITCamp 2017 - Laurent Ellerbach - Bot. You said bot? Let's build a bot then...
The best of Windows Server 2016 - Thomas Maurer

What's hot (20)

PDF
Xamarin Under The Hood - Dan Ardelean
PDF
From Developer to Data Scientist - Gaines Kergosien
PDF
How to secure and manage modern IT - Ondrej Vysek
PDF
Blockchain for mere mortals - understand the fundamentals and start building ...
PDF
Kubernetes - Cloud Native Application Orchestration - Catalin Jora
PDF
Everyone Loves Docker Containers Before They Understand Docker Containers - A...
PPTX
Serverless Single Page Apps with React and Redux at ItCamp 2017
PDF
Windows 10 Creators Update: what’s on tap for business users - Ionut Balan
PDF
Migrating to Continuous Delivery with TFS 2017 - Liviu Mandras-Iura
PDF
#NoAgile - Dan Suciu
PDF
Modern cybersecurity threats, and shiny new tools to help deal with them - T...
PDF
Testing your PowerShell code with Pester - Florin Loghiade
PDF
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
PDF
Scaling face recognition with big data - Bogdan Bocse
PDF
The Vision of Computer Vision: The bold promise of teaching computers to unde...
PDF
Building and Managing your Virtual Datacenter using PowerShell DSC - Florin L...
PDF
BUILD with Microsoft - Radu Stefan
PDF
Developing PowerShell Tools - Razvan Rusu
PDF
What's New in Hyper-V 2016 - Thomas Maurer
PDF
Nano Server - the future of Windows Server - Thomas Maurer
Xamarin Under The Hood - Dan Ardelean
From Developer to Data Scientist - Gaines Kergosien
How to secure and manage modern IT - Ondrej Vysek
Blockchain for mere mortals - understand the fundamentals and start building ...
Kubernetes - Cloud Native Application Orchestration - Catalin Jora
Everyone Loves Docker Containers Before They Understand Docker Containers - A...
Serverless Single Page Apps with React and Redux at ItCamp 2017
Windows 10 Creators Update: what’s on tap for business users - Ionut Balan
Migrating to Continuous Delivery with TFS 2017 - Liviu Mandras-Iura
#NoAgile - Dan Suciu
Modern cybersecurity threats, and shiny new tools to help deal with them - T...
Testing your PowerShell code with Pester - Florin Loghiade
The Fine Art of Time Travelling - Implementing Event Sourcing - Andrea Saltar...
Scaling face recognition with big data - Bogdan Bocse
The Vision of Computer Vision: The bold promise of teaching computers to unde...
Building and Managing your Virtual Datacenter using PowerShell DSC - Florin L...
BUILD with Microsoft - Radu Stefan
Developing PowerShell Tools - Razvan Rusu
What's New in Hyper-V 2016 - Thomas Maurer
Nano Server - the future of Windows Server - Thomas Maurer
Ad

Viewers also liked (20)

PDF
QCONSF - ACID Is So Yesterday: Maintaining Data Consistency with Sagas
PPTX
Windows Containers and Docker: Why You Should Care
PDF
A Pattern Language for Microservices
PPTX
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
PPTX
Decouvrir son sujet grace à l'event storming
PDF
Sortir de notre zone de confort
PDF
Async await...oh wait!
PDF
Ddd reboot (english version)
PDF
Faible latence haut debit Devoxx FR 2014
PDF
Faible latence, haut debit PerfUG (Septembre 2014)
PDF
Decouvrir CQRS (sans Event sourcing) par la pratique
PDF
TDD is dead?!? Let's do an autospy (ncrafts.io)
PDF
.NET Inside - Microservices, .NET Core e Serverless
PPTX
Docker and Windows: The State of the Union
PDF
Coder sans peur du changement avec la meme pas mal hexagonal architecture
PPTX
The Velvet Revolution: Modernizing Traditional ASP.NET Apps with Docker
PDF
Culture craft humantalks
PDF
CQRS without event sourcing
PDF
Solving distributed data management problems in a microservice architecture (...
PDF
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
QCONSF - ACID Is So Yesterday: Maintaining Data Consistency with Sagas
Windows Containers and Docker: Why You Should Care
A Pattern Language for Microservices
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
Decouvrir son sujet grace à l'event storming
Sortir de notre zone de confort
Async await...oh wait!
Ddd reboot (english version)
Faible latence haut debit Devoxx FR 2014
Faible latence, haut debit PerfUG (Septembre 2014)
Decouvrir CQRS (sans Event sourcing) par la pratique
TDD is dead?!? Let's do an autospy (ncrafts.io)
.NET Inside - Microservices, .NET Core e Serverless
Docker and Windows: The State of the Union
Coder sans peur du changement avec la meme pas mal hexagonal architecture
The Velvet Revolution: Modernizing Traditional ASP.NET Apps with Docker
Culture craft humantalks
CQRS without event sourcing
Solving distributed data management problems in a microservice architecture (...
Building and deploying microservices with event sourcing, CQRS and Docker (Be...
Ad

Similar to Azure tales: a real world CQRS and ES Deep Dive - Andrea Saltarello (20)

PPTX
Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016
PDF
Azure Microservices in Practice - Radu Vunvulea
PDF
Azure SQL Database From A Developer's Perspective - Alex Mang
PDF
One Azure Monitor to Rule Them All? - Marius Zaharia
PPTX
One Azure Monitor to Rule Them All? (IT Camp 2017, Cluj, RO)
PDF
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
PPTX
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
PPTX
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
PDF
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
PDF
ITCamp 2018 - Damian Widera U-SQL in great depth
PPTX
Xamarin - Under the bridge
PDF
ITCamp 2018 - Florin Loghiade - Containers in Azure - An Infrastructure persp...
PPTX
The fight for surviving in the IoT world
PDF
ITCamp 2011 - Mihai Nadas - Windows Azure interop
PDF
Where should I run my code? Serverless, Containers, Virtual Machines and more
PPTX
Signal R 2015
PDF
Genomic Computation at Scale with Serverless, StackStorm and Docker Swarm
PDF
Spring and Pivotal Application Service - SpringOne Tour - Boston
PDF
Cisco project ideas
PDF
Productionizing Machine Learning - Bigdata meetup 5-06-2019
Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016
Azure Microservices in Practice - Radu Vunvulea
Azure SQL Database From A Developer's Perspective - Alex Mang
One Azure Monitor to Rule Them All? - Marius Zaharia
One Azure Monitor to Rule Them All? (IT Camp 2017, Cluj, RO)
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2018 - Damian Widera U-SQL in great depth
Xamarin - Under the bridge
ITCamp 2018 - Florin Loghiade - Containers in Azure - An Infrastructure persp...
The fight for surviving in the IoT world
ITCamp 2011 - Mihai Nadas - Windows Azure interop
Where should I run my code? Serverless, Containers, Virtual Machines and more
Signal R 2015
Genomic Computation at Scale with Serverless, StackStorm and Docker Swarm
Spring and Pivotal Application Service - SpringOne Tour - Boston
Cisco project ideas
Productionizing Machine Learning - Bigdata meetup 5-06-2019

More from ITCamp (20)

PDF
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
PDF
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
PDF
ITCamp 2019 - Peter Leeson - Managing Skills
PDF
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
PDF
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
PPTX
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
PPTX
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
PPTX
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
PPTX
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
PPTX
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
PPTX
ITCamp 2019 - Andy Cross - Business Outcomes from AI
PPTX
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
PPTX
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
PDF
ITCamp 2019 - Peter Leeson - Vitruvian Quality
PDF
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
PDF
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
PDF
ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
PDF
ITCamp 2018 - Magnus Mårtensson - Azure Global Application Perspectives
PDF
ITCamp 2018 - Magnus Mårtensson - Azure Resource Manager For The Win
PDF
ITCamp 2018 - Ionut Balan - A beginner’s guide to Windows Mixed Reality
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
ITCamp 2018 - Magnus Mårtensson - Azure Global Application Perspectives
ITCamp 2018 - Magnus Mårtensson - Azure Resource Manager For The Win
ITCamp 2018 - Ionut Balan - A beginner’s guide to Windows Mixed Reality

Recently uploaded (20)

PPTX
SGT Report The Beast Plan and Cyberphysical Systems of Control
PDF
A symptom-driven medical diagnosis support model based on machine learning te...
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
Build Real-Time ML Apps with Python, Feast & NoSQL
PDF
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Co-training pseudo-labeling for text classification with support vector machi...
PDF
Ensemble model-based arrhythmia classification with local interpretable model...
PPTX
Internet of Everything -Basic concepts details
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PDF
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
SaaS reusability assessment using machine learning techniques
PDF
Human Computer Interaction Miterm Lesson
PDF
4 layer Arch & Reference Arch of IoT.pdf
PDF
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
PPTX
Microsoft User Copilot Training Slide Deck
SGT Report The Beast Plan and Cyberphysical Systems of Control
A symptom-driven medical diagnosis support model based on machine learning te...
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
Build Real-Time ML Apps with Python, Feast & NoSQL
A hybrid framework for wild animal classification using fine-tuned DenseNet12...
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Co-training pseudo-labeling for text classification with support vector machi...
Ensemble model-based arrhythmia classification with local interpretable model...
Internet of Everything -Basic concepts details
Build automations faster and more reliably with UiPath ScreenPlay
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
Early detection and classification of bone marrow changes in lumbar vertebrae...
Advancing precision in air quality forecasting through machine learning integ...
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
SaaS reusability assessment using machine learning techniques
Human Computer Interaction Miterm Lesson
4 layer Arch & Reference Arch of IoT.pdf
Aug23rd - Mulesoft Community Workshop - Hyd, India.pdf
Microsoft User Copilot Training Slide Deck

Azure tales: a real world CQRS and ES Deep Dive - Andrea Saltarello

  • 1. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Azure tales: a real world CQRS and ES Deep Dive Andrea Saltarello Solution Architect @ Managed Designs https://twitter.com/andysal74 https://github.com/andysal
  • 2. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Many thanks to our sponsors & partners! GOLD SILVER PARTNERS PLATINUM POWERED BY
  • 3. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Andrea Saltarello • Solution Architect @ Managed Designs • Microsoft .NET MVP since 2003 • Microsoft Regional Director • Author, along with Dino, of .NET: Architecting Applications for the Enterprise, di Microsoft Press • Basically, a software architect eager to write code ☺
  • 4. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • CQRS/Event Sourcing recap • CQRS/ES @ Azure: deployment blueprints • Technology & economic considerations Agenda
  • 5. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals CQRS/ES RECAP
  • 7. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Not the way to implement Event Sourcing, but a working way to do it nonetheless Demo app available on Github (GPL3): it is a real open source project of which my company sells customizations There’s no silver bullet
  • 8. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals A few fancy dressed blokes going for a jaunt The (Relational) Lord of the Rings
  • 10. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals It really became clear to me in the last couple of years that we need a new building block and that is the Domain Event. [Eric Evans] An event is something that has happened in the past. [Greg Young] A domain event … captures the memory of something interesting which affects the domain [Martin Fowler]
  • 11. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Instead of focusing on a system’s last known state, we might note down every occurring event: this way, we would be able to (re)build the state the system was in at any point in time just replaying those events To cut a long story short: we’d end up recording an event stream Event Sourcing in a nutshell JobOrderStarted InvoiceIssuedJobOrderExtended JobOrderCompleted
  • 12. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals The (immutable) composition of: • A (meaningful) name • (Typed) Attributes What’s an event, anyway? InvoiceIssued DateOfIssue Customer Price ProjectStarted DateOfStart ProjectId ProjectCompleted DateOfCompletion ProjectId ProjectRegistered DateOfRegistration DateOfEstimatedCompletion ProjectId CustomerId Price
  • 13. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO Event Stream
  • 14. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Still, my users are more interested in knowing a job order’s balance or whether an invoice has been paid. (cit.) That is, we need a way to produce an entity state Event Stream vs. «My application»
  • 15. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DDD’s Aggregates provide a convenient way to encapsulate event management Aggregate: A collection of objects that are bound together by a root entity, otherwise known as an aggregate root. The aggregate root guarantees the consistency of changes being made within the aggregate. [Wikipedia] An aggregate is responsible for: • encapsulating business logic pertaining to an “entity” • generating events to have them available for saving • replaying events in order to rebuild a specific state Event Sourcing <3 DDD
  • 16. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO Aggregates
  • 17. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals var aggr = repository.GetById<TAggr>(id); //Triggers [time travelling] event replay aggr.DoSomething(); //Biz logic + events repository.Save(aggr); //Updates the event stream Repository: Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects. [DDD] Aggregates vs. Events vs. Repos
  • 18. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO Time Travelling
  • 19. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Still², my users are more interested in knowing a job order’s balance or whether an invoice has been paid. Quickly. Ways to achieve that: • Snapshots can help • CQRS to the rescue: let’s have a database storing the usual «last known system state» and use it as a read model Event Stream vs. «My application»
  • 20. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Acronym for Command Query Responsibility Segregation Basically, ad hoc application stacks for either “writing” or reading: • “Command” stack writes events and snapshots • “Read” stack reads from eventually consistent, reading purposes optimized database(s) Enter CQRS
  • 21. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO Read Model
  • 22. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals 1. Application sends a command to the system 2. Command execution might alter the system’s state and then raise events to state success/failure 3. Events are notified to interested subscribers (a.k.a. handlers), such as: • Workflow managers (a.k.a. «Sagas») which could execute more commands • Denormalizers, which will update the read model database Note: command/event dispatch/execution will usually be managed by a Mediator («bus») CQRS/ES in a nutshell
  • 23. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Application Layer Snapshots Event store Read stack Domain Layer Ad-hoc DBHandlers Command Event Data Handlers Model ServicesB U S CQRS/ES at a glance
  • 24. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO Handlers
  • 25. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals BLUEPRINTS
  • 26. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Azure <3 CQRS: n-tiered Back-endFront-end Application Layer Snapshots Event store Read stack Domain Layer Ad-hoc DBHandlers Command Event Data Handlers Model Services A S B
  • 27. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Front end: • VM • Web role • App Service • Docker Back end: • Worker role • Service Fabric • Docker N-tiered deploy
  • 28. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Azure <3 CQRS: full stack App Service Application Layer Snapshots Event store Read stack Domain Layer Ad-hoc DBHandlers Command Event Data Handlers Model Services A S B
  • 29. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • VM • Web role • App Service • Docker • Service Fabric Full stack deploy
  • 30. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals A fine-grained deploy allows each “component” to be: • Evolved • Deployed • Configured (e.g.: scaled) Independently, thus having each one only consuming the resources it really needs but it means having more moving parts to manage N-tiered vs. Full stack
  • 31. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals TECHNOLOGY & ECONOMIC CONSIDERATIONS
  • 32. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals App Service Cloud Services Docker Service Fabric VM PROs: • PaaS PROs: • PaaS PROs • Deploy • Scaling* • Documentation/samples PROs: • Fault tolerance • Load balancing • Deploy PROs • (Usually) cheapest monthly bill • No new skiils needed • Unparalled option set CONs: • .NET 4.5.1 only(*) CONs: (?) • Need for an orchestrator CONs: • Ad-hoc SDK CONs: • Management Azure Compute smackdown
  • 33. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals A 2 cores, 3.5 GB RAM, 60 GB disk compute unit costs: • 75,92 EUR/month as a VM • 94,11 EUR/month as an AppService • 100,39 EUR/month as a Cloud Service (*) • 338,80** - 564,47*** EUR/month as a Service Fabric cluster * 490Gb disk **3 nodes ***5 nodes From a billing perspective
  • 34. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals An effective CQRS/ES implementation usually relies on 2 structural pillars: • A mediator bus • An event store Well come on and let me know… Should I stay build or should I go (shopping)? (demi quote) On a technology side…
  • 35. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Rebus.net: • is an open source, production tested bus for .NET. Source code is available on Github, but usually Nuget packages will do. • provides much-needed features such as: – Fault tolerance – Scalability – Events’ scheduling – Easy migration from on-premises to cloud • requires: – a transport protocol (e.g.: MSMQ, RabbitMQ, Azure Service Bus, Amazon Sqs, ...) – an IoC container (e.g.: Autofac, Ninject, .NET Core ServiceProvider, StructureMap, Unity, Windsor...) – a storage (e.g.: MongoDB, RavenDb, SQL Server, ...) Enter Rebus.net
  • 36. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals DEMO Configuration Back to the Future
  • 37. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals MementoFX NEventStore https://www.nuget.org/packages?q=MementoFx • FOSS • DDD/ES stack • Time travelling • Alternative timelines https://www.nuget.org/packages?q=NEventStore • FOSS • Event Store API only • “CommonDomain” package available to support DDD • Wide community + Slack channel CQRS Application Frameworks
  • 38. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals CosmosDB mLab VM PROS: • Multiple APIs (e.g.: DocumentDB, MongoDB) • PaaS • Scalability/Georedundancy PROS: • PaaS • Large ecosystem PROS: • Unparalleled configuration options CONS: • Billing CONS: • Few instance sizes CONS: • Management Event Store: a couple of options
  • 39. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals • A CosmosDB database is billed on a per-collection basis, with a 1 GB, 400 RU/sec collection costing 20.08 EUR/month • A 3 “A2” VM MongoDB Linux cluster costs 146,82 EUR/month (but we’d have to manage it) • mLab’s dedicated cluster options: From a Billing perspective Size RAM Disk Monthly price M1 1.7 GB 40 GB $200 M2 3.5 GB 60 GB $400 M3 7 GB 120 GB $800 M4 14 GB 240 GB $1,320 M5 28 GB 480 GB $2,450 M6 56 GB 700 GB $4,280
  • 40. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals THANK YOU!
  • 41. @ITCAMPRO #ITCAMP17Community Conference for IT Professionals Q & A