100 Days of Data Engineering Day 10B retail case study

Chapter: Data Warehousing in Retail – A Case Study


Retailers operate in a fast-paced, highly competitive landscape. The ability to extract insights from vast amounts of data is a crucial competitive advantage. Data warehouses, designed specifically for analytics, provide a powerful foundation for retail decision-making. In this chapter, we’ll delve into the principles of data warehousing through a retail store case study and explore how to design an effective data warehouse schema.

Four-Step Dimensional Design Process

Dimensional modeling is a cornerstone of data warehouse design. Here’s a breakdown of the four key steps:

  1. Select the Business Process: Start by identifying a core process critical to the retail business. Examples include sales transactions, inventory management, customer behavior, or marketing campaigns. We’ll focus on sales transactions.
  2. Declare the Grain: The grain determines the level of detail captured in the fact table. A fine-grained fact table offers more detailed analysis potential. In our retail example, we’ll use an individual sales line item as our grain, allowing us to analyze sales by product, time, and location.
  3. Choose the Dimensions: Dimensions are the ‘who, what, when, where, and why’ that provide context to the measurements in the fact table. In our retail case, relevant dimensions include:
    • Product: Details like SKU, brand, category, color, size, etc.
    • Date/Time: Date and time of the sale.
    • Store: Geographic location and store characteristics.
    • Promotion: Details of any promotions applied to the sale.
    • Transaction Number: A unique identifier for the transaction.
  4. Identify the Facts: These are the numerical metrics that will be the focus of analysis. In our retail scenario, core facts include:
    • Sales Amount: Dollar value of the line item
    • Quantity Sold: Number of units sold
    • Cost: The retailer’s cost for the item
    • Profit: (Calculated) Sales Amount – Cost

Dimension Table Attributes

Let’s explore some of our dimensions in more depth:

  • Date Dimension
    • Date dimensions are ubiquitous in data warehouses, enabling time-based analysis.
    • Common attributes include:
      • Individual date components (day, month, year)
      • Fiscal periods (quarter, fiscal year)
      • Weekday/weekend indicators
      • Holiday flags
  • Product Dimension
    • Provides rich descriptive context for sales analysis.
    • Typical attributes include:
      • SKU (Stock Keeping Unit)
      • Product name and description
      • Hierarchy (Brand > Category > Subcategory > Department )
      • Pricing information
      • Physical attributes (color, size, etc.)
  • Store Dimension
    • Allows for performance comparisons across locations.
    • Consider attributes like:
      • Address (city, state, zip code)
      • Region
      • Store type (flagship, outlet, etc.)
      • Demographics of the surrounding area
  • Promotion Dimension
    • Enables evaluation of promotion effectiveness.
    • May include:
      • Promotion code or description
      • Discount type (percentage off, dollar off)
      • Start and end dates
      • Marketing channel (email, social media, etc.)
  • Degenerate Transaction Number Dimension
    • This dimension consists solely of the unique transaction number.
    • Its primary purpose is to provide a link back to the source transaction system if detailed order-level information is needed.

Retail Schema in Action

Visualizing our model as a star schema helps understand its structure. The sales fact table sits at the center, with the dimensions radiating outwards. This design allows analysts to query the warehouse to answer questions like:

  • Sales by Region: What are the top-selling product categories in the Northeast vs. West Coast?
  • Promotion Performance: Which promotions generated the highest lift in sales volume compared to a baseline?
  • Seasonality Impact: How do holiday periods impact sales trends across different store locations?

Retail Schema Extensibility

The beauty of dimensional modeling lies in its adaptability. As business needs evolve, the model can be expanded to incorporate new perspectives. Let’s imagine the retailer wants to introduce a customer loyalty program:

  • New Customer Dimension: This would capture customer demographics, purchase history, and loyalty program tier.
  • Linking to Sales: The sales fact table could be updated with a foreign key to the customer dimension, allowing the retailer to analyze sales patterns by customer segment.

Resisting Comfort Zone Urges

  • Overloading Fact Tables: It’s tempting to pack fact tables with descriptive information. However, keep facts strictly numerical for optimal analytic flexibility. Descriptive data belongs in dimensions.

Retail Schema Extensibility

The beauty of dimensional modeling lies in its adaptability. As business needs evolve, the model can be expanded to incorporate new perspectives. Let’s imagine the retailer wants to introduce a customer loyalty program:

  • New Customer Dimension: This dimension would capture information like customer demographics, their purchase history, and their loyalty program membership tier.
  • Linking to Sales: By adding a foreign key referencing the customer dimension to the sales fact table, retailers could now analyze sales trends by customer segment.

Resisting Comfort Zone Urges

  • Overloading Fact Tables: It might feel natural to load fact tables with descriptive information. However, this compromises analysis flexibility. Keep facts strictly numerical, reserving descriptive information for dimensions.
  • Premature Optimization: Avoid overly complex designs upfront. Start with the core business needs and iterate as requirements evolve.

Dimension Normalization (Snowflaking)

Snowflaking involves breaking down dimensional hierarchies into separate, more detailed tables. Consider our Product Dimension:

  • Original: Product Category > Product Subcategory > Product Name
  • Snowflaked: A separate ‘Category’ table, a ‘Subcategory’ table, and the original ‘Product’ table, linked to each other.

Trade-offs of Snowflaking

  • Potential Performance Gains: Snowflaking can sometimes improve query performance for specific analytical scenarios.
  • Increased Complexity: More tables mean more joins during querying, potentially complicating analysis and model maintenance. Evaluate the trade-off carefully.

Too Many Dimensions

An excess of dimensions can hinder the usability and performance of your data warehouse. Here’s why:

  • Analyst Confusion: Too many dimensions make it difficult for users to understand the model and choose the right tables for their analysis.
  • Query Performance Impact: Excessively wide dimension tables can slow down query execution.

Prioritization is Key: Focus on adding the dimensions that offer the most valuable analytical insights for your specific retail business questions.

Surrogate Keys

Surrogate keys are unique, usually system-generated, identifiers assigned to each dimension record. They offer several advantages:

  • Immunity to Source System Changes: Business-meaningful keys from source systems might change (e.g., a product SKU reassignment). Surrogate keys isolate the warehouse from such changes.
  • Performance: Integer surrogate keys often perform better for joins than longer, text-based natural keys.
  • Simplified ETL: Data loading processes are streamlined when using consistent surrogate keys across the warehouse.

Market Basket Analysis

A classic retail analytics use case, made possible by a well-designed dimensional model, is market basket analysis. This technique identifies product combinations that are frequently purchased together. Let’s see how our schema supports this:

  • Fact Table Grain: Because we captured sales at the line item level, we can see individual products that were part of the same transaction.
  • Transaction Number: This acts as a grouping identifier, allowing us to analyze all the items purchased within a single transaction.

Market Basket Analysis Benefits:

  • Cross-selling: Identify items to promote together in bundles or displays.
  • Placement Optimization: Group frequently co-purchased items strategically within the store.
  • Customer Understanding: Gain insights into customer buying behavior.


  • Data warehouses are invaluable tools for gaining insights in the retail industry.
  • The dimensional modeling approach offers a structured and analytics-focused way to design data warehouses.
  • Start with core business processes, and carefully consider the most important dimensions and facts for your retail use cases.
  • Remain cautious about surrogate keys, snowflaking, and over-engineering your model upfront.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *