SlideShare a Scribd company logo
STATE OR INTENT?
An Introduction to Event Sourcing
Oslo/NDC
Tomas Jansson
14/06/2013
THIS IS ME
Tomas Jansson
Manager & Group Lead .NET
BEKK Oslo
@TomasJansson
tomas.jansson@bekk.no
github.com/mastoj
blog.tomasjansson.com
WHY USE NOSQL IF WE ARE STORING THE SAME THING?
State
Tables
ORM
Anemic domain model
State
Document
Mapping
Anemic domain model
RDBMS
NoSQL
(Document store)
WHAT DO WE REALLY GAIN WITH A DOCUMENT STORE?
?
STORE THE INTENT INSTEAD OF THE STATE
Event
Sourcing
Understand
the
business
Testing
No
impedance
mismatch
Integration
Error fixing
Additional
value from
history
WHAT IS AN EVENT?
An event is something that has happened in the past
Examples:
CustomerMoved
TableReserved
OrderPlaced
Compare to actions:
MoveCustomer
ReserveTable
PlaceOrder
UNDERSTAND THE BUSINESS
What data is stored
What was the
intention (the event)
Focus
TESTING 1: SOMEONE CORRECTS THE ADDRESS OF A CUSTOMER
[TestFeature]
public class CustomerTests : BaseTestSetup
{
[Test]
public void When_The_Changing_The_Address_The_Address_Should_Change()
{
// Given
AddEvent(new CustomerCreated(1, "Tomas"));
AddEvent(
new AddressAdded(1, new Address("Street 1", "Oslol", "4040", "Norway")));
var customer = _domainRepository.Get<Customer>(1);
// When
customer.CorrectAddress(new Address("Street 1", "Oslo", "4040", "Norway"));
var events = _domainRepository.Commit();
// Then
Assert.AreEqual(1, events.Count());
Assert.Contains(
new AddressChanged("Street 1", "Oslo", "4040", "Norway"), events);
}
}
TESTING 2: A CUSTOMER MOVES
[TestFeature]
public class CustomerTests : BaseTestSetup
{
[Test]
public void When_The_Customer_Moves_The_Address_Should_Change_And_Notify()
{
// Given
AddEvent(new CustomerCreated(1, "Tomas"));
AddEvent(
new AddressAdded(1, new Address("Street 1", "Oslo", "4040", "Norway")));
var customer = _domainRepository.Get<Customer>(1);
// When
customer.Move(new Address("New Street 9", "Oslo", "6666", "Norway"));
var events = _domainRepository.Commit();
// Then
Assert.AreEqual(2, events.Count());
Assert.Contains(new CustomerMoved(1), events);
Assert.Contains(
new AddressChanged("Street 1", "Oslo", "4040", "Norway"), events);
}
}
Testing what we really expect to happen, and we also tests the
absence of side effects!
NO IMPEDANCE MISMATCH
public class Customer
{
private Address _address;
public Customer(IEnumerable<IEvent> events)
{ ... }
private void Handle(AddressChanged @event)
{
_address = @event.Address;
}
public void Move(Address address)
{ ... }
public void ChangeAddress(Address address)
{ ... }
.
.
.
}
Build instance from events
AddressChanged (an event)
is part of the domain
THE LAST THREE
Easier to make integration
async and explicit
Parties that are intrested can
just tail the event source
Focus is on behavior  fixing
the root cause instead of
changing the data
Complete audit log
Just replay the events
Integration Error fixing
Additional value
from history
THE NEGATIVE SIDE OF EVENT SOURCING
Defining events is hard!
No tooling available
Lack of information regarding Event Sourcing
Projection of the events might be considered complex
RESOURCES
Rinat Abduling about why event sourcing: http://bliki.abdullin.com/event-sourcing/why
Events as a storage mechanism: http://cqrs.wordpress.com/documents/events-as-storage-mechanism/
My post about the subject: http://tinyurl.com/StateOrIntent
Thank you!
@TomasJansson

More Related Content

Similar to State or intent

MVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data libertyMVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data liberty
csmyth501
 
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data LibertyMVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
csmyth501
 
"An introduction to object-oriented programming for those who have never done...
"An introduction to object-oriented programming for those who have never done..."An introduction to object-oriented programming for those who have never done...
"An introduction to object-oriented programming for those who have never done...
Fwdays
 
Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...
Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...
Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...
Trivadis
 
Aesthetics and the Beauty of an Architecture
Aesthetics and the Beauty of an ArchitectureAesthetics and the Beauty of an Architecture
Aesthetics and the Beauty of an Architecture
Tom Scott
 
