Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

15 – 16 November, Sofia ISTACon.org Event Sourcing By Vladik Khononov A New Dimension in Software Design

Slide 3

Slide 3 text

15 – 16 November, Sofia ISTACon.org

Slide 4

Slide 4 text

15 – 16 November, Sofia ISTACon.org

Slide 5

Slide 5 text

15 – 16 November, Sofia ISTACon.org

Slide 6

Slide 6 text

15 – 16 November, Sofia ISTACon.org Agenda • How it happened • Why it happened • How event sourcing solves the problem • Why event sourcing benefits the company

Slide 7

Slide 7 text

15 – 16 November, Sofia ISTACon.org Call Center Management

Slide 8

Slide 8 text

15 – 16 November, Sofia ISTACon.org LEAD • Id • Name • Email • Phone • Status (Available / Follow-up / Closed / Converted)

Slide 9

Slide 9 text

15 – 16 November, Sofia ISTACon.org Name Email Phone Status Stefan Ivanov [email protected] 03-27243457 Available Viktor Kovachev [email protected] 08-8332491 Available Martin Mateev [email protected] 04-8537112 Available Lilyana Yankov [email protected] 04-6092212 Available

Slide 10

Slide 10 text

15 – 16 November, Sofia ISTACon.org Name Email Phone Status Stefan Ivanov [email protected] 03-27243457 Available Viktor Kovachev [email protected] 08-8332491 Available Martin Mateev [email protected] 04-8537112 Available Lilyana Yankov [email protected] 04-6092212 Available

Slide 11

Slide 11 text

15 – 16 November, Sofia ISTACon.org

Slide 12

Slide 12 text

15 – 16 November, Sofia ISTACon.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; } }

Slide 13

Slide 13 text

15 – 16 November, Sofia ISTACon.org

Slide 14

Slide 14 text

15 – 16 November, Sofia ISTACon.org SELECT * FROM leads WHERE [name] LIKE ‘%name%’ OR [phone] LIKE ‘%phone%’ OR [email] LIKE ‘%email%’;

Slide 15

Slide 15 text

WTF??? ISTACon.org

Slide 16

Slide 16 text

15 – 16 November, Sofia ISTACon.org Lead #1410 Name Viktor Radkov Email [email protected] Phone 09-9801298 Status Available

Slide 17

Slide 17 text

15 – 16 November, Sofia ISTACon.org

Slide 18

Slide 18 text

15 – 16 November, Sofia ISTACon.org PM

Slide 19

Slide 19 text

15 – 16 November, Sofia ISTACon.org …1 month later

Slide 20

Slide 20 text

15 – 16 November, Sofia ISTACon.org

Slide 21

Slide 21 text

15 – 16 November, Sofia ISTACon.org PM

Slide 22

Slide 22 text

15 – 16 November, Sofia ISTACon.org …2 months later

Slide 23

Slide 23 text

15 – 16 November, Sofia ISTACon.org

Slide 24

Slide 24 text

15 – 16 November, Sofia ISTACon.org PM

Slide 25

Slide 25 text

15 – 16 November, Sofia ISTACon.org Search on stale data Status change dates Audit log for BI

Slide 26

Slide 26 text

15 – 16 November, Sofia ISTACon.org PM

Slide 27

Slide 27 text

15 – 16 November, Sofia ISTACon.org PM

Slide 28

Slide 28 text

15 – 16 November, Sofia ISTACon.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; } }

Slide 29

Slide 29 text

15 – 16 November, Sofia ISTACon.org Name Email Phone Status Follow-up Stefan Ivanov [email protected] 03-27243457 Available

Slide 30

Slide 30 text

15 – 16 November, Sofia ISTACon.org Name Email Phone Status Follow-up Date Stefan Ivanov [email protected] 050-8139904 Follow-up 23/11/2016

Slide 31

Slide 31 text

15 – 16 November, Sofia ISTACon.org Name Email Phone Status Follow-up Date Stefan Ivanov [email protected] 050-8139904 Converted

Slide 32

Slide 32 text

15 – 16 November, Sofia ISTACon.org Name Email Phone Status Follow-up Date Stefan Ivanov [email protected] 050-8139904 Converted

Slide 33

Slide 33 text

15 – 16 November, Sofia ISTACon.org

Slide 34

Slide 34 text

15 – 16 November, Sofia ISTACon.org Event Sourcing

Slide 35

Slide 35 text

15 – 16 November, Sofia ISTACon.org Changes = First class citizens = Events

Slide 36

Slide 36 text

15 – 16 November, Sofia ISTACon.org Lead Events • Lead Was Initialized (Id) • Status Changed (NewStatus) • Name Changed (NewName) • Contact Information Changed (NewEmail, NewPhone) • Followup Set (Date)

