SlideShare a Scribd company logo
Introduction to Event Sourcing
… and CQRS
Vladik Khononov
Chief Architect at Internovus
http://il.linkedin.com/in/vladikkhononov/
vladikk vladikkhttp://vladikk.com
Information Systems
HTML5AngularJSWPFIOSFlashExtJSAndroidSilverlight
Responsive
webdesign
SPACSS3
User
Interface
User
Interface
MySQLMongoDBDynamoDBNeo4jRavenDBPostgreSQLHBaseCassandraSql ServerMariaDBRedisCouchDB
Data
Access
User
Interface
Data
Access
“Verbs & Nouns”Domain Driven Design
Business
Logic
Domain Driven Design?
User
Interface
Business
Logic
Data
Access
– www.dictionary.com
Model: A simplified representation of a system or
phenomenon.
– www.wikipedia.org
‫:מודל‬ ‫ייצוג‬‫תאורטי‬‫של‬‫מערכת‬‫מורכבת‬ , ‫שמטרתו‬
‫לחקות‬‫את‬‫המערכת‬‫בהיבטים‬‫מהותיים‬ . ‫המודל‬‫אינו‬
‫מתאר‬‫כל‬‫תופעה‬‫במערכת‬ , ‫אלא‬‫מתייחס‬‫להיבטים‬
‫מוגדרים‬‫ומצומצמים‬‫שלה‬ . ‫המודל‬‫מבוסס‬‫על‬‫קירוב‬‫של‬
‫המציאות‬‫בדרך‬‫של‬‫הפשטה‬ , ‫איחוד‬‫ישויות‬‫והתעלמות‬
‫מגורמים‬‫שהשפעתם‬‫אינה‬‫מהותית‬ .
User
Interface
Business
Logic
Data
Access
Domain Model
Good Domain Model
• Not too much
• Not too less
• Sweet spot
• The information we need
• The information we will need
Why domain models fail
• We absolutely suck at predicting the future
• No single model can suit all the use cases
• Model transformations are painful
Case Study:
Customers Management
• A customer has customer id number and a name
• A customer has contact information: email, phone
number
• A customer can be in on of the following states:
New, CallLater, Converted, NotInterested
• A seller has seller id number, name and password
• The selling home page contains a list of the
customers in the following statuses:
• New
• CallLater (when scheduled call date is met)
• Seller chooses a customer to call from the home
page
• Seller can change the customer’s status to
“Converted”, “Not Interested”
• Seller can schedule a future call by setting the
future call date. The Customer’s status will change
to “CallLater”
• Seller can change name, email, and phone
number
enum Status {
New, CallLater, Converted,
NotInterested
}
class Customer {
int Id;
string Name;
Status Status;
DateTime? ScheduledCall;
string Email;
string PhoneNumber;
}
CREATE TABLE Customers (
ID INTEGER,
Name CHAR(40),
Email CHAR(40),
PhoneNumber CHAR(40),
Status INTEGER,
ScheduledCall DATETIME,
PRIMARY KEY (ID)
)
class Seller {
int Id;
string Name;
string Password;
}
CREATE TABLE Sellers (
ID INTEGER,
Name CHAR(40),
Password CHAR(40)
PRIMARY KEY (ID)
)
• Seller can find customers by name, email, and/or
phone number in the search page
• The customers should be found by the current and
the past values
• If no new customers are available on the home
page, it should display customers in the
NotInterested status, if it was set more than a 30
days ago
• Analysts should be able to review status changes
history for each customer - change date and the
new status
class Seller {
int Id;
string Name;
string Password;
}
CREATE TABLE Sellers (
ID INTEGER,
Name CHAR(40),
Password CHAR(40)
PRIMARY KEY (ID)
)
enum Status {
New, CallLater, Converted,
NotInterested
}
class Customer {
int Id;
string Name;
Status Status;
DateTime? ScheduledCall;
string Email;
string PhoneNumber;
}
CREATE TABLE Customers (
ID INTEGER,
Name CHAR(40),
Email CHAR(40),
PhoneNumber CHAR(40),
Status INTEGER,
ScheduledCall DATETIME,
PRIMARY KEY (ID)
)
Id Name Email Phone number Status
Scheduled
Call
10 John john@gmail.com 04-2342343 New
Id Name Email Phone number Status
Scheduled
Call
10 John john@gmail.com 04-2342343 CallLater 27/10/2014
Id Name Email Phone number Status
Scheduled
Call
10 John john@gmail.com 08-9876653 CallLater 27/10/2014
Id Name Email Phone number Status
Scheduled
Call
10 John john@gmail.com 08-9876653 Converted
Id Name Email Phone number Status
Scheduled
Call
10 John john@gmail.com 08-9876653 Converted
Event Sourcing
Capture all changes to an application
state as a sequence of events
~ Martin Fowler
class StatusChanged : IEvent {
Status NewStatus;
DateTime CreatedOn; int CreatedBy;
}
class FutureCallScheduled : IEvent {
DateTime ScheduledCallTime;
DateTime CreatedOn; int CreatedBy;
}
class ContactDetailsWereUpdated : IEvent {
string NewName;
string NewEmail;
string NewPhone;
DateTime CreatedOn; int CreatedBy;
}
class Customer {
int Id;
string Name;
string Email;
string PhoneNumber;
Status Status;
DateTime? ScheduledCall;
List<IEvent> Events;
…
void Apply(StatusChanged e) {
Status = e.NewStatus;
Events.Add(e);
}
….
….
}
class Customer {
int Id;
string Name;
string Email;
string PhoneNumber;
Status Status;
DateTime? ScheduledCall;
List<IEvent> Events;
…
…
void Apply(FutureCallScheduled e) {
ScheduledCall = e.ScheduledCallTime;
Events.Add(e);
}
…
}
class Customer {
int Id;
string Name;
string Email;
string PhoneNumber;
Status Status;
DateTime? ScheduledCall;
List<IEvent> Events;
…
…
…
void Apply(ContactDetailsWereUpdated e) {
Name = e.NewName;
Email = e.NewEmail;
PhoneNumber = e.NewPhoneNumber;
Events.Add(e);
}
}
Id Name Email Phone number Status
Scheduled
Call
10 John john@gmail.com 08-9876653 Converted
1. new StatusChanged(Status.CallLater)
2. new FutureCallScheduled(’27/10/2014’)
3. new ContactDetailsWereUpdated(
NewPhoneNumber=’08-9876653’
)
4. new StatusChanged(Status.Converted)
Event Storage
Entity Id + New events
Entity IdEvent1,
Event2,
Event3,
….
class CustomerSearchModel {
int Id;
List<string> Names;
List<string> Emails;
List<string> PhoneNumbers;
Status Status;
DateTime? ScheduledCall;
…
…
…
void Apply(ContactDetailsWereUpdated e) {
Names.Add(e.NewName);
Emails.Add(e.NewEmail);
PhoneNumbers.Add(e.NewPhoneNumber);
}
}
class CustomerAnalysisModel {
int Id;
string Name;
string Email;
string PhoneNumber;
List<StatusChange> StatusChanges;
DateTime? ScheduledCall;
…
void Apply(StatusChanged e) {
StatusChanges.Add(
new StatusChange(e.CreatedOn, e.NewStatus)
);
}
….
….
}
class Customer {
int Id;
string Name;
string Email;
string PhoneNumber;
Status Status;
DateTime? ScheduledCall;
List<IEvent> Events;
}
class CustomerSearchModel {
int Id;
List<string> Names;
List<string> Emails;
List<string> PhoneNumbers;
Status Status;
DateTime? ScheduledCall;
}
class CustomerAnalysisModel {
int Id;
string Name;
string Email;
string PhoneNumber;
List<StatusChange> StatusChanges;
DateTime? ScheduledCall;
}
Good Domain Model
• Not too much
• Not too less
• Sweet spot
• The information we need
• The information we might need
Why domain models fail
• We absolutely suck at predicting the future
• No single model can suit all the use cases
(e.g.: transactional processing, business intelligence,
search)
• Model transformations are painful
Event Storage
Entity Id + New events
Entity IdEvent1,
Event2,
Event3,
….
CQRS
Command Query Responsibility Segregation
• Event based models
• Effective modeling
• No future predicting required
• Time machine
• Retroactive debugging
• Infrastructural freedom
• Infinite scalability
• Easy to scale writes
• Easy to scale reads
Conclusions
Bounded Contexts
Domain Types
• Core Domain
• Subdomain
• Generic Subdomain
Plexop
Campaign Management
(Core Domain)
Creative Catalog
(Subdomain)
User Management
(Generic Subdomain)
Billing
(Generic Subdomain)
Before you try this at home
• Read “Implementing Domain Driven Design” by
Vaughn Vernon
• Read “Domain Driven Design” by Eric Evans
• Follow Greg Young, Udi Dahan, DDD community
• Read DDD/CQRS on Google Groups
• Join http://meetup.com/DDD-IL :)
Questions?
http://il.linkedin.com/in/vladikkhononov
http://twitter.com/vladikk
http://vladikk.com
Introduction to Event Sourcing and CQRS (IASA-IL)
Introduction to Event Sourcing and CQRS (IASA-IL)

