Presentation is loading. Please wait.

Presentation is loading. Please wait.

Event Sourcing Cameron Fletcher. Agenda  What is an Event?  Events as a Storage Mechanism  Versioning  Testing with Events  Performance and Scalability.

Similar presentations


Presentation on theme: "Event Sourcing Cameron Fletcher. Agenda  What is an Event?  Events as a Storage Mechanism  Versioning  Testing with Events  Performance and Scalability."— Presentation transcript:

1 Event Sourcing Cameron Fletcher

2 Agenda  What is an Event?  Events as a Storage Mechanism  Versioning  Testing with Events  Performance and Scalability  Demonstration

3 What is an Event?

4 An Event An event is something that has happened in the past as a result of a change in state of our domain Fill glass Request to change state Glass has been filled Event Glass is already full! Glass is broken! Exception

5 Events as a Storage Mechanism

6

7

8 Carts CartIdHasCheckedOut 1False CartItems CartIdItemId Name 11 Domain Driven Design 12 Enterprise Integration Patterns 13 Event Centric Item Added Checkout Completed Shopping Cart Created True

9 Item Added Checkout Completed Shopping Cart Created Domain Object

10 Item Added Item Removed Shopping Cart Created Checkout Completed

11 Versioning

12 snapshot

13 Cart Domain Object Example // request to mutate state public void Add(Item item) { if (this.itemCount > 5) throw new CartFullException(this.id); ApplyChange( new ItemAdded(this.id, item.Name)); } // mutate state private void { this.itemCount++; }

14 Domain Object Base protected void { true); } private void bool isNew) { if (isNew) }

15 Domain Object Reconstitution public void LoadFromHistory(IEnumerable history) { foreach in history) false); }

16 Domain Object Persistence public IEnumerable GetUncommittedChanges() { return this.uncommittedChanges; } public void MarkChangesAsCommitted() { this.uncommittedChanges.Clear(); }

17 Testing with Events

18 Overdraw Attempts are Rejected Given An account with a balance of 100 When A debit is requested for 101 Then An InsufficientBalanceException is thrown

19 Overdraw Attempts are Rejected Given An account is created A deposit was made for 100 When A debit is requested for 101 Then An InsufficientBalanceException is thrown

20 Overdraw Attempts are Rejected Given A series of events When A command Then Zero or more events, or an exception is thrown

21 Overdraw Attempts are Rejected Given An account is created A deposit was made for 100 A debit is requested for 101 When A debit is requested for 20 Then An InsufficientBalanceException is thrown

22 Performance and Scalability

23 Performance and Scalability Benefits  Append-only model  Partitioning (Sharding)  Persisting Objects  Reconstituting Objects

24 Demonstration

25 Summary

26 Questions?

27


Download ppt "Event Sourcing Cameron Fletcher. Agenda  What is an Event?  Events as a Storage Mechanism  Versioning  Testing with Events  Performance and Scalability."

Similar presentations


Ads by Google