Windows Azure and a little SQL Data Services
Windows Azure and a little SQL Data ServicesWindows Azure and a little SQL Data Services
Windows Azure and a little SQL Data Services
ukdpe
 
NOSQL Session GlueCon May 2010
NOSQL Session GlueCon May 2010NOSQL Session GlueCon May 2010
NOSQL Session GlueCon May 2010
MongoDB
 
Oracle Event Delivery Network (EDN) of SOA Suite 11g
Oracle Event Delivery Network (EDN) of SOA Suite 11gOracle Event Delivery Network (EDN) of SOA Suite 11g
Oracle Event Delivery Network (EDN) of SOA Suite 11g
Guido Schmutz
 
Data Modeling and Relational to NoSQL
Data Modeling and Relational to NoSQLData Modeling and Relational to NoSQL
Data Modeling and Relational to NoSQL
DATAVERSITY
 
Data Warehouse Project Report
Data Warehouse Project Report Data Warehouse Project Report
Data Warehouse Project Report
Tom Donoghue
 
Moving from SQL Server to MongoDB
Moving from SQL Server to MongoDBMoving from SQL Server to MongoDB
Moving from SQL Server to MongoDB
Nick Court
 
Writing Good Tests
Writing Good TestsWriting Good Tests
Writing Good Tests
Matteo Baglini
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Bill Buchan
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020
Thodoris Bais
 
Introduction to terrastore
Introduction to terrastoreIntroduction to terrastore
Introduction to terrastore
svjson
 
JSON Schema: Your API's Secret Weapon
JSON Schema: Your API's Secret WeaponJSON Schema: Your API's Secret Weapon
JSON Schema: Your API's Secret Weapon
Pete Gamache
 
Udi Dahan: Event Sourcing Keynote @ DDD EU
Udi Dahan: Event Sourcing Keynote @ DDD EUUdi Dahan: Event Sourcing Keynote @ DDD EU
Udi Dahan: Event Sourcing Keynote @ DDD EU
udidahan
 
Couchbase@live person meetup july 22nd
Couchbase@live person meetup   july 22ndCouchbase@live person meetup   july 22nd
Couchbase@live person meetup july 22nd
Ido Shilon
 
Designing software with security in mind
Designing software with security in mindDesigning software with security in mind
Designing software with security in mind
Omegapoint Academy
 
ST-Toolkit, a Framework for Trajectory Data Warehousing
ST-Toolkit, a Framework for Trajectory Data WarehousingST-Toolkit, a Framework for Trajectory Data Warehousing
ST-Toolkit, a Framework for Trajectory Data Warehousing
Simone Campora
 

Similar to State or intent (20)

MVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data libertyMVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data liberty
 
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data LibertyMVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
 
"An introduction to object-oriented programming for those who have never done...
"An introduction to object-oriented programming for those who have never done..."An introduction to object-oriented programming for those who have never done...
"An introduction to object-oriented programming for those who have never done...
 
Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...
Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...
Trivadis TechEvent 2016 Polybase challenges Hive relational access to non-rel...
 
Aesthetics and the Beauty of an Architecture
Aesthetics and the Beauty of an ArchitectureAesthetics and the Beauty of an Architecture
Aesthetics and the Beauty of an Architecture
 
Windows Azure and a little SQL Data Services
Windows Azure and a little SQL Data ServicesWindows Azure and a little SQL Data Services
Windows Azure and a little SQL Data Services
 
NOSQL Session GlueCon May 2010
NOSQL Session GlueCon May 2010NOSQL Session GlueCon May 2010
NOSQL Session GlueCon May 2010
 
Oracle Event Delivery Network (EDN) of SOA Suite 11g
Oracle Event Delivery Network (EDN) of SOA Suite 11gOracle Event Delivery Network (EDN) of SOA Suite 11g
Oracle Event Delivery Network (EDN) of SOA Suite 11g
 
Data Modeling and Relational to NoSQL
Data Modeling and Relational to NoSQLData Modeling and Relational to NoSQL
Data Modeling and Relational to NoSQL
 
Data Warehouse Project Report
Data Warehouse Project Report Data Warehouse Project Report
Data Warehouse Project Report
 
Moving from SQL Server to MongoDB
Moving from SQL Server to MongoDBMoving from SQL Server to MongoDB
Moving from SQL Server to MongoDB
 
Writing Good Tests
Writing Good TestsWriting Good Tests
Writing Good Tests
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
 
NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020NoSQL Endgame DevoxxUA Conference 2020
NoSQL Endgame DevoxxUA Conference 2020
 
Introduction to terrastore
Introduction to terrastoreIntroduction to terrastore
Introduction to terrastore
 
JSON Schema: Your API's Secret Weapon
JSON Schema: Your API's Secret WeaponJSON Schema: Your API's Secret Weapon
JSON Schema: Your API's Secret Weapon
 
Udi Dahan: Event Sourcing Keynote @ DDD EU
Udi Dahan: Event Sourcing Keynote @ DDD EUUdi Dahan: Event Sourcing Keynote @ DDD EU
Udi Dahan: Event Sourcing Keynote @ DDD EU
 
Couchbase@live person meetup july 22nd
Couchbase@live person meetup   july 22ndCouchbase@live person meetup   july 22nd
Couchbase@live person meetup july 22nd
 
Designing software with security in mind
Designing software with security in mindDesigning software with security in mind
Designing software with security in mind
 
ST-Toolkit, a Framework for Trajectory Data Warehousing
ST-Toolkit, a Framework for Trajectory Data WarehousingST-Toolkit, a Framework for Trajectory Data Warehousing
ST-Toolkit, a Framework for Trajectory Data Warehousing
 

More from Tomas Jansson

Roslyn
RoslynRoslyn
File -> new project to deploy in 10 minutes with TeamCity and Octopus Deploy
File -> new project to deploy in 10 minutes with TeamCity and Octopus DeployFile -> new project to deploy in 10 minutes with TeamCity and Octopus Deploy
File -> new project to deploy in 10 minutes with TeamCity and Octopus Deploy
Tomas Jansson
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
Tomas Jansson
 
Deployment taken seriously with Octopus Deploy and TeamCity
Deployment taken seriously with Octopus Deploy and TeamCityDeployment taken seriously with Octopus Deploy and TeamCity
Deployment taken seriously with Octopus Deploy and TeamCity
Tomas Jansson
 
NServiceBus workshop presentation
NServiceBus workshop presentationNServiceBus workshop presentation
NServiceBus workshop presentation
Tomas Jansson
 
SignalR - Building an async web app with .NET
SignalR - Building an async web app with .NETSignalR - Building an async web app with .NET
SignalR - Building an async web app with .NET
Tomas Jansson
 
REST for .NET - Introduction to ASP.NET Web API
REST for .NET - Introduction to ASP.NET Web APIREST for .NET - Introduction to ASP.NET Web API
REST for .NET - Introduction to ASP.NET Web API
Tomas Jansson
 

More from Tomas Jansson (7)

Roslyn
RoslynRoslyn
Roslyn
 
File -> new project to deploy in 10 minutes with TeamCity and Octopus Deploy
File -> new project to deploy in 10 minutes with TeamCity and Octopus DeployFile -> new project to deploy in 10 minutes with TeamCity and Octopus Deploy
File -> new project to deploy in 10 minutes with TeamCity and Octopus Deploy
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
Deployment taken seriously with Octopus Deploy and TeamCity
Deployment taken seriously with Octopus Deploy and TeamCityDeployment taken seriously with Octopus Deploy and TeamCity
Deployment taken seriously with Octopus Deploy and TeamCity
 
NServiceBus workshop presentation
NServiceBus workshop presentationNServiceBus workshop presentation
NServiceBus workshop presentation
 
SignalR - Building an async web app with .NET
SignalR - Building an async web app with .NETSignalR - Building an async web app with .NET
SignalR - Building an async web app with .NET
 
REST for .NET - Introduction to ASP.NET Web API
REST for .NET - Introduction to ASP.NET Web APIREST for .NET - Introduction to ASP.NET Web API
REST for .NET - Introduction to ASP.NET Web API
 

Recently uploaded

GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
ScyllaDB
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
UiPathCommunity
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
leebarnesutopia
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
ScyllaDB
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Ukraine
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 

Recently uploaded (20)

GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 
Day 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio FundamentalsDay 2 - Intro to UiPath Studio Fundamentals
Day 2 - Intro to UiPath Studio Fundamentals
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdfLee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
Lee Barnes - Path to Becoming an Effective Test Automation Engineer.pdf
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's TipsGetting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
Getting the Most Out of ScyllaDB Monitoring: ShareChat's Tips
 
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
GlobalLogic Java Community Webinar #18 “How to Improve Web Application Perfor...
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 