More Related Content

Viewers also liked

Antifragile Software Design
Antifragile Software DesignAntifragile Software Design
Antifragile Software Design
Hayim Makabee
 
The SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design PatternsThe SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design Patterns
Hayim Makabee
 
To document or not to document? An exploratory study on developers' motivatio...
To document or not to document? An exploratory study on developers' motivatio...To document or not to document? An exploratory study on developers' motivatio...
To document or not to document? An exploratory study on developers' motivatio...
Hayim Makabee
 
Aliyah: Looking for a hi-tech job in Israel
Aliyah: Looking for a hi-tech job in IsraelAliyah: Looking for a hi-tech job in Israel
Aliyah: Looking for a hi-tech job in Israel
Hayim Makabee
 
Agile archiecture iltam 2014
Agile archiecture   iltam 2014Agile archiecture   iltam 2014
Agile archiecture iltam 2014
Dani Mannes
 
Watch-It-Next: A Contextual TV Recommendation System
Watch-It-Next: A Contextual TV Recommendation SystemWatch-It-Next: A Contextual TV Recommendation System
Watch-It-Next: A Contextual TV Recommendation System
Raz Nissim
 
Reducing Technical Debt
Reducing Technical DebtReducing Technical Debt
Reducing Technical Debt
Hayim Makabee
 
