ISTA 2016: Event Sourcing

ISTA 2016: Event Sourcing
15 – 16 November, SofiaISTACon.org
Event Sourcing
By Vladik Khononov
A New Dimension in Software Design
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
Agenda
• How it happened
• Why it happened
• How event sourcing solves the problem
• Why event sourcing benefits the company
15 – 16 November, SofiaISTACon.org
Call Center Management
15 – 16 November, SofiaISTACon.org
LEAD
• Id
• Name
• Email
• Phone
• Status (Available / Follow-up / Closed / Converted)
15 – 16 November, SofiaISTACon.org
Name Email Phone Status
Stefan Ivanov stefan@ivanov.com 03-27243457 Available
Viktor Kovachev viktor@kovachev.com 08-8332491 Available
Martin Mateev martin@mateev.com 04-8537112 Available
Lilyana Yankov lilyana@yankov.com 04-6092212 Available
15 – 16 November, SofiaISTACon.org
Name Email Phone Status
Stefan Ivanov stefan@ivanov.com 03-27243457 Available
Viktor Kovachev viktor@kovachev.com 08-8332491 Available
Martin Mateev martin@mateev.com 04-8537112 Available
Lilyana Yankov lilyana@yankov.com 04-6092212 Available
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
}
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
SELECT * FROM leads
WHERE [name] LIKE ‘%name%’ OR
[phone] LIKE ‘%phone%’ OR
[email] LIKE ‘%email%’;
WTF???
ISTACon.org
15 – 16 November, SofiaISTACon.org
Lead #1410
Name Viktor Radkov
Email viktor@radkov.com
Phone 09-9801298
Status Available
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
PM
15 – 16 November, SofiaISTACon.org
…1 month later
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
PM
15 – 16 November, SofiaISTACon.org
…2 months later
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
PM
15 – 16 November, SofiaISTACon.org
Search on stale data
Status change dates
Audit log for BI
15 – 16 November, SofiaISTACon.org
PM
15 – 16 November, SofiaISTACon.org
PM
15 – 16 November, SofiaISTACon.org
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
}
15 – 16 November, SofiaISTACon.org
Name Email Phone Status Follow-up
Stefan Ivanov stefan@ivanov.com 03-27243457 Available
15 – 16 November, SofiaISTACon.org
Name Email Phone Status Follow-up Date
Stefan Ivanov stefan@ivanov.com 050-8139904 Follow-up 23/11/2016
15 – 16 November, SofiaISTACon.org
Name Email Phone Status Follow-up Date
Stefan Ivanov stefan@ivanov.com 050-8139904 Converted
15 – 16 November, SofiaISTACon.org
Name Email Phone Status Follow-up Date
Stefan Ivanov stefan@ivanov.com 050-8139904 Converted
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
Event Sourcing
15 – 16 November, SofiaISTACon.org
Changes
=
First class citizens
=
Events
15 – 16 November, SofiaISTACon.org
Lead Events
• Lead Was Initialized (Id)
• Status Changed (NewStatus)
• Name Changed (NewName)
• Contact Information Changed (NewEmail, NewPhone)
• Followup Set (Date)
15 – 16 November, SofiaISTACon.org
Lead: Stefan Ivanov
• Lead Was Initialized (1410)
• Status Changed (Available)
• Contact Information Changed (stefan@ivanov.com, 03-27243457)
• Status Changed (Followup)
• Followup Set (23/11/2016)
• Contact Information Changed (stefan@ivanov.com, 050-8139904)
• Status Changed (Converted)
15 – 16 November, SofiaISTACon.org
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
public void Apply(LeadWasInitialized event) {…}
public void Apply(StatusChanged event) {…}
public void Apply(NameChanged event) {…}
public void Apply(ContactInfoChanged event) {…}
public void Apply(FollowupSet event) {…}
}
15 – 16 November, SofiaISTACon.org
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
public void Apply(LeadWasInitialized event) {…}
public void Apply(StatusChanged event) {…}
public void Apply(NameChanged event) {…}
public void Apply(ContactInfoChanged event) {…}
public void Apply(FollowupSet event) {…}
}
Apply(StatusChanged event) {
this.Status = event.NewStatus;
}
15 – 16 November, SofiaISTACon.org
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
public void Apply(LeadWasInitialized event) {…}
public void Apply(StatusChanged event) {…}
public void Apply(NameChanged event) {…}
public void Apply(ContactInfoChanged event) {…}
public void Apply(FollowupSet event) {…}
}
Apply(NameChanged event) {
this.Name = event.NewName;
}
15 – 16 November, SofiaISTACon.org
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
public void Apply(LeadWasInitialized event) {…}
public void Apply(StatusChanged event) {…}
public void Apply(NameChanged event) {…}
public void Apply(ContactInfoChanged event) {…}
public void Apply(FollowupSet event) {…}
}
Apply(ContactInfoChanged event) {
this.Phone = event.NewPhone;
this.Email = event.NewEmail;
}
15 – 16 November, SofiaISTACon.org
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
public void Apply(LeadWasInitialized event) {…}
public void Apply(StatusChanged event) {…}
public void Apply(NameChanged event) {…}
public void Apply(ContactInfoChanged event) {…}
public void Apply(FollowupSet event) {…}
}
Apply(FollowupSet event) {
this.FollowUpOn = event.Date;
}
15 – 16 November, SofiaISTACon.org
Lead: Stefan Ivanov
Lead Was Initialized (1410)
Status Changed (Available)
Contact Information Changed (stefan@ivanov.com,03-27243457)
Status Changed (Converted)
Status Changed (Followup)
Followup Set (23/11/2016)
Contact Information Changed (stefan@ivanov.com, 050-8139904)
15 – 16 November, SofiaISTACon.org
Name Email Phone Status Follow-up Date
Stefan Ivanov stefan@ivanov.com 050-8139904 Converted
15 – 16 November, SofiaISTACon.org
Lead: Stefan Ivanov
Lead Was Initialized (1410)
Status Changed (Available)
Contact Information Changed (stefan@ivanov.com,03-27243457)
Status Changed (Converted)
Status Changed (Followup)
Followup Set (23/11/2016)
Contact Information Changed (stefan@ivanov.com, 050-8139904)
15 – 16 November, SofiaISTACon.org
Lead: Stefan Ivanov
Lead Was Initialized (1410)
Status Changed (Available)
Contact Information Changed (stefan@ivanov.com,03-27243457)
15 – 16 November, SofiaISTACon.org
Lead: Stefan Ivanov
Lead Was Initialized (1410)
Status Changed (Available)
Contact Information Changed (stefan@ivanov.com,03-27243457)
Status Changed (Followup)
Followup Set (23/11/2016)
Contact Information Changed (stefan@ivanov.com, 050-8139904)
15 – 16 November, SofiaISTACon.org
Lead: Stefan Ivanov
Lead Was Initialized (1410)
Status Changed (Available)
Contact Information Changed (stefan@ivanov.com,03-27243457)
Status Changed (Converted)
Status Changed (Followup)
Followup Set (23/11/2016)
Contact Information Changed (stefan@ivanov.com, 050-8139904)
15 – 16 November, SofiaISTACon.org
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
}
15 – 16 November, SofiaISTACon.org
Lead: Stefan Ivanov
Lead Was Initialized (1410)
Status Changed (Available)
Contact Information Changed (stefan@ivanov.com,03-27243457)
Status Changed (Converted)
Status Changed (Followup)
Followup Set (23/11/2016)
Contact Information Changed (stefan@ivanov.com, 050-8139904)
15 – 16 November, SofiaISTACon.org
public class LeadSearch {
public long Id { get; private set; }
…
public List<string> Emails;
public List<string> Phones;
…
public void Apply(ContactInfoChanged event) {…}
…
}
Apply(ContactInfoChanged event) {
this.Phones.Append(event.NewPhone);
this.Emails.Append(event.NewEmail);
}
15 – 16 November, SofiaISTACon.org
public class LeadStatusChangesModel {
public long Id { get; set; }
public List<StatusLog> StatusChangesLog;
…
public void Apply(StatusChanged event) {…}
…
}
Apply(StatusChanged event) {
this.StatusChangesLog.Append(
new StatusLog(event.NewStatus,
DateTime.Now);
);
15 – 16 November, SofiaISTACon.org
public class LeadStatusChangesModel {
public long Id { get; set; }
public List<StatusLog> StatusChangesLog;
…
}
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
…
}
public class LeadSearch {
public long Id { get; private set; }
public List<string> Emails;
public List<string> Phones;
…
}
15 – 16 November, SofiaISTACon.org
Lead: Stefan Ivanov
Lead Was Initialized (1410)
Status Changed (Available)
Contact Information Changed (stefan@ivanov.com,03-27243457)
Status Changed (Converted)
Status Changed (Followup)
Followup Set (23/11/2016)
Contact Information Changed (stefan@ivanov.com, 050-8139904)
15 – 16 November, SofiaISTACon.org
Events = Source of Truth
Event Sourcing
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
Storage: Event Store
15 – 16 November, SofiaISTACon.org
Event Store API: The Good News
Append(Entity Id + New events)
GetEvents(Entity Id)Event1,