Slide 37

Slide 37 text

15 – 16 November, Sofia ISTACon.org Lead: Stefan Ivanov • Lead Was Initialized (1410) • Status Changed (Available) • Contact Information Changed ([email protected], 03-27243457) • Status Changed (Followup) • Followup Set (23/11/2016) • Contact Information Changed ([email protected], 050-8139904) • Status Changed (Converted)

Slide 38

Slide 38 text

15 – 16 November, Sofia ISTACon.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) {…} }

Slide 39

Slide 39 text

15 – 16 November, Sofia ISTACon.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; }

Slide 40

Slide 40 text

15 – 16 November, Sofia ISTACon.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; }

Slide 41

Slide 41 text

15 – 16 November, Sofia ISTACon.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; }

Slide 42

Slide 42 text

15 – 16 November, Sofia ISTACon.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; }

Slide 43

Slide 43 text

15 – 16 November, Sofia ISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed ([email protected],03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed ([email protected], 050-8139904)

Slide 44

Slide 44 text

15 – 16 November, Sofia ISTACon.org Name Email Phone Status Follow-up Date Stefan Ivanov [email protected] 050-8139904 Converted

Slide 45

Slide 45 text

15 – 16 November, Sofia ISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed ([email protected],03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed ([email protected], 050-8139904)

Slide 46

Slide 46 text

15 – 16 November, Sofia ISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed ([email protected],03-27243457)

Slide 47

Slide 47 text

15 – 16 November, Sofia ISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed ([email protected],03-27243457) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed ([email protected], 050-8139904)

Slide 48

Slide 48 text

15 – 16 November, Sofia ISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed ([email protected],03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed ([email protected], 050-8139904)

Slide 49

Slide 49 text

15 – 16 November, Sofia ISTACon.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; } }

Slide 50

Slide 50 text

15 – 16 November, Sofia ISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed ([email protected],03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed ([email protected], 050-8139904)

Slide 51

Slide 51 text

15 – 16 November, Sofia ISTACon.org public class LeadSearch { public long Id { get; private set; } … public List Emails; public List Phones; … public void Apply(ContactInfoChanged event) {…} … } Apply(ContactInfoChanged event) { this.Phones.Append(event.NewPhone); this.Emails.Append(event.NewEmail); }

Slide 52

Slide 52 text

15 – 16 November, Sofia ISTACon.org public class LeadStatusChangesModel { public long Id { get; set; } public List StatusChangesLog; … public void Apply(StatusChanged event) {…} … } Apply(StatusChanged event) { this.StatusChangesLog.Append( new StatusLog(event.NewStatus, DateTime.Now); );

Slide 53

Slide 53 text

15 – 16 November, Sofia ISTACon.org public class LeadStatusChangesModel { public long Id { get; set; } public List 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 Emails; public List Phones; … }

Slide 54

Slide 54 text

15 – 16 November, Sofia ISTACon.org Lead: Stefan Ivanov Lead Was Initialized (1410) Status Changed (Available) Contact Information Changed ([email protected],03-27243457) Status Changed (Converted) Status Changed (Followup) Followup Set (23/11/2016) Contact Information Changed ([email protected], 050-8139904)

Slide 55

Slide 55 text

15 – 16 November, Sofia ISTACon.org Events = Source of Truth Event Sourcing

Slide 56

Slide 56 text

15 – 16 November, Sofia ISTACon.org

Slide 57

Slide 57 text

15 – 16 November, Sofia ISTACon.org

Slide 58

Slide 58 text

15 – 16 November, Sofia ISTACon.org

Slide 59

Slide 59 text

15 – 16 November, Sofia ISTACon.org Storage: Event Store

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

15 – 16 November, Sofia ISTACon.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”)

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

15 – 16 November, Sofia ISTACon.org CQRS Command Query Responsibility Segregation

Slide 65

Slide 65 text

15 – 16 November, Sofia ISTACon.org CQRS • Command - write data • Query - read data • A use case can be either Command or Query. Never both

Slide 66

Slide 66 text

15 – 16 November, Sofia ISTACon.org Queries Read Model Read DB Commands Write Model Writes DB Projection engine

Slide 67

Slide 67 text

15 – 16 November, Sofia ISTACon.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 …

Slide 68

Slide 68 text

15 – 16 November, Sofia ISTACon.org Queries Read Model Read DB Commands Write Model Writes DB Projection engine

Slide 69

Slide 69 text

15 – 16 November, Sofia ISTACon.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

Slide 70

Slide 70 text

15 – 16 November, Sofia ISTACon.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; }

Slide 71

Slide 71 text

15 – 16 November, Sofia ISTACon.org Queries Read Model Read DB Commands Event Sourcing Event Store Projection engine

Slide 72

Slide 72 text

15 – 16 November, Sofia ISTACon.org Queries Read Model Read DB Commands Write Model Writes DB Projection engine Projection • RDBMS • Documents • Graphs • Files

Slide 73

Slide 73 text

15 – 16 November, Sofia ISTACon.org Queries Read Model Commands Write Model Writes DB Projection engine Projection • RDBMS • Documents • Graphs • Files • Multiple DBs Read DBs

Slide 74

Slide 74 text

15 – 16 November, Sofia ISTACon.org Queries Read Model Commands Write Model Writes DB Projection engine Read DBs Concurrency • Pessimistic • Optimistic • Optimistic on steroids

Slide 75

Slide 75 text

15 – 16 November, Sofia ISTACon.org SetFollowupCommand + StatusChangeEvent => Collision ChangeNameCommand + StatusChangeEvent => OK

Slide 76

Slide 76 text

15 – 16 November, Sofia ISTACon.org Event Sourcing + CQRS • Flexible business domain modeling • Insane scalability and availability • Rock solid infrastructure • …look great on your C.V.

Slide 77

Slide 77 text

15 – 16 November, Sofia ISTACon.org

Slide 78

Slide 78 text

15 – 16 November, Sofia ISTACon.org CQRS: When? Event Sourcing ‎CQRS Non-functional benefits

Slide 79

Slide 79 text

15 – 16 November, Sofia ISTACon.org Event Sourcing CQRS

Slide 80

Slide 80 text

15 – 16 November, Sofia ISTACon.org Event Sourcing: When? ?

Slide 81

Slide 81 text

15 – 16 November, Sofia ISTACon.org Subdomains Generic, Supporting, Core

Slide 82

Slide 82 text

15 – 16 November, Sofia ISTACon.org

Slide 83

Slide 83 text

15 – 16 November, Sofia ISTACon.org Subdomains Generic, Supporting, Core

Slide 84

Slide 84 text

15 – 16 November, Sofia ISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENT COMMISSIONS CALCULATION DESK MANAGEMENT VOIP MANAGEMENT EMAIL CAMPAIGNS

Slide 85

Slide 85 text

15 – 16 November, Sofia ISTACon.org Generic Subdomains

Slide 86

Slide 86 text

15 – 16 November, Sofia ISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENT COMMISSIONS CALCULATION DESK MANAGEMENT VOIP MANAGEMENT EMAIL CAMPAIGN

Slide 87

Slide 87 text

15 – 16 November, Sofia ISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENT COMMISSIONS CALCULATION DESK MANAGEMENT VOIP MANAGEMENT EMAIL CAMPAIGN

Slide 88

Slide 88 text

15 – 16 November, Sofia ISTACon.org Supporting Subdomains

Slide 89

Slide 89 text

15 – 16 November, Sofia ISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENT COMMISSIONS CALCULATION DESK MANAGEMENT VOIP MANAGEMENT EMAIL CAMPAIGN

Slide 90

Slide 90 text

15 – 16 November, Sofia ISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENT COMMISSIONS CALCULATION DESK MANAGEMENT VOIP MANAGEMENT EMAIL CAMPAIGN

Slide 91

Slide 91 text

15 – 16 November, Sofia ISTACon.org Core Domains

Slide 92

Slide 92 text

15 – 16 November, Sofia ISTACon.org CREATIVE CATALOG CAMPAIGN PUBLISHING BILLING USERS MANAGEMENT LEAD MANAGEMENT COMMISSIONS CALCULATION DESK MANAGEMENT VOIP MANAGEMENT EMAIL CAMPAIGN

Slide 93

Slide 93 text

15 – 16 November, Sofia ISTACon.org Event Sourcing: When? Core business domains

Slide 94

Slide 94 text

15 – 16 November, Sofia ISTACon.org Before you try this at home

Slide 95

Slide 95 text

15 – 16 November, Sofia ISTACon.org Available Event Stores • http://GetEventStore.com • NEventStore • Akka Persistence • Elastic Event Store (Coming soon)

Slide 96

Slide 96 text

15 – 16 November, Sofia ISTACon.org

Slide 97

Slide 97 text

15 – 16 November, Sofia ISTACon.org €100 Discount for attendees of ISTA 2016 https://ti.to/webengineers/ddd17/discount/istacon2016

Slide 98

Slide 98 text

15 – 16 November, Sofia ISTACon.org Domain-Driven Design • How to identify subdomains? • How to define business entities? • How do define events? • How to talk to business experts?

Slide 99

Slide 99 text

15 – 16 November, Sofia ISTACon.org

Slide 100

Slide 100 text

15 – 16 November, Sofia ISTACon.org Thank you! @vladikk vladikk.com vladikkhononov [email protected]