The Role of the Software Architect (short version)
The Role of the Software Architect (short version)The Role of the Software Architect (short version)
The Role of the Software Architect (short version)
Hayim Makabee
 
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkTaming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Joseph Yoder
 
ADUF - Adaptable Design Up Front
ADUF -  Adaptable Design Up FrontADUF -  Adaptable Design Up Front
ADUF - Adaptable Design Up Front
Hayim Makabee
 
Adaptable Designs for Agile Software Development
Adaptable Designs for Agile  Software DevelopmentAdaptable Designs for Agile  Software Development
Adaptable Designs for Agile Software Development
Hayim Makabee
 
Introduction to event practice 1
Introduction to event practice 1Introduction to event practice 1
Introduction to event practice 1
Chris Hattingh
 
July 2013 Talk, What Industry Needs from Architecture Description Languages
July 2013 Talk, What Industry Needs from Architecture Description LanguagesJuly 2013 Talk, What Industry Needs from Architecture Description Languages
July 2013 Talk, What Industry Needs from Architecture Description Languages
grossd18
 
Hierarchical Composable Optimization of Web Pages
Hierarchical Composable Optimization of Web PagesHierarchical Composable Optimization of Web Pages
Hierarchical Composable Optimization of Web Pages
Hayim Makabee
 
