22
EVENT SOURCING And the Get Event Store How, Where, Why

Event sourcing with the GetEventStore

Embed Size (px)

Citation preview

EVENT SOURCINGAnd the Get Event Store

How, Where, Why

When should I use event sourcing?

ComplexDomain

CompetitiveAdvantageCQRS

DDD

Cart LinesLineId CartId Product Qty

3 1 Cap 1

CartCartId Shipping Address Credits

1 Centurion 2

Company A

Cart Lines HistoryCartId LineId CartHistId Product Qty

Cart HistoryHistId CartId Address Credits

1 1 Sandton 3

Company A

Cart TransactionsCartHistId Type Credits

1 Created 3

1

CartCreate

d

Cart Lines HistoryCartId LineId CartHistId Product Qty

1 1 2 Socks 2

Cart HistoryHistId CartId Address Credits

1 1 Sandton 32 1 Sandton 3

Company A

Cart TransactionsCartHistId Type Credits

1 Created 3

2Added

2Socks

1

CartCreate

d

Cart Lines HistoryCartId LineId CartHistId Product Qty

1 1 2 Socks 2

Cart HistoryHistId CartId Address Credits

1 1 Sandton 32 1 Sandton 33 1 Centurion 3

Company A

Cart TransactionsCartHistId Type Credits

1 Created 3

3

Relocated

Centurion

2Added

2Socks

1

CartCreate

d

Cart Lines HistoryCartId LineId CartHistId Product Qty

1 1 2 Socks 21 1 4 Socks 21 2 4 T-Shirt 3

Cart HistoryHistId CartId Address Credits

1 1 Sandton 32 1 Sandton 33 1 Centurion 34 1 Centurion 3

Company A

Cart TransactionsCartHistId Type Credits

1 Created 3

4Added 3T-Shirts3

Relocated

Centurion

2Added

2Socks

1

CartCreate

d

Cart Lines HistoryCartId LineId CartHistId Product Qty

1 1 2 Socks 21 1 4 Socks 21 2 4 T-Shirt 31 2 5 T-Shirt 3

Cart HistoryHistId CartId Address Credits

1 1 Sandton 32 1 Sandton 33 1 Centurion 34 1 Centurion 35 1 Centurion 3

Company A

Cart TransactionsCartHistId Type Credits

1 Created 3

There is no delete!

5

Removed 2

Socks

4Added 3T-Shirts3

Relocated

Centurion

2Added

2Socks

1

CartCreate

d

Cart Lines HistoryCartId LineId CartHistId Product Qty

1 1 2 Socks 21 1 4 Socks 21 2 4 T-Shirt 31 2 5 T-Shirt 3

Cart HistoryHistId CartId Address Credits

1 1 Sandton 32 1 Sandton 33 1 Centurion 34 1 Centurion 35 1 Centurion 36 1 Centurion 0

Company A

Cart TransactionsCartHistId Type Credits

1 Created 3

There is no delete!

5

Removed 2

Socks

4Added 3T-Shirts3

Relocated

Centurion

2Added

2Socks

1

CartCreate

d

Cart Lines HistoryCartId LineId CartHistId Product Qty

1 1 2 Socks 21 1 4 Socks 21 2 4 T-Shirt 31 2 5 T-Shirt 3

Cart HistoryHistId CartId Address Credits

1 1 Sandton 32 1 Sandton 33 1 Centurion 34 1 Centurion 35 1 Centurion 36 1 Centurion 0

Company A

Cart TransactionsCartHistId Type Credits

1 Created 36 Checkout -3

There is no delete!

6Checkou

t5

Removed 2

Socks

4Added 3T-Shirts3

Relocated

Centurion

2Added

2Socks

1

CartCreate

d

Cart Lines HistoryCartId LineId CartHistId Product Qty

1 1 2 Socks 21 1 4 Socks 21 2 4 T-Shirt 31 2 5 T-Shirt 31 3 7 Cap 1

Cart HistoryHistId CartId Address Credits

1 1 Sandton 32 1 Sandton 33 1 Centurion 34 1 Centurion 35 1 Centurion 36 1 Centurion 07 1 Centurion 0

Company A

Cart TransactionsCartHistId Type Credits

1 Created 36 Checkout -3

There is no delete!

7

Added 1

Cap

6Checkou

t5

Removed 2

Socks

4Added 3T-Shirts3

Relocated

Centurion

2Added

2Socks

1

CartCreate

d

Cart Lines HistoryCartId LineId CartHistId Product Qty

1 1 2 Socks 21 1 4 Socks 21 2 4 T-Shirt 31 2 5 T-Shirt 31 3 7 Cap 1

Cart HistoryHistId CartId Address Credits

1 1 Sandton 32 1 Sandton 33 1 Centurion 34 1 Centurion 35 1 Centurion 36 1 Centurion 07 1 Centurion 08 1 Centurion 2

Company A

Cart TransactionsCartHistId Type Credits

1 Created 36 Checkout -37 Invoice 1There is no delete!

8Invoic

ed7

Added 1

Cap

6Checkou

t5

Removed 2

Socks

4Added 3T-Shirts3

Relocated

Centurion

2Added

2Socks

1

CartCreate

d Cart -1

What are domain events?

-Verb in the past tense: CustomerRelocated / CargoShipped

-Part of the Ubiquitous Language

-Makes the concept explicit

CartCart Lines (n)

ShippingInformation

http://docs.geteventstore.com/introduction/event-sourcing-basics/

There is no delete!

8Invoic

ed7

Added 1

Cap

6Checkou

t5

Removed 2

Socks

4Added 3T-Shirts3

Relocated

Centurion

2Added

2Socks

1

CartCreate

d

What are domain events?

public class InventoryItemDeactivated { public readonly Guid InventoryItemId; public readonly string Reason;

public InventoryItemDeactivated(inventoryItemId, reason) { InventoryItemId = inventoryItemId; Reason = reason; }}

What are domain events?

{ eventId: 0, eventType: ‘InventoryItemDeactivated’, data: { InventoryItemId: 5, Reason: ‘No Stock’ }}

Project - Remote Metering

HistoryAny meter should have a full traceable history.

IntegrationsHardware specific, financial systems.

Performance1 immutable reading every 15 minutes.100 000 meters, 20GB per month.

DisconnectedInternal Storage

Inherent bad dataLoad Shedding

Time boundShould not change

100 000

Readings

100 000

Fixes

50 000

Billing

A smart utility solution.

?ComplexDomain ?

CompetitiveAdvantage

50 000

Jan 01 Jan 02 Jan 03 Jan 04 Jan 05

Jan 01 100

Jan 02 200 220

Jan 03 300

Jan 04 400

Jan 05 500

Calendar Time

Syste

m T

ime

- Forward only with History

Get Event Store - Features

Event-sourcing Event Store stores your data

as a series of immutable events over time, making it easy to build event-sourced

applications.

ProjectionsProjections allow you to react to events as they are written,

and to create new events when interesting

combinations occur.

Client InterfacesEvent Store has a native HTTP

interface based on the AtomPub protocol which is plenty fast enough for the

majority of use cases.

High Availability Event Store can run as a

cluster of nodes containing the same data, which remains available for writes provided

at least half the nodes are alive and connected.

Runs on Windows, Linux or Mac OS X

Event Store is written in C++, C# and JavaScript.

http://geteventstore.com/features

https://geteventstore.com/blog/20130708/testing-event-store-ha/index.html

Projections

Client Projection

Event Store

Lets create some events :)

DEMO

What else ?

EventualConsistency

Production /ReliabilityCQRS

DDD

- Come talk to me.

THANK YOUTerence Kruger

@tjmkruger