Event2,

Event3,
….
15 – 16 November, SofiaISTACon.org
Key (Entity Id) Value (Events list)
Lead #1410 1. LeadWasInitialized(1410)
2. StatusChanged(Available)
3. NameChanged(“Martin Mateev”)
4. StatusChanged(Converted)
Lead #1406 1. LeadWasInitialized(1406)
2. StatusChanged(Available’’’)
3. NameChanged(“Lilyana Yankov”)
15 – 16 November, SofiaISTACon.org
Event Store API: The Good News
Append(Entity Id + New events)
GetEvents(Entity Id)Event1,

Event2,

Event3,
….
15 – 16 November, SofiaISTACon.org
Event Store API: The Bad News
Append(Entity Id + New events)
GetEvents(Entity Id)Event1,

Event2,

Event3,
….
15 – 16 November, SofiaISTACon.org
CQRS
Command Query Responsibility Segregation
15 – 16 November, SofiaISTACon.org
CQRS
• Command - write data
• Query - read data
• A use case can be either Command or Query. Never both
15 – 16 November, SofiaISTACon.org
Queries
Read Model
Read DB
Commands
Write Model
Writes DB
Projection engine
15 – 16 November, SofiaISTACon.org
Event Sourced Model (Write)
Lead #1410 1. LeadWasInitialized(1410)
2. StatusChanged(Available)
3. NameChanged(“Martin Mateev”)
4. StatusChanged(Closed)
…
1000. StatusChanged(FollowUp)
1001. FollowupSet(16/11/2017)
Read Model
Id 1410
Name Martin Mateev
Status Followup
FollowupOn (Empty)
Email …
Phone …
15 – 16 November, SofiaISTACon.org
Queries
Read Model
Read DB
Commands
Write Model
Writes DB
Projection engine
15 – 16 November, SofiaISTACon.org
Event Sourced Model (Write)
Lead #1410 1. LeadWasInitialized(1410)
2. StatusChanged(Available)
3. NameChanged(“Martin Mateev”)
4. StatusChanged(Closed)
5. StatusChanged(Available)
6. NameChanged(“Viktor Rumenov”)
Read Model
Id 1410
Phone …
Status Available
FollowupOn (Empty)
Email …
Name Martin Mateev
15 – 16 November, SofiaISTACon.org
public class Lead {
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public LeadStatus Status { get; set; }
public DateTime? FollowupOn { get; set; }
public void Apply(LeadWasInitialized event) {…}
public void Apply(StatusChanged event) {…}
public void Apply(NameChanged event) {…}
public void Apply(ContactInfoChanged event) {…}
public void Apply(FollowupSet event) {…}
}
Apply(NameChanged event) {
this.Name = event.NewName;
}
15 – 16 November, SofiaISTACon.org
Queries
Read Model
Read DB
Commands
Event Sourcing
Event Store
Projection engine
15 – 16 November, SofiaISTACon.org
Queries
Read Model
Read DB
Commands
Write Model
Writes DB
Projection
engine
Projection
• RDBMS
• Documents
• Graphs
• Files
15 – 16 November, SofiaISTACon.org
Queries
Read Model
Commands
Write Model
Writes DB
Projection
engine
Projection
• RDBMS
• Documents
• Graphs
• Files
• Multiple DBs
Read DBs
15 – 16 November, SofiaISTACon.org
Queries
Read Model
Commands
Write Model
Writes DB
Projection
engine
Read DBs
Concurrency
• Pessimistic
• Optimistic
• Optimistic on steroids
15 – 16 November, SofiaISTACon.org
SetFollowupCommand + StatusChangeEvent => Collision
ChangeNameCommand + StatusChangeEvent => OK
15 – 16 November, SofiaISTACon.org
Event Sourcing + CQRS
• Flexible business domain modeling
• Insane scalability and availability
• Rock solid infrastructure
• …look great on your C.V.
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
CQRS: When?
Event Sourcing ➡ CQRS
Non-functional benefits
15 – 16 November, SofiaISTACon.org
Event Sourcing
CQRS
15 – 16 November, SofiaISTACon.org
Event Sourcing: When?
?
15 – 16 November, SofiaISTACon.org
Subdomains
Generic, Supporting, Core
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
Subdomains
Generic, Supporting, Core
15 – 16 November, SofiaISTACon.org
CREATIVE CATALOG
CAMPAIGN PUBLISHING
BILLING USERS MANAGEMENT
LEAD MANAGEMENTCOMMISSIONS CALCULATION
DESK MANAGEMENTVOIP MANAGEMENT
EMAIL CAMPAIGNS
15 – 16 November, SofiaISTACon.org
Generic Subdomains
15 – 16 November, SofiaISTACon.org
CREATIVE CATALOG
CAMPAIGN PUBLISHING
BILLING USERS MANAGEMENT
LEAD MANAGEMENTCOMMISSIONS CALCULATION
DESK MANAGEMENTVOIP MANAGEMENT
EMAIL CAMPAIGN
15 – 16 November, SofiaISTACon.org
CREATIVE CATALOG
CAMPAIGN PUBLISHING
BILLING USERS MANAGEMENT
LEAD MANAGEMENTCOMMISSIONS CALCULATION
DESK MANAGEMENTVOIP MANAGEMENT
EMAIL CAMPAIGN
15 – 16 November, SofiaISTACon.org
Supporting Subdomains
15 – 16 November, SofiaISTACon.org
CREATIVE CATALOG
CAMPAIGN PUBLISHING
BILLING USERS MANAGEMENT
LEAD MANAGEMENTCOMMISSIONS CALCULATION
DESK MANAGEMENTVOIP MANAGEMENT
EMAIL CAMPAIGN
15 – 16 November, SofiaISTACon.org
CREATIVE CATALOG
CAMPAIGN PUBLISHING
BILLING USERS MANAGEMENT
LEAD MANAGEMENTCOMMISSIONS CALCULATION
DESK MANAGEMENTVOIP MANAGEMENT
EMAIL CAMPAIGN
15 – 16 November, SofiaISTACon.org
Core Domains
15 – 16 November, SofiaISTACon.org
CREATIVE CATALOG
CAMPAIGN PUBLISHING
BILLING USERS MANAGEMENT
LEAD MANAGEMENTCOMMISSIONS CALCULATION
DESK MANAGEMENTVOIP MANAGEMENT
EMAIL CAMPAIGN
15 – 16 November, SofiaISTACon.org
Event Sourcing: When?
Core business domains
15 – 16 November, SofiaISTACon.org
Before you try this at home
15 – 16 November, SofiaISTACon.org
Available Event Stores
• http://GetEventStore.com
• NEventStore
• Akka Persistence
• Elastic Event Store (Coming soon)
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
€100 Discount for attendees of ISTA 2016
https://ti.to/webengineers/ddd17/discount/istacon2016
15 – 16 November, SofiaISTACon.org
Domain-Driven Design
• How to identify subdomains?
• How to define business entities?
• How do define events?
• How to talk to business experts?
15 – 16 November, SofiaISTACon.org
15 – 16 November, SofiaISTACon.org
Thank you!
@vladikk
vladikk.com
vladikkhononov
vladik@khononov.com
1 of 100

