SlideShare a Scribd company logo
ddd meets
cqrs and
events sourcing
who am I
gottfried szing
 doing IT stuff for 30+ years
 requirements engineer/business analyst
 software/solution architect
 java, kotlin, js
@GottfriedSzing
gottfried@szing.eu
what to expect...
 some patterns & concepts
 no code, json snippets for illustration
 no silver bullet for solving problems
a possible path to an scalable, maintainable, fault tolerant, fault
resilient application
Patterns & Concepts in
DDD
Patterns & concepts in DDD
 ubiquitous language
 domain & subdomain
 bounded context
 context map
 layered architecture
 entity
 value object
 aggregate
 service
 repository
 factory
 domain event
“
”
The essence of a Domain Event
is that you use it to capture
things that can trigger a
change to the state of the
application you are developing.
Martin Fowler, 2005
“
”
A Domain Event is a record of
some business-significant
occurrence in a Bounded
Context.
Vernon, Vaughn. Domain-Driven Design Distilled, 2016
Customer
Created
Product Version
Changed
Characteristics of Domain Events
 result of a state change
 events happened in the past
 events are facts
 events can never be rejected
 events can never be changed, they are immutable
 part of the ubiquitous language
 nameChanged
 invoicePrinted
 orderConfirmed
 callRecorded
 softwareCrashed
A typical application
Zoomed in...
Slaying a monolith
Microservices to the rescue!?
What are microservices?
 Small,
 independent applications,
 loosely coupled,
 communicating with each other in an asynchronous
manner (across system boundaries), and
 can fail independently, and if one or some fails, the
system as a whole still works, though the functionality
might be downgraded when there are failures.
First approach
First approach
Let’s try it again...
CQS: command-query separation
 pattern on component level
Methods either query or command but never both:
 query does not change state
 command does not return value, only changes the state
 read/write can have a separated model
 reads can be run multiple times without side effects
 reads are automatically idempotent
Example
Commands
Queries
Hidden query,
because
returns
value via
supplied
reference!
Query and command
combined
CQS applied
Monolith
CQS for services
CQS with datapump
Event driven CQRS
CQRS for multiple read models
Example for commands & events
commands for the write side: cause a state change of an
aggregate
public class ConfirmOrder {
public Guid OrderId;
}
events for the result side: are the result of a command
public class OrderConfirmed {
public Guid OrderId;
public DateTime ConfirmationDate;
}
Properties of Domain Events
 Name of event
 Noun + verb in past tense (+ "namespace”)
 at.bounded.context.callRecorded vs. callRecorded
 Timestamp when occurred
 Cause for change
 causation ID, reference to the command
 Granularity
 Enriched: all data inside; high coupling, internals
 Query-Back: only IDs; additional load, replay
 Empty: event itself is important
Concurrency of commands
commands should be handled
concurrently...
... but this could lead to conflicts!
Conflicts with command
person {
"userId": 123456
"username": “root”
}
changeUsernameCommand {
"userId": 123456
"username": "toor"
}
changeUsernameCommand {
"userId": 123456
"username": ”admin"
}
usernameChangedEvent {
"userId": 123456
"username": ???
}
Conflict resolution/prevention
 optimistic locking
 first one wins
 last one wins
 pessimistic locking
 serialization of commands
 single-writer principle
 versioning of the aggregate
Evolution of events
Reason for changes
 aggregate boundaries are wrong
 new attributes
 refactoring
 typos
 type changes
 ...
Non-breaking changes
 adding attribute: up-casting of old events to new ones by
using a new default by converting old events to new
 leads to cascades of up-casts and costs performance 
 assumes an tolerant consumer
event {
"id": 123
}
event {
"id": 123
"state": "cool"
}
Breaking changes
 removing attribute
 leave it in
 renaming of attribute
 add new attribute or live with it
 changes of semantic meaning
 e.g. discount of price in percentage or euro?
 type changes
 e.g. flag to array
 better to add an additional array to the existing flag
event {
"id": 123
”discont": ”10”
"flag": "boolean”
”newFlag": ["boolean”]
}
Event sourcing
What is event sourcing?
Domain modell
Persistence
id name created_at
33 Vernons Blog NOVEMBER 1, 2008
id blog title created_at posted content
12 33 Summary of
CRDTs
MARCH 01,
2015
MARCH 26,
2015
In this article I
am going to
introduce you
to CRDTs....
Events for persistence
Time
blogEntryCreated 12;33;MARCH 01, 2015
blogEntryEdited 12;“...CDRTs...”
blogEntryEdited 12;“...CRDTs...”
blogEntryPublished 12;Vernon, MARCH 25, 2015
blogEntryTitleChanged 12;“Summary of CRDTs”
blogEntryEdited 12;“Yeah, But…”
blogEntryPublished 12;Vernon, MARCH 26, 2015
blogEntryCreated 13;33;MAY 14, 2015
id blog title created_at posted content
12 33 Summary of
CRDTs
MARCH 01,
2015
MARCH 26,
2015
...CRDTs...
13 33 MAY 14, 2015
Event sourcing
 events are the source of truth
 audit logging
 traceability
 easy temporal queries
 ability to put the system in prior state
 for debugging
 recreating state with new business logic
 replay of events
 bug fixing
 evolutionary architectures
