event sourcing

17
Event Sourcing RICH 2016/04/15 GitHub

Upload: rich-lee

Post on 15-Jan-2017

109 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Event sourcing

Event SourcingRICH

2016/04/15GitHub

Page 2: Event sourcing
Page 3: Event sourcing

OutlineActive Record Pattern (ORM)

What’s Event Sourcing?

Pros & Cons

When to use ?

Frameworks & Projects

Page 4: Event sourcing

Active Record Pattern (ORM)MVC

View

Controller

Model (AR)

Database

Page 5: Event sourcing

Active Record Pattern (ORM)An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data. [M. Fowler]

Page 6: Event sourcing
Page 7: Event sourcing

Active Record Pattern (ORM)I think the ORM is

Page 8: Event sourcing

Active Record Pattern (ORM)But the fact is...

Page 9: Event sourcing

Active Record Pattern (ORM)SQL TO CRITERIA QUERY:SELECT * FROM NameCard WHERE statuus NOT IN (‘frozen’,’suspended’) AND private = ‘everyone’ ORDER BY lastUpdateDate DESC

Page 10: Event sourcing

Active Record Pattern (ORM)Pros:

Speeds-up Development (Time and Costs) - eliminates the need for repetitive SQL code. (find(), findAll(), update())

Overcomes vendor specific SQL differences (Decoupling)Reduce the cost of learning SQL

Cons:Performance (Query, Mapping)Memory consumptionORM fail to compete against SQL queries for complex queries. (Must use native SQL...)

Page 11: Event sourcing

What’s Event SourcingStore all application state changes as a sequence of events

Not just can we query these events, we can also use the event log to reconstruct past states

A foundation to automatically adjust the state to cope with retroactive changes

[M. Fowler]

Page 12: Event sourcing
Page 13: Event sourcing
Page 14: Event sourcing

Pros & ConsPros:

Bypass the O-R impedance mismatchEasy way to undo thingsDebugability and traceabilityAfter-the-fact data analysis of Event Streams

Cons:Much less framework/community/vendor supportAwkward queries (solved by CQRS)

Page 15: Event sourcing

When to use?Building rich object-oriented domain models (e.g. DDD)Accountability/Debugability is criticalNeed version control/undo for data (e. G. Wikis, Google Docs)your business derives value or competitive advantage from event

datayou're building a scaleable system based on the CQRS pattern

Page 16: Event sourcing

Framework & ProjectsEvent Store

Open Source database for Event Sourcing

Akka PersistenceActor model

EventStore2A framework for creating event sourced applications in Java

maven-archetype-eventsourcing

Page 17: Event sourcing

Reference[Event Sourcing] http://martinfowler.com/eaaDev/EventSourcing.html

[Active Record] http://www.martinfowler.com/eaaCatalog/activeRecord.html

[Event Sourcing in Action] https://ookami86.github.io/event-sourcing-in-practice/

[CQRS] http://martinfowler.com/bliki/CQRS.html

[Microservice] http://martinfowler.com/articles/microservices.html

[maven-archetype-eventsourcing] https://github.com/jansoren/maven-archetype-eventsourcing