DEV Community

Moeen Kamali
Moeen Kamali

Posted on

unclearness about event sourcing

how i know the concepts about event soucring that important events of app are stored on event store databases. but there are many prallel questions.

1) how main DB works in this application? for example when wi store a data like (player transaction added 100 golds) how main database that stores current state of player/user should be used. can i do a CRUD to update the main database in other microservices or its different?

2) how SAGA benefits from event sourcing. does it benefit at all? for example when one of the microservices failed and we want to compensate the whole scenario, do we need to use event sourcing for that or an inner state memory is enough?

3) what is the best practice saving user events in event stores? as you may know event stores can get very big soon. assume that based on some condition we want to remake a user current state from its events? what is the right approach?

Top comments (4)

Collapse
 
phlash profile image
Phil Ashby

In case you haven't seen it, Martin Fowler has a good article on event sourcing that covers a lot of these questions: martinfowler.com/eaaDev/EventSourc...

Specifically to address your questions:
1/ Current object state, can be in a 'normal looking' database record, and can be used as the authoritative system of record, however you must ensure that any external changes to this also commit an event that represents that change.

2/ It depends 😁.. if your compensation mechanism includes time travel (eg: rolling back recent events) then the event log should be updated during the travel so it represents the entire sequence of changes including compensation after a failure. If no time travel is involved, then no new events need be generated.

3/ Event stores are designed to hold billions of events and process them efficiently, that said you can also look at: sharding event stores, especially if you have an obvious partition key such as user or customer identity and there are none or only a few cross-over queries; rolling up events beyond a historical threshold, especially if your business has an obvious threshold such as financial records not being held for more than 3 years.

Hope this helps..

Collapse
 
virtouso profile image
Moeen Kamali

i think projection is used to update the main database to apply the event on main database. right? i think orchestration is a must to make sure that main database is synced with events store.

Collapse
 
virtouso profile image
Moeen Kamali

another question is: is there any standard implementaion for event sourcing or any type of saving sequence of events is called event sourcing. martin fowler example is in c# as i needed but i could not find the project implementation of it on github or somewhere else.

Collapse
 
phlash profile image
Phil Ashby • Edited

This is where I admit to being the architect, not the detail guy 😁 IMO if you are storing immutable events such that the current application state can be recreated from them, then you are 'doing event sourcing', look at Martin's example of source control being an exemplar. As Martin mentions in the article introduction (from 2005!), he's not been able to get back to it and tidy up / create complete examples so you won't find anything from him on this. Personally, I would search for 'event sourcing exemplars'' and see what turns up... good luck!