SlideShare una empresa de Scribd logo
1 de 14
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

Más contenido relacionado

Similar a 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 libertycsmyth501
 
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 Libertycsmyth501
 
"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 ArchitectureTom 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 Servicesukdpe
 
NOSQL Session GlueCon May 2010
NOSQL Session GlueCon May 2010NOSQL Session GlueCon May 2010
NOSQL Session GlueCon May 2010MongoDB
 
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 11gGuido Schmutz
 
Data Modeling and Relational to NoSQL
Data Modeling and Relational to NoSQLData Modeling and Relational to NoSQL
Data Modeling and Relational to NoSQLDATAVERSITY
 
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 MongoDBNick Court
 
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 2020Thodoris Bais
 
Introduction to terrastore
Introduction to terrastoreIntroduction to terrastore
Introduction to terrastoresvjson
 
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 WeaponPete 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 EUudidahan
 
Couchbase@live person meetup july 22nd
Couchbase@live person meetup   july 22ndCouchbase@live person meetup   july 22nd
Couchbase@live person meetup july 22ndIdo Shilon
 
Designing software with security in mind
Designing software with security in mindDesigning software with security in mind
Designing software with security in mindOmegapoint 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 WarehousingSimone Campora
 

Similar a 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
 

Más de Tomas Jansson

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 DeployTomas Jansson
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETTomas 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 TeamCityTomas Jansson
 
NServiceBus workshop presentation
NServiceBus workshop presentationNServiceBus workshop presentation
NServiceBus workshop presentationTomas 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 .NETTomas 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 APITomas Jansson
 

Más de 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
 

Último

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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

Notas del editor

  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.