Serverless CQRS in Azure!
Toon Vanhoutte
https://be.linkedin.com/pub/toon-vanhoutte/6/276/84b
Toon Vanhoutte
Serverless CQRS in Azure!
Nice to meet you
Toon Vanhoutte
Lead Architect @ Codit Belgium
Microsoft Azure MVP
@toonvanhoutte
toonvanhoutte.wordpress.com
www.linkedin.com/in/toon-vanhoutte
Who we are
Customers Entities
2000 Belgium
2004 France
2013 Portugal
2016 Switzerland
2016 UK
2016 The Netherlands
2017 Malta
150
worldwide
The thing we do
Agenda
• An Introduction to CQRS
• Serverless Technologies in Azure
• Use Case: Optimize a Webshop
• Conclusion
6
An introduction to CQRS
CRUD Architecture
Proven and simple design
Command Query Responsibility Segregation
Dealing with complex domain models
Command Query Responsibility Segregation
Dealing with high performing applications
Commands vs Queries
Write
Reliable
Sync / Async
Transactional
Persistent
Commands Queries
Read
Volatile
Sync
Non Transactional
In Memory
Fast Fast
Serverless in Azure
Pizza as a Service
14
Serverless Technology Options
Azure Functions
“Code triggered by events”
Azure Logic Apps
“Workflows triggered by events”
Azure Event Grid
“Serverless event routing service”
Azure Service Bus
“Reliable messaging platform”
Pricing Model
Security
Runtime
Monitoring
Deployment
State
Networking
Connectivity
Exception Handling
Developer experience
Azure Functions Azure Logic Apps
Azure Functions Azure Logic Apps
Preferred option for
complex synchronous
request/response calls.
Preferred option for
asynchronous fire-and-
forget messaging.
Azure Functions
perfectly extends
Azure Logic Apps.
Command
Query
Report
TransferNotification
MeasurementAssignment
Job
Update
Request Trace
Handover
Azure Service Bus Azure Event Grid
© Clemens Vasters
Azure Service Bus Azure Event Grid
Command
Query
ReportTransfer
Notification
Measurement
Assignment
Job
Update
Request
Trace
Handover
Passing Intents Reporting Facts
Messaging
Eventing
Discrete
Series
© Clemens Vasters
Azure Service Bus Azure Event Grid
Passing Intents Reporting Facts
Messaging
Eventing
Discrete
Series
“PriceUpdated”
“OpportunityWon”
“InvoiceBooked”
Temperature stream
Telemetry data
Audit trail
“CreateOrder”
“BookHotel”
“UpdateStock”
© Clemens Vasters
Use Case
Pizza Antonio
Find out how CQRS will save
Antonio’s business!
Pizza Antonio
Website
€ 10€ 12€ 11
Submit
Query
Command
Pizza Antonio
QueryCommand
GetProducts
CreateOrder
SQLDatabase
Very good pizza’s
Customers get errors when ordering pizza during peak hours
Pizza Antonio
QueryCommand
GetProducts
CreateOrder
SQLDatabase
Customers don’t get any errors anymore
The orders don’t make it to the database, so no pizza
Pizza Antonio
QueryCommand
GetProducts
CreateOrder
SQLDatabase
All orders make it to the database
Polling during quiet hours is rather expensive, so more expensive pizza’s
Pizza Antonio
QueryCommand
GetProducts
CreateOrder
SQLDatabase
Cheaper polling mechanism, so again sharper prices
No flexible way to send order confirmations through email
Pizza Antonio
QueryCommand
GetProducts
CreateOrder
SQLDatabase
Flexible extension points for e.g. emails
Two different URL’s and security keys for the website
Pizza Antonio
QueryCommand
SQLDatabase
GetProducts
CreateOrder
AzureFunctionProxy
Uniform API for website
Loading products on the website is extremely slow during peak hours
Pizza Antonio
QueryCommand
SQLDatabase
GetProducts
CreateOrder
AzureFunctionProxy
Fast responsive times on the website
No flexible way to update products on external food delivery services
Pizza Antonio
QueryCommand
GetProducts
CreateOrder
SQLDatabase
AzureFunctionProxy
Pizza Antonio
QueryCommand
GetProducts
CreateOrder
SQLDatabase
AzureFunctionProxy
Antonio happy
Customers happy
Conclusion
CQRS is a proven design pattern!
It exists in many different variations
Azure Function Proxy
SQL Database
QueryCommand
Sentinet
SQL Database
QueryCommand
Azure API Mgmt
SQL Database
QueryCommand
Cache
Lessons learned
Azure Functions Azure Event Grid
Consumption plan results
in cold starts, also for
function proxies!
Solution:
• Keep it warm (5 min)
• App Service Plan
• Pre-compiled
functions
Event Grid puts
responsibility for
sequencing at receive side!
Solution:
• Use it wisely
• Consider Azure Service
Bus if sequencing is
required
Architectural Advise on CQRS
Do not overengineer!
Performance
Flexibility
Scalability
Advantages
Idempotence
Resiliency
Eventual Consistency
Challenges
Complexity
Maintenance
Monitoring
Disadvantages
Apply CQRS carefully on specific parts of the solution!
Thank you!
Keep in touch.
@toonvanhoutte
toonvanhoutte.wordpress.com
www.linkedin.com/in/toon-vanhoutte

Serverless CQRS in Azure!

Editor's Notes

  • #10 From a DDD perspective, where the business complexity requires two separate models for read and write models. Eg one database with write against database tables and reads done based on views that are optimized for the UI
  • #11 Improve performance, scalability and flexibility
  • #12 Improve performance, scalability and flexibility