State or intent

  • 1. STATE OR INTENT? An Introduction to Event Sourcing Oslo/NDC Tomas Jansson 14/06/2013
  • 2. THIS IS ME Tomas Jansson Manager & Group Lead .NET BEKK Oslo @TomasJansson tomas.jansson@bekk.no github.com/mastoj blog.tomasjansson.com
  • 3. WHY USE NOSQL IF WE ARE STORING THE SAME THING? State Tables ORM Anemic domain model State Document Mapping Anemic domain model RDBMS NoSQL (Document store)
  • 4. WHAT DO WE REALLY GAIN WITH A DOCUMENT STORE? ?
  • 5. STORE THE INTENT INSTEAD OF THE STATE Event Sourcing Understand the business Testing No impedance mismatch Integration Error fixing Additional value from history
  • 6. WHAT IS AN EVENT? An event is something that has happened in the past Examples: CustomerMoved TableReserved OrderPlaced Compare to actions: MoveCustomer ReserveTable PlaceOrder
  • 7. UNDERSTAND THE BUSINESS What data is stored What was the intention (the event) Focus
  • 8. TESTING 1: SOMEONE CORRECTS THE ADDRESS OF A CUSTOMER [TestFeature] public class CustomerTests : BaseTestSetup { [Test] public void When_The_Changing_The_Address_The_Address_Should_Change() { // Given AddEvent(new CustomerCreated(1, "Tomas")); AddEvent( new AddressAdded(1, new Address("Street 1", "Oslol", "4040", "Norway"))); var customer = _domainRepository.Get<Customer>(1); // When customer.CorrectAddress(new Address("Street 1", "Oslo", "4040", "Norway")); var events = _domainRepository.Commit(); // Then Assert.AreEqual(1, events.Count()); Assert.Contains( new AddressChanged("Street 1", "Oslo", "4040", "Norway"), events); } }
  • 9. TESTING 2: A CUSTOMER MOVES [TestFeature] public class CustomerTests : BaseTestSetup { [Test] public void When_The_Customer_Moves_The_Address_Should_Change_And_Notify() { // Given AddEvent(new CustomerCreated(1, "Tomas")); AddEvent( new AddressAdded(1, new Address("Street 1", "Oslo", "4040", "Norway"))); var customer = _domainRepository.Get<Customer>(1); // When customer.Move(new Address("New Street 9", "Oslo", "6666", "Norway")); var events = _domainRepository.Commit(); // Then Assert.AreEqual(2, events.Count()); Assert.Contains(new CustomerMoved(1), events); Assert.Contains( new AddressChanged("Street 1", "Oslo", "4040", "Norway"), events); } } Testing what we really expect to happen, and we also tests the absence of side effects!
  • 10. NO IMPEDANCE MISMATCH public class Customer { private Address _address; public Customer(IEnumerable<IEvent> events) { ... } private void Handle(AddressChanged @event) { _address = @event.Address; } public void Move(Address address) { ... } public void ChangeAddress(Address address) { ... } . . . } Build instance from events AddressChanged (an event) is part of the domain
  • 11. THE LAST THREE Easier to make integration async and explicit Parties that are intrested can just tail the event source Focus is on behavior  fixing the root cause instead of changing the data Complete audit log Just replay the events Integration Error fixing Additional value from history
  • 12. THE NEGATIVE SIDE OF EVENT SOURCING Defining events is hard! No tooling available Lack of information regarding Event Sourcing Projection of the events might be considered complex
  • 13. RESOURCES Rinat Abduling about why event sourcing: http://bliki.abdullin.com/event-sourcing/why Events as a storage mechanism: http://cqrs.wordpress.com/documents/events-as-storage-mechanism/ My post about the subject: http://tinyurl.com/StateOrIntent

Editor's Notes

  1. Present thetopic Deployment
  2. Keep it short
  3. I’ve written down ”Anemic domain model” since the domain objects we have are loaded by mapping, and we are not setting the properties of our object based on domain actions/events.
  4. I don’t know, it’s still just the data no extra information. Maybe some mapping, but the tools we have today for relational databases often solve that.We are not solving the real problem we are only subotimizing what we do. It’s like putting a bandaid on a broken leg.
  5. And how can we do that? Use event sourcing.What will we gaing? Click.
  6. What does this mean? This means you have to have your business logic before saving the event.
  7. Instead of focusing on this data need to be stored and that should set this flag in this table you shift focus to what the intention of the action is. If the action succeed you store the intention (or event).
  8. Testing is simple and explicit. The setup is clear, the action is clear and the intention is clear.
  9. You can load them from a set of events.The events is part of the domain.