Your SlideShare is downloading. ×
STATE OR INTENT?An Introduction to Event SourcingOslo/NDCTomas Jansson14/06/2013
THIS IS METomas JanssonManager & Group Lead .NETBEKK Oslo@TomasJanssontomas.jansson@bekk.nogithub.com/mastojblog.tomasjans...
WHY USE NOSQL IF WE ARE STORING THE SAME THING?StateTablesORMAnemic domain modelStateDocumentMappingAnemic domain modelRDB...
WHAT DO WE REALLY GAIN WITH A DOCUMENT STORE??
STORE THE INTENT INSTEAD OF THE STATEEventSourcingUnderstandthebusinessTestingNoimpedancemismatchIntegrationError fixingAd...
WHAT IS AN EVENT?An event is something that has happened in the pastExamples:CustomerMovedTableReservedOrderPlacedCompare ...
UNDERSTAND THE BUSINESSWhat data is storedWhat was theintention (the event)Focus
TESTING 1: SOMEONE CORRECTS THE ADDRESS OF A CUSTOMER[TestFeature]public class CustomerTests : BaseTestSetup{[Test]public ...
TESTING 2: A CUSTOMER MOVES[TestFeature]public class CustomerTests : BaseTestSetup{[Test]public void When_The_Customer_Mov...
NO IMPEDANCE MISMATCHpublic class Customer{private Address _address;public Customer(IEnumerable<IEvent> events){ ... }priv...
THE LAST THREEEasier to make integrationasync and explicitParties that are intrested canjust tail the event sourceFocus is...
THE NEGATIVE SIDE OF EVENT SOURCINGDefining events is hard!No tooling availableLack of information regarding Event Sourcin...
RESOURCESRinat Abduling about why event sourcing: http://bliki.abdullin.com/event-sourcing/whyEvents as a storage mechanis...
Thank you!@TomasJansson
Upcoming SlideShare
Loading in...5
×

State or intent

616

Published on

Slides for a lighting talk about event sourcing I held 14th of June in 2013 at NDC Oslo.

Published in: Technology, Travel, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
616
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Present thetopic Deployment
  • Keep it short
  • 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.
  • 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.
  • And how can we do that? Use event sourcing.What will we gaing? Click.
  • What does this mean? This means you have to have your business logic before saving the event.
  • 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).
  • Testing is simple and explicit. The setup is clear, the action is clear and the intention is clear.
  • You can load them from a set of events.The events is part of the domain.
  • Transcript of "State or intent"

    1. 1. STATE OR INTENT?An Introduction to Event SourcingOslo/NDCTomas Jansson14/06/2013
    2. 2. THIS IS METomas JanssonManager & Group Lead .NETBEKK Oslo@TomasJanssontomas.jansson@bekk.nogithub.com/mastojblog.tomasjansson.com
    3. 3. WHY USE NOSQL IF WE ARE STORING THE SAME THING?StateTablesORMAnemic domain modelStateDocumentMappingAnemic domain modelRDBMSNoSQL(Document store)
    4. 4. WHAT DO WE REALLY GAIN WITH A DOCUMENT STORE??
    5. 5. STORE THE INTENT INSTEAD OF THE STATEEventSourcingUnderstandthebusinessTestingNoimpedancemismatchIntegrationError fixingAdditionalvalue fromhistory
    6. 6. WHAT IS AN EVENT?An event is something that has happened in the pastExamples:CustomerMovedTableReservedOrderPlacedCompare to actions:MoveCustomerReserveTablePlaceOrder
    7. 7. UNDERSTAND THE BUSINESSWhat data is storedWhat was theintention (the event)Focus
    8. 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(){// GivenAddEvent(new CustomerCreated(1, "Tomas"));AddEvent(new AddressAdded(1, new Address("Street 1", "Oslol", "4040", "Norway")));var customer = _domainRepository.Get<Customer>(1);// Whencustomer.CorrectAddress(new Address("Street 1", "Oslo", "4040", "Norway"));var events = _domainRepository.Commit();// ThenAssert.AreEqual(1, events.Count());Assert.Contains(new AddressChanged("Street 1", "Oslo", "4040", "Norway"), events);}}
    9. 9. TESTING 2: A CUSTOMER MOVES[TestFeature]public class CustomerTests : BaseTestSetup{[Test]public void When_The_Customer_Moves_The_Address_Should_Change_And_Notify(){// GivenAddEvent(new CustomerCreated(1, "Tomas"));AddEvent(new AddressAdded(1, new Address("Street 1", "Oslo", "4040", "Norway")));var customer = _domainRepository.Get<Customer>(1);// Whencustomer.Move(new Address("New Street 9", "Oslo", "6666", "Norway"));var events = _domainRepository.Commit();// ThenAssert.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 theabsence of side effects!
    10. 10. NO IMPEDANCE MISMATCHpublic 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 eventsAddressChanged (an event)is part of the domain
    11. 11. THE LAST THREEEasier to make integrationasync and explicitParties that are intrested canjust tail the event sourceFocus is on behavior  fixingthe root cause instead ofchanging the dataComplete audit logJust replay the eventsIntegration Error fixingAdditional valuefrom history
    12. 12. THE NEGATIVE SIDE OF EVENT SOURCINGDefining events is hard!No tooling availableLack of information regarding Event SourcingProjection of the events might be considered complex
    13. 13. RESOURCESRinat Abduling about why event sourcing: http://bliki.abdullin.com/event-sourcing/whyEvents as a storage mechanism: http://cqrs.wordpress.com/documents/events-as-storage-mechanism/My post about the subject: http://tinyurl.com/StateOrIntent
    14. 14. Thank you!@TomasJansson

    ×