Events for integration
Integration of microservices
Integration Events
private
public
Events sourcing & integration
blogEntryCreated
Time
blogEntryEdited
blogEntryEdited
blogEntryPublished
blogEntryTitleChanged
blogEntryEdited
blogEntryPublished
postPublished
postPublished
internal / private external / public
Recap
Recap...
 domain events
 monoliths
 microservice
 distributed monoliths
 CQS
 CQRS
 CQRS with integration events
 event sourcing
Further topics and pitfalls
 versioning of events
 performance in event sourcing
 long running processes: orchestration vs. choreography
 sagas for long lived/distributed transactions
 how to identify domain events
 data protection, authorization, GDPR,...
 “reactive” microservices
 ...
“
”
[...] each pattern represents our current best
guess as to what arrangement of the physical
environment will work to solve the problem
presented.
[...] patterns are still hypotheses, all 253 of
them—and are therefore all tentative, all free to
evolve under the impact of new experience and
observation.
— Christopher Alexander et al., A Pattern Language, p. xv, 1977
conclusion
• apply the patterns wisely, you don’t have to use (all of)
them!
• patterns change over time! new patterns emerge
permanently!
Questions...

More Related Content

What's hot

Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Luciano Mammino
 
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
MongoDB
 
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
MongoDB
 
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Chris Richardson
 
Introduction to BigchainDB
Introduction to BigchainDBIntroduction to BigchainDB
Introduction to BigchainDB
Feng-Ren Tsai
 
Performance and Security Enhancements in MongoDB's BI Connector
Performance and Security Enhancements in MongoDB's BI ConnectorPerformance and Security Enhancements in MongoDB's BI Connector
Performance and Security Enhancements in MongoDB's BI Connector
MongoDB
 

What's hot (6)

Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
Cracking JWT tokens: a tale of magic, Node.js and parallel computing - Code E...
 
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
 
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
 
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
 
Introduction to BigchainDB
Introduction to BigchainDBIntroduction to BigchainDB
Introduction to BigchainDB
 
Performance and Security Enhancements in MongoDB's BI Connector
Performance and Security Enhancements in MongoDB's BI ConnectorPerformance and Security Enhancements in MongoDB's BI Connector
Performance and Security Enhancements in MongoDB's BI Connector
 

Similar to DDD meets CQRS and event sourcing

Cqrs and event sourcing in azure
Cqrs and event sourcing in azureCqrs and event sourcing in azure
Cqrs and event sourcing in azure
Sergey Seletsky
 
Building Microservices with Event Sourcing and CQRS
Building Microservices with Event Sourcing and CQRSBuilding Microservices with Event Sourcing and CQRS
Building Microservices with Event Sourcing and CQRS
Michael Plöd
 