An Event-Driven Approach for the Separation of Concerns
An Event-Driven Approach for the Separation of ConcernsAn Event-Driven Approach for the Separation of Concerns
An Event-Driven Approach for the Separation of Concerns
Hayim Makabee
 
Adaptive Object Model - IASA IL Meeting on Software Evolution (3/2014)
Adaptive Object Model - IASA IL Meeting on Software Evolution  (3/2014)Adaptive Object Model - IASA IL Meeting on Software Evolution  (3/2014)
Adaptive Object Model - IASA IL Meeting on Software Evolution (3/2014)
Atzmon Hen-Tov
 
Designing with tests
Designing with testsDesigning with tests
Designing with tests
Dror Helper
 
Extracting Quality Scenarios from Functional Scenarios
Extracting Quality Scenarios from Functional ScenariosExtracting Quality Scenarios from Functional Scenarios
Extracting Quality Scenarios from Functional Scenarios
Prof. Amir Tomer
 
The five expertise of a software architect
The five expertise of a software architectThe five expertise of a software architect
The five expertise of a software architect
Lior Bar-On
 
Software Quality Attributes
Software Quality AttributesSoftware Quality Attributes
Software Quality Attributes
Hayim Makabee
 

Viewers also liked (20)

Antifragile Software Design
Antifragile Software DesignAntifragile Software Design
Antifragile Software Design
 
The SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design PatternsThe SOLID Principles Illustrated by Design Patterns
The SOLID Principles Illustrated by Design Patterns
 
To document or not to document? An exploratory study on developers' motivatio...
To document or not to document? An exploratory study on developers' motivatio...To document or not to document? An exploratory study on developers' motivatio...
To document or not to document? An exploratory study on developers' motivatio...
 
Aliyah: Looking for a hi-tech job in Israel
Aliyah: Looking for a hi-tech job in IsraelAliyah: Looking for a hi-tech job in Israel
Aliyah: Looking for a hi-tech job in Israel
 
Agile archiecture iltam 2014
Agile archiecture   iltam 2014Agile archiecture   iltam 2014
Agile archiecture iltam 2014
 
Watch-It-Next: A Contextual TV Recommendation System
Watch-It-Next: A Contextual TV Recommendation SystemWatch-It-Next: A Contextual TV Recommendation System
Watch-It-Next: A Contextual TV Recommendation System
 
Reducing Technical Debt
Reducing Technical DebtReducing Technical Debt
Reducing Technical Debt
 
The Role of the Software Architect (short version)
The Role of the Software Architect (short version)The Role of the Software Architect (short version)
The Role of the Software Architect (short version)
 
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard WorkTaming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
Taming Big Balls of Mud with Diligence, Agile Practices, and Hard Work
 
ADUF - Adaptable Design Up Front
ADUF -  Adaptable Design Up FrontADUF -  Adaptable Design Up Front
ADUF - Adaptable Design Up Front
 
Adaptable Designs for Agile Software Development
Adaptable Designs for Agile  Software DevelopmentAdaptable Designs for Agile  Software Development
Adaptable Designs for Agile Software Development
 
Introduction to event practice 1
Introduction to event practice 1Introduction to event practice 1
Introduction to event practice 1
 
July 2013 Talk, What Industry Needs from Architecture Description Languages
July 2013 Talk, What Industry Needs from Architecture Description LanguagesJuly 2013 Talk, What Industry Needs from Architecture Description Languages
July 2013 Talk, What Industry Needs from Architecture Description Languages
 
Hierarchical Composable Optimization of Web Pages
Hierarchical Composable Optimization of Web PagesHierarchical Composable Optimization of Web Pages
Hierarchical Composable Optimization of Web Pages
 
An Event-Driven Approach for the Separation of Concerns
An Event-Driven Approach for the Separation of ConcernsAn Event-Driven Approach for the Separation of Concerns
An Event-Driven Approach for the Separation of Concerns
 