Recommended

CQRS by
CQRSCQRS
CQRSFabian Vilers
1.2K views29 slides
Introduction to CQRS - command and query responsibility segregation by
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationAndrew Siemer
3.5K views55 slides
CQRS by
CQRSCQRS
CQRSPiotr Pelczar
7.7K views43 slides
CQRS Evolved - CQRS + Akka.NET by
CQRS Evolved - CQRS + Akka.NETCQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETDavid Hoerster
6.3K views57 slides
CQRS recipes or how to cook your architecture by
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureThomas Jaskula
18K views104 slides
CQRS and Event Sourcing with MongoDB and PHP by
CQRS and Event Sourcing with MongoDB and PHPCQRS and Event Sourcing with MongoDB and PHP
CQRS and Event Sourcing with MongoDB and PHPDavide Bellettini
10.8K views103 slides

More Related Content

More from Vladik Khononov

7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018) by
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
627 views139 slides
How to Tame TDD - ISTA 2017 by
How to Tame TDD - ISTA 2017How to Tame TDD - ISTA 2017
How to Tame TDD - ISTA 2017Vladik Khononov
492 views148 slides
Mind Your Business. And Its Logic by
Mind Your Business. And Its LogicMind Your Business. And Its Logic
Mind Your Business. And Its LogicVladik Khononov
625 views62 slides
Introduction to Event Sourcing and CQRS (IASA-IL) by
Introduction to Event Sourcing and CQRS (IASA-IL)Introduction to Event Sourcing and CQRS (IASA-IL)
Introduction to Event Sourcing and CQRS (IASA-IL)Vladik Khononov
6.5K views61 slides
Introduction to Event Sourcing and CQRS by
Introduction to Event Sourcing and CQRSIntroduction to Event Sourcing and CQRS
Introduction to Event Sourcing and CQRSVladik Khononov
1.1K views52 slides
Introduction to MongoDB by
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBVladik Khononov
337 views16 slides