Building and deploying microservices with event sourcing, CQRS and Docker (Me...
Building and deploying microservices with event sourcing, CQRS and Docker (Me...Building and deploying microservices with event sourcing, CQRS and Docker (Me...
Building and deploying microservices with event sourcing, CQRS and Docker (Me...
Chris Richardson
 
Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)
Chris Richardson
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservices
Dennis Doomen
 
Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)
Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)
Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)
Chris Richardson
 
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Chris Richardson
 
Developing microservices with aggregates (melbourne)
Developing microservices with aggregates (melbourne)Developing microservices with aggregates (melbourne)
Developing microservices with aggregates (melbourne)
Chris Richardson
 
Developing microservices with aggregates (devnexus2017)
Developing microservices with aggregates (devnexus2017)Developing microservices with aggregates (devnexus2017)
Developing microservices with aggregates (devnexus2017)
Chris Richardson
 
Event Sourcing: Introduction & Challenges
Event Sourcing: Introduction & ChallengesEvent Sourcing: Introduction & Challenges
Event Sourcing: Introduction & Challenges
Michael Plöd
 
Building microservices with Scala, functional domain models and Spring Boot (...
Building microservices with Scala, functional domain models and Spring Boot (...Building microservices with Scala, functional domain models and Spring Boot (...
Building microservices with Scala, functional domain models and Spring Boot (...
Chris Richardson
 
#hacksummit 2016 - event-driven microservices – Events on the outside, on the...
#hacksummit 2016 - event-driven microservices – Events on the outside, on the...#hacksummit 2016 - event-driven microservices – Events on the outside, on the...
#hacksummit 2016 - event-driven microservices – Events on the outside, on the...
Chris Richardson
 
Events on the outside, on the inside and at the core (jfokus jfokus2016)
Events on the outside, on the inside and at the core (jfokus jfokus2016)Events on the outside, on the inside and at the core (jfokus jfokus2016)
Events on the outside, on the inside and at the core (jfokus jfokus2016)
Chris Richardson
 
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Chris Richardson
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Chris Richardson
 
Building and deploying microservices with event sourcing, CQRS and Docker (Ha...
Building and deploying microservices with event sourcing, CQRS and Docker (Ha...Building and deploying microservices with event sourcing, CQRS and Docker (Ha...
Building and deploying microservices with event sourcing, CQRS and Docker (Ha...
Chris Richardson
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)
Chris Richardson
 
Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...
Chris Richardson
 
Intellias CQRS Framework
Intellias CQRS FrameworkIntellias CQRS Framework
Intellias CQRS Framework
Sergey Seletsky
 
DDD, CQRS, ES lessons learned
DDD, CQRS, ES lessons learnedDDD, CQRS, ES lessons learned
DDD, CQRS, ES lessons learned
Qframe
 

Similar to DDD meets CQRS and event sourcing (20)

Cqrs and event sourcing in azure
Cqrs and event sourcing in azureCqrs and event sourcing in azure
Cqrs and event sourcing in azure
 
Building Microservices with Event Sourcing and CQRS
Building Microservices with Event Sourcing and CQRSBuilding Microservices with Event Sourcing and CQRS
Building Microservices with Event Sourcing and CQRS
 
Building and deploying microservices with event sourcing, CQRS and Docker (Me...
Building and deploying microservices with event sourcing, CQRS and Docker (Me...Building and deploying microservices with event sourcing, CQRS and Docker (Me...
Building and deploying microservices with event sourcing, CQRS and Docker (Me...
 
Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservices
 
Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)
Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)
Developing Event-driven Microservices with Event Sourcing & CQRS (gotoams)
 
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...Building and deploying microservices with event sourcing, CQRS and Docker (QC...
Building and deploying microservices with event sourcing, CQRS and Docker (QC...
 
Developing microservices with aggregates (melbourne)
Developing microservices with aggregates (melbourne)Developing microservices with aggregates (melbourne)
Developing microservices with aggregates (melbourne)
 
Developing microservices with aggregates (devnexus2017)
Developing microservices with aggregates (devnexus2017)Developing microservices with aggregates (devnexus2017)
Developing microservices with aggregates (devnexus2017)
 
Event Sourcing: Introduction & Challenges
Event Sourcing: Introduction & ChallengesEvent Sourcing: Introduction & Challenges
Event Sourcing: Introduction & Challenges
 
Building microservices with Scala, functional domain models and Spring Boot (...
Building microservices with Scala, functional domain models and Spring Boot (...Building microservices with Scala, functional domain models and Spring Boot (...
Building microservices with Scala, functional domain models and Spring Boot (...
 
#hacksummit 2016 - event-driven microservices – Events on the outside, on the...
#hacksummit 2016 - event-driven microservices – Events on the outside, on the...#hacksummit 2016 - event-driven microservices – Events on the outside, on the...
#hacksummit 2016 - event-driven microservices – Events on the outside, on the...
 
Events on the outside, on the inside and at the core (jfokus jfokus2016)
Events on the outside, on the inside and at the core (jfokus jfokus2016)Events on the outside, on the inside and at the core (jfokus jfokus2016)
Events on the outside, on the inside and at the core (jfokus jfokus2016)
 
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
 
Building and deploying microservices with event sourcing, CQRS and Docker (Ha...
Building and deploying microservices with event sourcing, CQRS and Docker (Ha...Building and deploying microservices with event sourcing, CQRS and Docker (Ha...
Building and deploying microservices with event sourcing, CQRS and Docker (Ha...
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)
 
Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...Futures and Rx Observables: powerful abstractions for consuming web services ...
Futures and Rx Observables: powerful abstractions for consuming web services ...
 
Intellias CQRS Framework
Intellias CQRS FrameworkIntellias CQRS Framework
Intellias CQRS Framework
 
DDD, CQRS, ES lessons learned
DDD, CQRS, ES lessons learnedDDD, CQRS, ES lessons learned
DDD, CQRS, ES lessons learned
 

Recently uploaded

A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 

Recently uploaded (20)

A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 

DDD meets CQRS and event sourcing

  • 2. who am I gottfried szing  doing IT stuff for 30+ years  requirements engineer/business analyst  software/solution architect  java, kotlin, js @GottfriedSzing gottfried@szing.eu
  • 3. what to expect...  some patterns & concepts  no code, json snippets for illustration  no silver bullet for solving problems a possible path to an scalable, maintainable, fault tolerant, fault resilient application
  • 5. Patterns & concepts in DDD  ubiquitous language  domain & subdomain  bounded context  context map  layered architecture  entity  value object  aggregate  service  repository  factory  domain event
  • 6. “ ” The essence of a Domain Event is that you use it to capture things that can trigger a change to the state of the application you are developing. Martin Fowler, 2005
  • 7. “ ” A Domain Event is a record of some business-significant occurrence in a Bounded Context. Vernon, Vaughn. Domain-Driven Design Distilled, 2016
  • 10. Characteristics of Domain Events  result of a state change  events happened in the past  events are facts  events can never be rejected  events can never be changed, they are immutable  part of the ubiquitous language  nameChanged  invoicePrinted  orderConfirmed  callRecorded  softwareCrashed
  • 14. What are microservices?  Small,  independent applications,  loosely coupled,  communicating with each other in an asynchronous manner (across system boundaries), and  can fail independently, and if one or some fails, the system as a whole still works, though the functionality might be downgraded when there are failures.
  • 17. Let’s try it again...
  • 18. CQS: command-query separation  pattern on component level Methods either query or command but never both:  query does not change state  command does not return value, only changes the state  read/write can have a separated model  reads can be run multiple times without side effects  reads are automatically idempotent
  • 25. CQRS for multiple read models
  • 26. Example for commands & events commands for the write side: cause a state change of an aggregate public class ConfirmOrder { public Guid OrderId; } events for the result side: are the result of a command public class OrderConfirmed { public Guid OrderId; public DateTime ConfirmationDate; }
  • 27. Properties of Domain Events  Name of event  Noun + verb in past tense (+ "namespace”)  at.bounded.context.callRecorded vs. callRecorded  Timestamp when occurred  Cause for change  causation ID, reference to the command  Granularity  Enriched: all data inside; high coupling, internals  Query-Back: only IDs; additional load, replay  Empty: event itself is important
  • 28. Concurrency of commands commands should be handled concurrently... ... but this could lead to conflicts!
  • 29. Conflicts with command person { "userId": 123456 "username": “root” } changeUsernameCommand { "userId": 123456 "username": "toor" } changeUsernameCommand { "userId": 123456 "username": ”admin" } usernameChangedEvent { "userId": 123456 "username": ??? }
  • 30. Conflict resolution/prevention  optimistic locking  first one wins  last one wins  pessimistic locking  serialization of commands  single-writer principle  versioning of the aggregate
  • 32. Reason for changes  aggregate boundaries are wrong  new attributes  refactoring  typos  type changes  ...
  • 33. Non-breaking changes  adding attribute: up-casting of old events to new ones by using a new default by converting old events to new  leads to cascades of up-casts and costs performance   assumes an tolerant consumer event { "id": 123 } event { "id": 123 "state": "cool" }
  • 34. Breaking changes  removing attribute  leave it in  renaming of attribute  add new attribute or live with it  changes of semantic meaning  e.g. discount of price in percentage or euro?  type changes  e.g. flag to array  better to add an additional array to the existing flag event { "id": 123 ”discont": ”10” "flag": "boolean” ”newFlag": ["boolean”] }
  • 35. Event sourcing What is event sourcing?
  • 36.
  • 38. Persistence id name created_at 33 Vernons Blog NOVEMBER 1, 2008 id blog title created_at posted content 12 33 Summary of CRDTs MARCH 01, 2015 MARCH 26, 2015 In this article I am going to introduce you to CRDTs....
  • 39. Events for persistence Time blogEntryCreated 12;33;MARCH 01, 2015 blogEntryEdited 12;“...CDRTs...” blogEntryEdited 12;“...CRDTs...” blogEntryPublished 12;Vernon, MARCH 25, 2015 blogEntryTitleChanged 12;“Summary of CRDTs” blogEntryEdited 12;“Yeah, But…” blogEntryPublished 12;Vernon, MARCH 26, 2015 blogEntryCreated 13;33;MAY 14, 2015 id blog title created_at posted content 12 33 Summary of CRDTs MARCH 01, 2015 MARCH 26, 2015 ...CRDTs... 13 33 MAY 14, 2015
  • 40. Event sourcing  events are the source of truth  audit logging  traceability  easy temporal queries  ability to put the system in prior state  for debugging  recreating state with new business logic  replay of events  bug fixing  evolutionary architectures
  • 44. Events sourcing & integration blogEntryCreated Time blogEntryEdited blogEntryEdited blogEntryPublished blogEntryTitleChanged blogEntryEdited blogEntryPublished postPublished postPublished internal / private external / public
  • 45. Recap
  • 46. Recap...  domain events  monoliths  microservice  distributed monoliths  CQS  CQRS  CQRS with integration events  event sourcing
  • 47. Further topics and pitfalls  versioning of events  performance in event sourcing  long running processes: orchestration vs. choreography  sagas for long lived/distributed transactions  how to identify domain events  data protection, authorization, GDPR,...  “reactive” microservices  ...
  • 48. “ ” [...] each pattern represents our current best guess as to what arrangement of the physical environment will work to solve the problem presented. [...] patterns are still hypotheses, all 253 of them—and are therefore all tentative, all free to evolve under the impact of new experience and observation. — Christopher Alexander et al., A Pattern Language, p. xv, 1977 conclusion • apply the patterns wisely, you don’t have to use (all of) them! • patterns change over time! new patterns emerge permanently!

Editor's Notes

  1. https://vaughnvernon.co/?p=1012