Connecting the Dots, Data in Event Sourcing and Dimensional Modeling, How Close are They?

Photo by Hunter Harritt on Unsplash

Event Sourcing Design of the Online Book Store

It would be overkill to design event sourcing for this case of course, but let say we design the events, how the design will look like? Quoting Martin Fowler, Event Sourcing [1]:

Image by Author
Image by Author

Dimensional Model Design of the Online Book Store

Now, what about dimensional model of the use case? Before we go into the design, here are dimensional modeling steps suggested by Kimball [2]:

  1. Select business process
  2. Decide granularity
  3. Identify dimension
  4. Identify facts and measures
  1. Select business process: Sales
  2. Decide granularity: Order Item because I need book category. However, as only one book allowed per order, order item grain = sales grain
  3. Identify dimension: Book category, date
  4. Identify facts and measures: Book quantity
Image by Author
fact_sales JOIN dim_book ON fact_sales.book_id = dim_book.book_id

So… How close?

Assuming I’m building a dimensional model data from event sourcing data, from the example above, there are several things that I can conclude:

  • They both care about events, hence storing all events will make dimensional modeling a lot easier, as opposed to using change data capture or guessing state changes from the latest state in database.
  • I might need to join data from several events in order to get dimensional model I want. In the example above, Pay Success Event is the definition of sales, but it does not care about book detail. So I have to join Pay Success Event and Order Event in order to get Fact Sales table
  • Not covered in the example above, but building a dimension table will need some events as well, such as Add Book Event.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rendy B. Junior

Rendy B. Junior

Crazy dad. Data technology enthusiast. Youtube: Insinyur Data