More from Vladik Khononov(8)

7 Years of DDD: Tackling Complexity in Marketing Systems (DDD Europe 2018) by 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)
Vladik Khononov627 views
Mind Your Business. And Its Logic by Vladik Khononov
Mind Your Business. And Its LogicMind Your Business. And Its Logic
Mind Your Business. And Its Logic
Vladik Khononov625 views
Introduction to Event Sourcing and CQRS (IASA-IL) by Vladik Khononov
Introduction to Event Sourcing and CQRS (IASA-IL)Introduction to Event Sourcing and CQRS (IASA-IL)
Introduction to Event Sourcing and CQRS (IASA-IL)
Vladik Khononov6.5K views
Introduction to Event Sourcing and CQRS by Vladik Khononov
Introduction to Event Sourcing and CQRSIntroduction to Event Sourcing and CQRS
Introduction to Event Sourcing and CQRS
Vladik Khononov1.1K views
Internal Project: Under the Hood by Vladik Khononov
Internal Project: Under the HoodInternal Project: Under the Hood
Internal Project: Under the Hood
Vladik Khononov535 views

Recently uploaded

SPICE PARK DEC2023 (6,625 SPICE Models) by
SPICE PARK DEC2023 (6,625 SPICE Models) SPICE PARK DEC2023 (6,625 SPICE Models)
SPICE PARK DEC2023 (6,625 SPICE Models) Tsuyoshi Horigome
17 views218 slides
NEW SUPPLIERS SUPPLIES (copie).pdf by
NEW SUPPLIERS SUPPLIES (copie).pdfNEW SUPPLIERS SUPPLIES (copie).pdf
NEW SUPPLIERS SUPPLIES (copie).pdfgeorgesradjou
15 views30 slides
Instrumentation & Control Lab Manual.pdf by
Instrumentation & Control Lab Manual.pdfInstrumentation & Control Lab Manual.pdf
Instrumentation & Control Lab Manual.pdfNTU Faisalabad
5 views63 slides
Introduction to CAD-CAM.pptx by
Introduction to CAD-CAM.pptxIntroduction to CAD-CAM.pptx
Introduction to CAD-CAM.pptxsuyogpatil49
5 views15 slides
CHEMICAL KINETICS.pdf by
CHEMICAL KINETICS.pdfCHEMICAL KINETICS.pdf
CHEMICAL KINETICS.pdfAguedaGutirrez
12 views337 slides
SUMIT SQL PROJECT SUPERSTORE 1.pptx by
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptxSumit Jadhav
12 views26 slides