Adaptive Object Model - IASA IL Meeting on Software Evolution (3/2014)
Adaptive Object Model - IASA IL Meeting on Software Evolution  (3/2014)Adaptive Object Model - IASA IL Meeting on Software Evolution  (3/2014)
Adaptive Object Model - IASA IL Meeting on Software Evolution (3/2014)
 
Designing with tests
Designing with testsDesigning with tests
Designing with tests
 
Extracting Quality Scenarios from Functional Scenarios
Extracting Quality Scenarios from Functional ScenariosExtracting Quality Scenarios from Functional Scenarios
Extracting Quality Scenarios from Functional Scenarios
 
The five expertise of a software architect
The five expertise of a software architectThe five expertise of a software architect
The five expertise of a software architect
 
Software Quality Attributes
Software Quality AttributesSoftware Quality Attributes
Software Quality Attributes
 

Similar to Introduction to Event Sourcing and CQRS (IASA-IL)

Introduction to Event Sourcing and CQRS
Introduction to Event Sourcing and CQRSIntroduction to Event Sourcing and CQRS
Introduction to Event Sourcing and CQRS
Vladik Khononov
 
Apex Design Patterns
Apex Design PatternsApex Design Patterns
Apex Design Patterns
Salesforce Developers
 
Service Architecture patterns
Service Architecture patternsService Architecture patterns
Service Architecture patterns
Vivek Singh
 
Apex Design Patterns
Apex Design PatternsApex Design Patterns
Apex Design Patterns
Salesforce Developers
 
Intro to AppExchange - Building Composite Apps
Intro to AppExchange - Building Composite AppsIntro to AppExchange - Building Composite Apps
Intro to AppExchange - Building Composite Apps
dreamforce2006
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENT
Lori Moore
 
Detroit ELEVATE Track 2
Detroit ELEVATE Track 2Detroit ELEVATE Track 2
Detroit ELEVATE Track 2
Joshua Birk
 
SA Chapter 10
SA Chapter 10SA Chapter 10
SA Chapter 10
Nuth Otanasap
 
Programming Building Blocks for Admins
Programming Building Blocks for Admins Programming Building Blocks for Admins
Programming Building Blocks for Admins
Salesforce Admins
 
Atl elevate programmatic developer slides
Atl elevate programmatic developer slidesAtl elevate programmatic developer slides
Atl elevate programmatic developer slides
David Scruggs
 
Df12 Performance Tuning
Df12 Performance TuningDf12 Performance Tuning
Df12 Performance Tuning
Stuart Bernstein
 
Performance Tuning for Visualforce and Apex
Performance Tuning for Visualforce and ApexPerformance Tuning for Visualforce and Apex
Performance Tuning for Visualforce and Apex
Salesforce Developers
 
Greg Lewis SQL Portfolio
Greg Lewis SQL PortfolioGreg Lewis SQL Portfolio
Greg Lewis SQL Portfolio
gregmlewis
 
Lerman Vvs14 Ef Tips And Tricks
Lerman Vvs14  Ef Tips And TricksLerman Vvs14  Ef Tips And Tricks
Lerman Vvs14 Ef Tips And Tricks
Julie Lerman
 
Linq
LinqLinq
Marcus Matthews
Marcus MatthewsMarcus Matthews
Marcus Matthews
MarcusMatthews38
 
Group Project 650 Report2
Group Project 650 Report2Group Project 650 Report2
Group Project 650 Report2
Yazeed Alkarzai
 
Job portal
Job portalJob portal
Job portal
Amit Gandhi
 
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Dan Robinson
 
Service Provider
Service Provider Service Provider
Service Provider
Jatin Devani
 

Similar to Introduction to Event Sourcing and CQRS (IASA-IL) (20)

Introduction to Event Sourcing and CQRS
Introduction to Event Sourcing and CQRSIntroduction to Event Sourcing and CQRS
Introduction to Event Sourcing and CQRS
 
Apex Design Patterns
Apex Design PatternsApex Design Patterns
Apex Design Patterns
 
Service Architecture patterns
Service Architecture patternsService Architecture patterns
Service Architecture patterns
 
