event sourcing
TRANSCRIPT
OutlineActive Record Pattern (ORM)
What’s Event Sourcing?
Pros & Cons
When to use ?
Frameworks & Projects
Active Record Pattern (ORM)MVC
View
Controller
Model (AR)
Database
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]
Active Record Pattern (ORM)I think the ORM is
Active Record Pattern (ORM)But the fact is...
Active Record Pattern (ORM)SQL TO CRITERIA QUERY:SELECT * FROM NameCard WHERE statuus NOT IN (‘frozen’,’suspended’) AND private = ‘everyone’ ORDER BY lastUpdateDate DESC
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...)
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]
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)
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
Framework & ProjectsEvent Store
Open Source database for Event Sourcing
Akka PersistenceActor model
EventStore2A framework for creating event sourced applications in Java
maven-archetype-eventsourcing
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