serverless cqrs in azure!
TRANSCRIPT
Serverless CQRS in Azure!
Toon Vanhoutte
https://be.linkedin.com/pub/toon-vanhoutte/6/276/84b
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
150worldwide
Agenda
• An Introduction to CQRS
• Serverless Technologies in Azure
• Use Case: Optimize a Webshop
• Conclusion
6
Commands vs Queries
Write
Reliable
Sync / Async
Transactional
Persistent
Commands Queries
Read
Volatile
Sync
Non Transactional
In Memory
Fast Fast
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
UpdateRequest Trace
Handover
Azure Service Bus Azure Event Grid
© Clemens Vasters
Azure Service Bus Azure Event Grid
Command
Query
ReportTransfer
Notification
MeasurementAssignment
Job
Update
Request
Trace
Handover
Passing Intents Reporting Facts
Mess
ag
ing Eve
ntin
g
Discrete
Series
© Clemens Vasters
Azure Service Bus Azure Event Grid
Passing Intents Reporting Facts
Mess
ag
ing Eve
ntin
g
Discrete
Series
“PriceUpdated”
“OpportunityWon”
“InvoiceBooked”
Temperature stream
Telemetry data
Audit trail
“CreateOrder”
“BookHotel”
“UpdateStock”
© Clemens Vasters
Pizza Antonio
Query
Co
mm
and
GetProducts
CreateOrder
SQ
L D
ata
base
Very good pizza’s
Customers get errors when ordering pizza during peak hours
Pizza Antonio
Query
Co
mm
and
GetProducts
CreateOrder
SQ
L D
ata
base
Customers don’t get any errors anymore
The orders don’t make it to the database, so no pizza
Pizza Antonio
Query
Co
mm
and
GetProducts
CreateOrder
SQ
L D
ata
base
All orders make it to the database
Polling during quiet hours is rather expensive, so more expensive pizza’s
Pizza Antonio
Query
Co
mm
and
GetProducts
CreateOrder
SQ
L D
ata
base
Cheaper polling mechanism, so again sharper prices
No flexible way to send order confirmations through email
Pizza Antonio
Query
Co
mm
and
GetProducts
CreateOrder
SQ
L D
ata
base
Flexible extension points for e.g. emails
Two different URL’s and security keys for the website
Pizza Antonio
Query
Co
mm
and
SQ
L D
ata
base
GetProducts
CreateOrder
Azu
re F
unct
ion P
roxy
Uniform API for website
Loading products on the website is extremely slow during peak hours
Pizza Antonio
Query
Co
mm
and
SQ
L D
ata
base
GetProducts
CreateOrder
Azu
re F
unct
ion P
roxy
Fast responsive times on the website
No flexible way to update products on external food delivery services
Pizza Antonio
Query
Co
mm
and
GetProducts
CreateOrder
SQ
L D
ata
base
Azu
re F
unct
ion P
roxy
Antonio happy
Customers happy
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 CQRSDo not overengineer!
Performance
Flexibility
Scalability
Advantages
Idempotence
Resiliency
Eventual Consistency
Challenges
Complexity
Maintenance
Monitoring
Disadvantages
Apply CQRS carefully on specific parts of the solution!