Apex Design Patterns
Apex Design PatternsApex Design Patterns
Apex Design Patterns
 
Intro to AppExchange - Building Composite Apps
Intro to AppExchange - Building Composite AppsIntro to AppExchange - Building Composite Apps
Intro to AppExchange - Building Composite Apps
 
ADBMS ASSIGNMENT
ADBMS ASSIGNMENTADBMS ASSIGNMENT
ADBMS ASSIGNMENT
 
Detroit ELEVATE Track 2
Detroit ELEVATE Track 2Detroit ELEVATE Track 2
Detroit ELEVATE Track 2
 
SA Chapter 10
SA Chapter 10SA Chapter 10
SA Chapter 10
 
Programming Building Blocks for Admins
Programming Building Blocks for Admins Programming Building Blocks for Admins
Programming Building Blocks for Admins
 
Atl elevate programmatic developer slides
Atl elevate programmatic developer slidesAtl elevate programmatic developer slides
Atl elevate programmatic developer slides
 
Df12 Performance Tuning
Df12 Performance TuningDf12 Performance Tuning
Df12 Performance Tuning
 
Performance Tuning for Visualforce and Apex
Performance Tuning for Visualforce and ApexPerformance Tuning for Visualforce and Apex
Performance Tuning for Visualforce and Apex
 
Greg Lewis SQL Portfolio
Greg Lewis SQL PortfolioGreg Lewis SQL Portfolio
Greg Lewis SQL Portfolio
 
Lerman Vvs14 Ef Tips And Tricks
Lerman Vvs14  Ef Tips And TricksLerman Vvs14  Ef Tips And Tricks
Lerman Vvs14 Ef Tips And Tricks
 
Linq
LinqLinq
Linq
 
Marcus Matthews
Marcus MatthewsMarcus Matthews
Marcus Matthews
 
Group Project 650 Report2
Group Project 650 Report2Group Project 650 Report2
Group Project 650 Report2
 
Job portal
Job portalJob portal
Job portal
 
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
Powering Heap With PostgreSQL And CitusDB (PGConf Silicon Valley 2015)
 
Service Provider
Service Provider Service Provider
Service Provider
 

More from Vladik Khononov

7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018)
7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018)7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018)
7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018)
Vladik Khononov
 
How to Tame TDD - ISTA 2017
How to Tame TDD - ISTA 2017How to Tame TDD - ISTA 2017
How to Tame TDD - ISTA 2017
Vladik Khononov
 
ISTA 2016: Event Sourcing
ISTA 2016: Event SourcingISTA 2016: Event Sourcing
ISTA 2016: Event Sourcing
Vladik Khononov
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Vladik Khononov
 
Introduction to CQRS and DDDD
Introduction to CQRS and DDDDIntroduction to CQRS and DDDD
Introduction to CQRS and DDDD
Vladik Khononov
 
Internal Project: Under the Hood
Internal Project: Under the HoodInternal Project: Under the Hood
Internal Project: Under the Hood
Vladik Khononov
 

More from Vladik Khononov (6)

7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018)
7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018)7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018)
7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018)
 
How to Tame TDD - ISTA 2017
How to Tame TDD - ISTA 2017How to Tame TDD - ISTA 2017
How to Tame TDD - ISTA 2017
 
ISTA 2016: Event Sourcing
ISTA 2016: Event SourcingISTA 2016: Event Sourcing
ISTA 2016: Event Sourcing
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to CQRS and DDDD
Introduction to CQRS and DDDDIntroduction to CQRS and DDDD
Introduction to CQRS and DDDD
 
Internal Project: Under the Hood
Internal Project: Under the HoodInternal Project: Under the Hood
Internal Project: Under the Hood
 

Recently uploaded

Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 

Recently uploaded (20)

Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 

