11
Event Sourcing @derek_comartin CodeOpinion.com

Event Sourcing

Embed Size (px)

DESCRIPTION

Event Sourcing Tech Talk by Derek Comartin @ Windsor Hackforge

Citation preview

Page 1: Event Sourcing

Event Sourcing

@derek_comartinCodeOpinion.com

Page 2: Event Sourcing

Agenda● Typical Data Persistence● Overview● Events● Why?● Queries● Drawbacks

Page 3: Event Sourcing

Typical Data Persistence

● Maintain current state● Concurrent users, data update conflicts.● Auditing

Page 4: Event Sourcing

Overview

● Old concept● Using already (transaction log)● Capture Intent● Event = State Change● Sequence of Events● Append Only

Page 5: Event Sourcing

Events

● Describes state change● Past tense● Source of truth● Audit log

Page 6: Event Sourcing

Event Stream

Started Shopping

Added T-Shirt

Added Socks

Removed Socks

Added Coupon

Page 7: Event Sourcing

EventStartedShopping{

CartId: f5a7f55d-1e33-440c-836c-ea50fc59a274,CustomerId: f98902b3-e8cf-4b7a-b561-5e39a06b5e0c,Date: 2014-01-03 15:36:08,

}

AddedSocksToShoppingCart{

CartId: f5a7f55d-1e33-440c-836c-ea50fc59a274,ProductId: ed00fa0b-6412-4cc6-bbac-14702bfeff3f,Quantity: 1,

}

Page 8: Event Sourcing

Why?

● Captures business intent● Transaction & Audit log● Build/Rebuild to any model● Debugging● Integration with other systems

Page 9: Event Sourcing

Queries● Generate Read Model from Events● Secondary Data Source required● Eventual Consistency

Started Shopping

Added T-Shirt

Added Socks

Removed Socks

Added Coupon

Any model you can think of!

Cart TableCartId

ProductIdQuantity

Denormalized TableCartId

CustomerNameProductIdQuantity

Price

Page 10: Event Sourcing

CQRS/ES

Data StorageDomain Object

Domain Object

Command Handlers

Client

CommandDTO

Message Queue

Read Layer

Facade

QueryDTO

Event Storage

Events

Message Queue Event Handlers

Data Storage

Page 11: Event Sourcing

Drawbacks

● Multiple Models / Data Sources● Versioning● Performance● Maturity / Public Knowledge