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

Working on both event sourcing and dimensional modeling, looking at the concept and understanding some use cases, I feel they are somehow similar. They both care about state changes, not the state itself. This makes me wonder, how close are they actually, can they work together in a, let say, hypothetical use case?

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. Decide granularity
  2. Identify dimension
  3. Identify facts and measures
  1. Decide granularity: Order Item because I need book category. However, as only one book allowed per order, order item grain = sales grain
  2. Identify dimension: Book category, date
  3. Identify facts and measures: Book quantity
Image by Author
SELECT
sales_date,
dim_book.category,
SUM(quantity)
FROM
fact_sales JOIN dim_book ON fact_sales.book_id = dim_book.book_id
WHERE
sales_date > DATE_SUB(CURRENT_DATE(), INTERVAL 3 MONTH)
GROUP BY 1, 2

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:

  • 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.

References

Crazy dad. Data technology enthusiast. Youtube: Insinyur Data

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