I have new project to track the status of order transition. I'm unable to reach a conclusion as to implement as an accumulating snapshot or a type 2 slowly changing dimension. ETL integrates a number of individual systems as the order transits each stage. What is the best way to design it?
Milton Keynes, UK
Many businesses have one or more central dimensions that undergo a state transition as they touch multiple processes. Is it enough to track the changes to the dimension? Or is an accumulating snapshot needed?
I'll walk you through some decision criteria. But first a little refresher on the two design options the reader is considering.
Type 2 changes and timestamps
Type 2 changes track the history of something represented by a dimension. Each time there is a change to this item, a new row is inserted in to the dimension table.
This allows any row in a fact table to be associated with a historically accurate version of the dimension as of the relevant point in time.
In the reader's case, status of the order might be an attribute of an Order dimension. Modeled as a type 2 change, the dimension holds a status history for each order. Adding effective and expiration dates to each row, you know exactly when each state transition occrred.
An accumulating snapshot is a type of fact table that records a single row for something the enterprise tracks closely, such as a trouble ticket or mortgage application--or, in the reader's case, an order.
This fact table contains multiple references to the date dimension -- one for each of the major milestones that the item in question can reach. In the case of the order, this might be the date of order, the date of credit approval, the date of picking, the date of shipment and the date of delivery.
Unlike other kinds of fact tables, the accumulating snapshot is intended to be updated. These dates are adjusted each time one of the milestones is reached.
There may also be facts that track the number of days (or minutes) spent between each milestone. These "lags" are a convenience -- they can be computed from the dates. (Building them into the fact table makes analysis much easier, but does require that the ETL process revisit rows on a regular basis, rather than when status changes.)
Avoiding correlated subqueries
If a type 2 slowly changing dimension with timestamps tracks the history, why consider an accumulating snapshot?
The analytic value of the accumulating snapshot is that it allows us to study the time spent at various stages. In the reader's case, it can make it simple to study the average time an order spends in the "picking" stage, for example.
We can do this with a type 2 slowly changing dimension as well, but it will be more difficult to study the average time between stages. For the order in question, days spent in the picking stage requires knowing the date of credit approval and the date picked. These will be in two different rows of the dimension. Now imagine doing this for all orders placed in January 2012. This will require a correlated subquery.
The accumulating snapshot pre-correlates these events and places them in a single row. This makes the queries much easier to write, and they are likely to run faster as well. The cost, of course, is the increased data integration burden of building the additional fact table.
Avoiding drilling across
When each of the discrete milestones is captured by a different fact table, lag may be computed without correlated subqueries. In this case, it will involve drilling across.
For example, separate fact tables track orders, credit approvals, picking and shipping. Each references the order dimension. Days spent in the picking stage can be studied by drilling across credit approvals and picking, with results linked by the common order dimension. 1
Here, the pressure for an accumulating snapshot is reduced. It may still be warranted, depending on your reporting tools, developer skills an user base.
Summary and final advice
In the end, your decision should boil down to the following:
- An accumulating snapshot should only be considered if you are studying the time spent between major milestones
- If it helps avoid correlated subqueries, it may be a strong option
- If it avoids drill-across queries, it may be a useful option
Also keep in mind the following:
- If you build an accumulating snapshot, you will probably also want to track status in the dimension as a type 2 change.
- Accumulating snapshots work best where the milestones are generally linear and predicable. If they are not, the design and maintenance will be significantly more complex.
- The accumulating snapshot should be derived from one or more base fact tables that capture the individual activities.
This is a popular topic for this blog. Here are some places where you can read more:
- Deeper into the Accumulating Snapshot (December 13, 2010) Discusses the accumulating snapshot and issues surrounding non-linear processes.
- Responding to star schema Detractors with Timestamps (March 12, 2008) Explains how a type 2 techniques and timestamps can track the change history of a dimension.
- Accumulating snapshots: are they necessary? (January 14, 2010) Looks at why the accumulating snapshot and type 2 technique may be used together.
- Q&A: Accumulating snapshots (October 1, 2010) Explores the cardinality relationship between accumulating snapshot and dimension table
- Three ways to drill across (December 23, 2011) Covers the drill-across process
- Chapter 8, "More Slow Change Techniques" discusses time stamped tracking of slow changes
- Chapter 11, "Transactions, Snapshots and Accumulating Snapshots" explores the accumulating snapshot in detail.
- Chapter 14, "Derived Schemas", discusses derivation of an accumulating snapshot from transaction-grained stars.
- Chapter 4, "A Fact Table for Each Process", includes a detailed discussion of dril-across analysis.
1 Note that this scenario applies to the reader, but does not always apply. Trouble tickets, for example, may be tracked in a single fact table that receives a new row for each status change. In this case, there is no drill-across option.