Introduction to Event Sourcing and CQRS (IASA-IL)

  • 1. Introduction to Event Sourcing … and CQRS
  • 2. Vladik Khononov Chief Architect at Internovus http://il.linkedin.com/in/vladikkhononov/ vladikk vladikkhttp://vladikk.com
  • 8.
  • 10. – www.dictionary.com Model: A simplified representation of a system or phenomenon. – www.wikipedia.org ‫:מודל‬ ‫ייצוג‬‫תאורטי‬‫של‬‫מערכת‬‫מורכבת‬ , ‫שמטרתו‬ ‫לחקות‬‫את‬‫המערכת‬‫בהיבטים‬‫מהותיים‬ . ‫המודל‬‫אינו‬ ‫מתאר‬‫כל‬‫תופעה‬‫במערכת‬ , ‫אלא‬‫מתייחס‬‫להיבטים‬ ‫מוגדרים‬‫ומצומצמים‬‫שלה‬ . ‫המודל‬‫מבוסס‬‫על‬‫קירוב‬‫של‬ ‫המציאות‬‫בדרך‬‫של‬‫הפשטה‬ , ‫איחוד‬‫ישויות‬‫והתעלמות‬ ‫מגורמים‬‫שהשפעתם‬‫אינה‬‫מהותית‬ .
  • 13. Good Domain Model • Not too much • Not too less • Sweet spot • The information we need • The information we will need
  • 14. Why domain models fail • We absolutely suck at predicting the future • No single model can suit all the use cases • Model transformations are painful
  • 16. • A customer has customer id number and a name • A customer has contact information: email, phone number • A customer can be in on of the following states: New, CallLater, Converted, NotInterested • A seller has seller id number, name and password • The selling home page contains a list of the customers in the following statuses: • New • CallLater (when scheduled call date is met)
  • 17. • Seller chooses a customer to call from the home page • Seller can change the customer’s status to “Converted”, “Not Interested” • Seller can schedule a future call by setting the future call date. The Customer’s status will change to “CallLater” • Seller can change name, email, and phone number
  • 18. enum Status { New, CallLater, Converted, NotInterested } class Customer { int Id; string Name; Status Status; DateTime? ScheduledCall; string Email; string PhoneNumber; } CREATE TABLE Customers ( ID INTEGER, Name CHAR(40), Email CHAR(40), PhoneNumber CHAR(40), Status INTEGER, ScheduledCall DATETIME, PRIMARY KEY (ID) ) class Seller { int Id; string Name; string Password; } CREATE TABLE Sellers ( ID INTEGER, Name CHAR(40), Password CHAR(40) PRIMARY KEY (ID) )
  • 19. • Seller can find customers by name, email, and/or phone number in the search page • The customers should be found by the current and the past values
  • 20. • If no new customers are available on the home page, it should display customers in the NotInterested status, if it was set more than a 30 days ago
  • 21. • Analysts should be able to review status changes history for each customer - change date and the new status
  • 22. class Seller { int Id; string Name; string Password; } CREATE TABLE Sellers ( ID INTEGER, Name CHAR(40), Password CHAR(40) PRIMARY KEY (ID) ) enum Status { New, CallLater, Converted, NotInterested } class Customer { int Id; string Name; Status Status; DateTime? ScheduledCall; string Email; string PhoneNumber; } CREATE TABLE Customers ( ID INTEGER, Name CHAR(40), Email CHAR(40), PhoneNumber CHAR(40), Status INTEGER, ScheduledCall DATETIME, PRIMARY KEY (ID) )
  • 23. Id Name Email Phone number Status Scheduled Call 10 John john@gmail.com 04-2342343 New
  • 24. Id Name Email Phone number Status Scheduled Call 10 John john@gmail.com 04-2342343 CallLater 27/10/2014
  • 25. Id Name Email Phone number Status Scheduled Call 10 John john@gmail.com 08-9876653 CallLater 27/10/2014
  • 26. Id Name Email Phone number Status Scheduled Call 10 John john@gmail.com 08-9876653 Converted
  • 27. Id Name Email Phone number Status Scheduled Call 10 John john@gmail.com 08-9876653 Converted
  • 28. Event Sourcing Capture all changes to an application state as a sequence of events ~ Martin Fowler
  • 29.
  • 30. class StatusChanged : IEvent { Status NewStatus; DateTime CreatedOn; int CreatedBy; } class FutureCallScheduled : IEvent { DateTime ScheduledCallTime; DateTime CreatedOn; int CreatedBy; } class ContactDetailsWereUpdated : IEvent { string NewName; string NewEmail; string NewPhone; DateTime CreatedOn; int CreatedBy; }
  • 31. class Customer { int Id; string Name; string Email; string PhoneNumber; Status Status; DateTime? ScheduledCall; List<IEvent> Events; … void Apply(StatusChanged e) { Status = e.NewStatus; Events.Add(e); } …. …. }
  • 32. class Customer { int Id; string Name; string Email; string PhoneNumber; Status Status; DateTime? ScheduledCall; List<IEvent> Events; … … void Apply(FutureCallScheduled e) { ScheduledCall = e.ScheduledCallTime; Events.Add(e); } … }
  • 33. class Customer { int Id; string Name; string Email; string PhoneNumber; Status Status; DateTime? ScheduledCall; List<IEvent> Events; … … … void Apply(ContactDetailsWereUpdated e) { Name = e.NewName; Email = e.NewEmail; PhoneNumber = e.NewPhoneNumber; Events.Add(e); } }
  • 34. Id Name Email Phone number Status Scheduled Call 10 John john@gmail.com 08-9876653 Converted
  • 35. 1. new StatusChanged(Status.CallLater) 2. new FutureCallScheduled(’27/10/2014’) 3. new ContactDetailsWereUpdated( NewPhoneNumber=’08-9876653’ ) 4. new StatusChanged(Status.Converted)
  • 36. Event Storage Entity Id + New events Entity IdEvent1, Event2, Event3, ….
  • 37. class CustomerSearchModel { int Id; List<string> Names; List<string> Emails; List<string> PhoneNumbers; Status Status; DateTime? ScheduledCall; … … … void Apply(ContactDetailsWereUpdated e) { Names.Add(e.NewName); Emails.Add(e.NewEmail); PhoneNumbers.Add(e.NewPhoneNumber); } }
  • 38. class CustomerAnalysisModel { int Id; string Name; string Email; string PhoneNumber; List<StatusChange> StatusChanges; DateTime? ScheduledCall; … void Apply(StatusChanged e) { StatusChanges.Add( new StatusChange(e.CreatedOn, e.NewStatus) ); } …. …. }
  • 39. class Customer { int Id; string Name; string Email; string PhoneNumber; Status Status; DateTime? ScheduledCall; List<IEvent> Events; }
  • 40. class CustomerSearchModel { int Id; List<string> Names; List<string> Emails; List<string> PhoneNumbers; Status Status; DateTime? ScheduledCall; }
  • 41. class CustomerAnalysisModel { int Id; string Name; string Email; string PhoneNumber; List<StatusChange> StatusChanges; DateTime? ScheduledCall; }
  • 42. Good Domain Model • Not too much • Not too less • Sweet spot • The information we need • The information we might need
  • 43. Why domain models fail • We absolutely suck at predicting the future • No single model can suit all the use cases (e.g.: transactional processing, business intelligence, search) • Model transformations are painful
  • 44.
  • 45. Event Storage Entity Id + New events Entity IdEvent1, Event2, Event3, ….
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52. • Event based models • Effective modeling • No future predicting required • Time machine • Retroactive debugging • Infrastructural freedom • Infinite scalability • Easy to scale writes • Easy to scale reads Conclusions
  • 54. Domain Types • Core Domain • Subdomain • Generic Subdomain
  • 56. Campaign Management (Core Domain) Creative Catalog (Subdomain) User Management (Generic Subdomain) Billing (Generic Subdomain)
  • 57. Before you try this at home • Read “Implementing Domain Driven Design” by Vaughn Vernon • Read “Domain Driven Design” by Eric Evans • Follow Greg Young, Udi Dahan, DDD community • Read DDD/CQRS on Google Groups • Join http://meetup.com/DDD-IL :)