Recently uploaded(20)

NEW SUPPLIERS SUPPLIES (copie).pdf by georgesradjou
NEW SUPPLIERS SUPPLIES (copie).pdfNEW SUPPLIERS SUPPLIES (copie).pdf
NEW SUPPLIERS SUPPLIES (copie).pdf
georgesradjou15 views
Instrumentation & Control Lab Manual.pdf by NTU Faisalabad
Instrumentation & Control Lab Manual.pdfInstrumentation & Control Lab Manual.pdf
Instrumentation & Control Lab Manual.pdf
NTU Faisalabad 5 views
Introduction to CAD-CAM.pptx by suyogpatil49
Introduction to CAD-CAM.pptxIntroduction to CAD-CAM.pptx
Introduction to CAD-CAM.pptx
suyogpatil495 views
SUMIT SQL PROJECT SUPERSTORE 1.pptx by Sumit Jadhav
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptx
Sumit Jadhav 12 views
Design of machine elements-UNIT 3.pptx by gopinathcreddy
Design of machine elements-UNIT 3.pptxDesign of machine elements-UNIT 3.pptx
Design of machine elements-UNIT 3.pptx
gopinathcreddy32 views
Generative AI Models & Their Applications by SN
Generative AI Models & Their ApplicationsGenerative AI Models & Their Applications
Generative AI Models & Their Applications
SN6 views
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) by Tsuyoshi Horigome
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,... by AakashShakya12
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
AakashShakya1266 views
_MAKRIADI-FOTEINI_diploma thesis.pptx by fotinimakriadi
_MAKRIADI-FOTEINI_diploma thesis.pptx_MAKRIADI-FOTEINI_diploma thesis.pptx
_MAKRIADI-FOTEINI_diploma thesis.pptx
fotinimakriadi7 views
GDSC Mikroskil Members Onboarding 2023.pdf by gdscmikroskil
GDSC Mikroskil Members Onboarding 2023.pdfGDSC Mikroskil Members Onboarding 2023.pdf
GDSC Mikroskil Members Onboarding 2023.pdf
gdscmikroskil12 views
Effect of deep chemical mixing columns on properties of surrounding soft clay... by AltinKaradagli
Effect of deep chemical mixing columns on properties of surrounding soft clay...Effect of deep chemical mixing columns on properties of surrounding soft clay...
Effect of deep chemical mixing columns on properties of surrounding soft clay...
AltinKaradagli6 views

ISTA 2016: Event Sourcing

  • 2. 15 – 16 November, SofiaISTACon.org Event Sourcing By Vladik Khononov A New Dimension in Software Design
  • 3. 15 – 16 November, SofiaISTACon.org
  • 4. 15 – 16 November, SofiaISTACon.org
  • 5. 15 – 16 November, SofiaISTACon.org
  • 6. 15 – 16 November, SofiaISTACon.org Agenda • How it happened • Why it happened • How event sourcing solves the problem • Why event sourcing benefits the company
  • 7. 15 – 16 November, SofiaISTACon.org Call Center Management
  • 8. 15 – 16 November, SofiaISTACon.org LEAD • Id • Name • Email • Phone • Status (Available / Follow-up / Closed / Converted)
  • 9. 15 – 16 November, SofiaISTACon.org Name Email Phone Status Stefan Ivanov stefan@ivanov.com 03-27243457 Available Viktor Kovachev viktor@kovachev.com 08-8332491 Available Martin Mateev martin@mateev.com 04-8537112 Available Lilyana Yankov lilyana@yankov.com 04-6092212 Available
  • 10. 15 – 16 November, SofiaISTACon.org Name Email Phone Status Stefan Ivanov stefan@ivanov.com 03-27243457 Available Viktor Kovachev viktor@kovachev.com 08-8332491 Available Martin Mateev martin@mateev.com 04-8537112 Available Lilyana Yankov lilyana@yankov.com 04-6092212 Available
  • 11. 15 – 16 November, SofiaISTACon.org
  • 12. 15 – 16 November, SofiaISTACon.org public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } }
  • 13. 15 – 16 November, SofiaISTACon.org
  • 14. 15 – 16 November, SofiaISTACon.org SELECT * FROM leads WHERE [name] LIKE ‘%name%’ OR [phone] LIKE ‘%phone%’ OR [email] LIKE ‘%email%’;
  • 16. 15 – 16 November, SofiaISTACon.org Lead #1410 Name Viktor Radkov Email viktor@radkov.com Phone 09-9801298 Status Available
  • 17. 15 – 16 November, SofiaISTACon.org
  • 18. 15 – 16 November, SofiaISTACon.org PM
  • 19. 15 – 16 November, SofiaISTACon.org …1 month later
  • 20. 15 – 16 November, SofiaISTACon.org
  • 21. 15 – 16 November, SofiaISTACon.org PM
  • 22. 15 – 16 November, SofiaISTACon.org …2 months later
  • 23. 15 – 16 November, SofiaISTACon.org
  • 24. 15 – 16 November, SofiaISTACon.org PM
  • 25. 15 – 16 November, SofiaISTACon.org Search on stale data Status change dates Audit log for BI
  • 26. 15 – 16 November, SofiaISTACon.org PM
  • 27. 15 – 16 November, SofiaISTACon.org PM
  • 28. 15 – 16 November, SofiaISTACon.org public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } }
  • 29. 15 – 16 November, SofiaISTACon.org Name Email Phone Status Follow-up Stefan Ivanov stefan@ivanov.com 03-27243457 Available
  • 30. 15 – 16 November, SofiaISTACon.org Name Email Phone Status Follow-up Date Stefan Ivanov stefan@ivanov.com 050-8139904 Follow-up 23/11/2016
  • 31. 15 – 16 November, SofiaISTACon.org Name Email Phone Status Follow-up Date Stefan Ivanov stefan@ivanov.com 050-8139904 Converted
  • 32. 15 – 16 November, SofiaISTACon.org Name Email Phone Status Follow-up Date Stefan Ivanov stefan@ivanov.com 050-8139904 Converted
  • 33. 15 – 16 November, SofiaISTACon.org
  • 34. 15 – 16 November, SofiaISTACon.org Event Sourcing
  • 35. 15 – 16 November, SofiaISTACon.org Changes = First class citizens = Events
  • 36. 15 – 16 November, SofiaISTACon.org Lead Events • Lead Was Initialized (Id) • Status Changed (NewStatus) • Name Changed (NewName) • Contact Information Changed (NewEmail, NewPhone) • Followup Set (Date)
  • 37. 15 – 16 November, SofiaISTACon.org Lead: Stefan Ivanov • Lead Was Initialized (1410) • Status Changed (Available) • Contact Information Changed (stefan@ivanov.com, 03-27243457) • Status Changed (Followup) • Followup Set (23/11/2016) • Contact Information Changed (stefan@ivanov.com, 050-8139904) • Status Changed (Converted)
  • 38. 15 – 16 November, SofiaISTACon.org public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } public void Apply(LeadWasInitialized event) {…} public void Apply(StatusChanged event) {…} public void Apply(NameChanged event) {…} public void Apply(ContactInfoChanged event) {…} public void Apply(FollowupSet event) {…} }
  • 39. 15 – 16 November, SofiaISTACon.org public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } public void Apply(LeadWasInitialized event) {…} public void Apply(StatusChanged event) {…} public void Apply(NameChanged event) {…} public void Apply(ContactInfoChanged event) {…} public void Apply(FollowupSet event) {…} } Apply(StatusChanged event) { this.Status = event.NewStatus; }
  • 40. 15 – 16 November, SofiaISTACon.org public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } public void Apply(LeadWasInitialized event) {…} public void Apply(StatusChanged event) {…} public void Apply(NameChanged event) {…} public void Apply(ContactInfoChanged event) {…} public void Apply(FollowupSet event) {…} } Apply(NameChanged event) { this.Name = event.NewName; }
  • 41. 15 – 16 November, SofiaISTACon.org public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } public void Apply(LeadWasInitialized event) {…} public void Apply(StatusChanged event) {…} public void Apply(NameChanged event) {…} public void Apply(ContactInfoChanged event) {…} public void Apply(FollowupSet event) {…} } Apply(ContactInfoChanged event) { this.Phone = event.NewPhone; this.Email = event.NewEmail; }
  • 42. 15 – 16 November, SofiaISTACon.org public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } public void Apply(LeadWasInitialized event) {…} public void Apply(StatusChanged event) {…} public void Apply(NameChanged event) {…} public void Apply(ContactInfoChanged event) {…} public void Apply(FollowupSet event) {…} } Apply(FollowupSet event) { this.FollowUpOn = event.Date; }
  • 43. 15 – 16 November, SofiaISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed (stefan@ivanov.com,03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed (stefan@ivanov.com, 050-8139904)
  • 44. 15 – 16 November, SofiaISTACon.org Name Email Phone Status Follow-up Date Stefan Ivanov stefan@ivanov.com 050-8139904 Converted
  • 45. 15 – 16 November, SofiaISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed (stefan@ivanov.com,03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed (stefan@ivanov.com, 050-8139904)
  • 46. 15 – 16 November, SofiaISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed (stefan@ivanov.com,03-27243457)
  • 47. 15 – 16 November, SofiaISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed (stefan@ivanov.com,03-27243457) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed (stefan@ivanov.com, 050-8139904)
  • 48. 15 – 16 November, SofiaISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed (stefan@ivanov.com,03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed (stefan@ivanov.com, 050-8139904)
  • 49. 15 – 16 November, SofiaISTACon.org public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } }
  • 50. 15 – 16 November, SofiaISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed (stefan@ivanov.com,03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed (stefan@ivanov.com, 050-8139904)
  • 51. 15 – 16 November, SofiaISTACon.org public class LeadSearch { public long Id { get; private set; } … public List<string> Emails; public List<string> Phones; … public void Apply(ContactInfoChanged event) {…} … } Apply(ContactInfoChanged event) { this.Phones.Append(event.NewPhone); this.Emails.Append(event.NewEmail); }
  • 52. 15 – 16 November, SofiaISTACon.org public class LeadStatusChangesModel { public long Id { get; set; } public List<StatusLog> StatusChangesLog; … public void Apply(StatusChanged event) {…} … } Apply(StatusChanged event) { this.StatusChangesLog.Append( new StatusLog(event.NewStatus, DateTime.Now); );
  • 53. 15 – 16 November, SofiaISTACon.org public class LeadStatusChangesModel { public long Id { get; set; } public List<StatusLog> StatusChangesLog; … } public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } … } public class LeadSearch { public long Id { get; private set; } public List<string> Emails; public List<string> Phones; … }
  • 54. 15 – 16 November, SofiaISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed (stefan@ivanov.com,03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed (stefan@ivanov.com, 050-8139904)
  • 55. 15 – 16 November, SofiaISTACon.org Events = Source of Truth Event Sourcing
  • 56. 15 – 16 November, SofiaISTACon.org
  • 57. 15 – 16 November, SofiaISTACon.org
  • 58. 15 – 16 November, SofiaISTACon.org
  • 59. 15 – 16 November, SofiaISTACon.org Storage: Event Store
  • 60. 15 – 16 November, SofiaISTACon.org Event Store API: The Good News Append(Entity Id + New events) GetEvents(Entity Id)Event1,
 Event2,
 Event3, ….
  • 61. 15 – 16 November, SofiaISTACon.org Key (Entity Id) Value (Events list) Lead #1410 1. LeadWasInitialized(1410) 2. StatusChanged(Available) 3. NameChanged(“Martin Mateev”) 4. StatusChanged(Converted) Lead #1406 1. LeadWasInitialized(1406) 2. StatusChanged(Available’’’) 3. NameChanged(“Lilyana Yankov”)
  • 62. 15 – 16 November, SofiaISTACon.org Event Store API: The Good News Append(Entity Id + New events) GetEvents(Entity Id)Event1,
 Event2,
 Event3, ….
  • 63. 15 – 16 November, SofiaISTACon.org Event Store API: The Bad News Append(Entity Id + New events) GetEvents(Entity Id)Event1,
 Event2,
 Event3, ….
  • 64. 15 – 16 November, SofiaISTACon.org CQRS Command Query Responsibility Segregation
  • 65. 15 – 16 November, SofiaISTACon.org CQRS • Command - write data • Query - read data • A use case can be either Command or Query. Never both
  • 66. 15 – 16 November, SofiaISTACon.org Queries Read Model Read DB Commands Write Model Writes DB Projection engine
  • 67. 15 – 16 November, SofiaISTACon.org Event Sourced Model (Write) Lead #1410 1. LeadWasInitialized(1410) 2. StatusChanged(Available) 3. NameChanged(“Martin Mateev”) 4. StatusChanged(Closed) … 1000. StatusChanged(FollowUp) 1001. FollowupSet(16/11/2017) Read Model Id 1410 Name Martin Mateev Status Followup FollowupOn (Empty) Email … Phone …
  • 68. 15 – 16 November, SofiaISTACon.org Queries Read Model Read DB Commands Write Model Writes DB Projection engine
  • 69. 15 – 16 November, SofiaISTACon.org Event Sourced Model (Write) Lead #1410 1. LeadWasInitialized(1410) 2. StatusChanged(Available) 3. NameChanged(“Martin Mateev”) 4. StatusChanged(Closed) 5. StatusChanged(Available) 6. NameChanged(“Viktor Rumenov”) Read Model Id 1410 Phone … Status Available FollowupOn (Empty) Email … Name Martin Mateev
  • 70. 15 – 16 November, SofiaISTACon.org public class Lead { public long Id { get; set; } public string Name { get; set; } public string Email { get; set; } public string Phone { get; set; } public LeadStatus Status { get; set; } public DateTime? FollowupOn { get; set; } public void Apply(LeadWasInitialized event) {…} public void Apply(StatusChanged event) {…} public void Apply(NameChanged event) {…} public void Apply(ContactInfoChanged event) {…} public void Apply(FollowupSet event) {…} } Apply(NameChanged event) { this.Name = event.NewName; }
  • 71. 15 – 16 November, SofiaISTACon.org Queries Read Model Read DB Commands Event Sourcing Event Store Projection engine
  • 72. 15 – 16 November, SofiaISTACon.org Queries Read Model Read DB Commands Write Model Writes DB Projection engine Projection • RDBMS • Documents • Graphs • Files
  • 73. 15 – 16 November, SofiaISTACon.org Queries Read Model Commands Write Model Writes DB Projection engine Projection • RDBMS • Documents • Graphs • Files • Multiple DBs Read DBs
  • 74. 15 – 16 November, SofiaISTACon.org Queries Read Model Commands Write Model Writes DB Projection engine Read DBs Concurrency • Pessimistic • Optimistic • Optimistic on steroids
  • 75. 15 – 16 November, SofiaISTACon.org SetFollowupCommand + StatusChangeEvent => Collision ChangeNameCommand + StatusChangeEvent => OK
  • 76. 15 – 16 November, SofiaISTACon.org Event Sourcing + CQRS • Flexible business domain modeling • Insane scalability and availability • Rock solid infrastructure • …look great on your C.V.
  • 77. 15 – 16 November, SofiaISTACon.org
  • 78. 15 – 16 November, SofiaISTACon.org CQRS: When? Event Sourcing ➡ CQRS Non-functional benefits
  • 79. 15 – 16 November, SofiaISTACon.org Event Sourcing CQRS
  • 80. 15 – 16 November, SofiaISTACon.org Event Sourcing: When? ?
  • 81. 15 – 16 November, SofiaISTACon.org Subdomains Generic, Supporting, Core
  • 82. 15 – 16 November, SofiaISTACon.org
  • 83. 15 – 16 November, SofiaISTACon.org Subdomains Generic, Supporting, Core
  • 84. 15 – 16 November, SofiaISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENTCOMMISSIONS CALCULATION DESK MANAGEMENTVOIP MANAGEMENT EMAIL CAMPAIGNS
  • 85. 15 – 16 November, SofiaISTACon.org Generic Subdomains
  • 86. 15 – 16 November, SofiaISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENTCOMMISSIONS CALCULATION DESK MANAGEMENTVOIP MANAGEMENT EMAIL CAMPAIGN
  • 87. 15 – 16 November, SofiaISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENTCOMMISSIONS CALCULATION DESK MANAGEMENTVOIP MANAGEMENT EMAIL CAMPAIGN
  • 88. 15 – 16 November, SofiaISTACon.org Supporting Subdomains
  • 89. 15 – 16 November, SofiaISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENTCOMMISSIONS CALCULATION DESK MANAGEMENTVOIP MANAGEMENT EMAIL CAMPAIGN
  • 90. 15 – 16 November, SofiaISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENTCOMMISSIONS CALCULATION DESK MANAGEMENTVOIP MANAGEMENT EMAIL CAMPAIGN
  • 91. 15 – 16 November, SofiaISTACon.org Core Domains
  • 92. 15 – 16 November, SofiaISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENTCOMMISSIONS CALCULATION DESK MANAGEMENTVOIP MANAGEMENT EMAIL CAMPAIGN
  • 93. 15 – 16 November, SofiaISTACon.org Event Sourcing: When? Core business domains
  • 94. 15 – 16 November, SofiaISTACon.org Before you try this at home
  • 95. 15 – 16 November, SofiaISTACon.org Available Event Stores • http://GetEventStore.com • NEventStore • Akka Persistence • Elastic Event Store (Coming soon)
  • 96. 15 – 16 November, SofiaISTACon.org
  • 97. 15 – 16 November, SofiaISTACon.org €100 Discount for attendees of ISTA 2016 https://ti.to/webengineers/ddd17/discount/istacon2016
  • 98. 15 – 16 November, SofiaISTACon.org Domain-Driven Design • How to identify subdomains? • How to define business entities? • How do define events? • How to talk to business experts?
  • 99. 15 – 16 November, SofiaISTACon.org
  • 100. 15 – 16 November, SofiaISTACon.org Thank you! @vladikk vladikk.com vladikkhononov vladik@khononov.com