Practice: E-commerce Platform
Scenario: You're designing a data model for Amazon's e-commerce platform to analyze sales performance, customer behavior, and inventory management.
Requirements:
- Track daily sales totals by product category
- Analyze customer purchase history for segmentation
- Calculate average order value (AOV) and customer lifetime value (CLV)
- Monitor product inventory levels
- Evaluate the effectiveness of marketing campaigns
Task: Create a high-level dimensional model to support these requirements.
Identify the core business process. What is the central event that generates most of the required metrics? Think about what happens when a customer makes a purchase.
Identify potential dimensions. Consider the "who, what, where, when" of the core business process. Who is involved in a sale? What is being sold? When does the sale occur?
Identify potential facts. What numerical values are generated when the core business process occurs? Think about quantities, amounts, and counts.
Consider slowly changing dimensions. Which entities might have attributes that change over time, and how should these changes be tracked?
Think about granularity. At what level of detail do you need to store data to support all the required analyses? Consider the trade-offs between granularity and performance.
Here's a high-level dimensional model for the e-commerce platform:
Fact Table:
- Sales_Fact
Dimension Tables:
- Date_Dim
- Product_Dim
- Customer_Dim
- Store_Dim (if applicable for omnichannel sales)
- Campaign_Dim
Fact Table Schema:
Sales_Fact ( date_key (FK), product_key (FK), customer_key (FK), store_key (FK), campaign_key (FK), order_id, quantity_sold, sales_amount, discount_amount, cost_amount, profit_amount )
Additional tables:
- Inventory_Snapshot_Fact (for daily inventory levels)
Explanation
Core Business Process:
- The central event here is a sale transaction. This forms the basis of our main fact table, Sales_Fact.
Granularity:
- The grain of the Sales_Fact table is at the individual product level within each order. This allows for maximum flexibility in analysis, supporting both detailed and aggregated views.
- Dimensions:
- Date_Dim: Supports time-based analysis and includes attributes like day, month, quarter, year, holiday flags, etc.
- Product_Dim: Contains product attributes including category, which is crucial for category-level analysis.
- Customer_Dim: Stores customer information for segmentation and customer-centric analysis.
- Store_Dim: If applicable, for analyzing sales across different stores or channels.
- Campaign_Dim: To link sales with marketing campaigns for effectiveness evaluation.
- Facts:
- quantity_sold: Supports volume analysis.
- sales_amount: For revenue analysis.
- discount_amount: To analyze the impact of discounts.
- cost_amount and profit_amount: For profitability analysis.
- Slowly Changing Dimensions:
- Product_Dim might be treated as a Type 2 SCD to track changes in product categories or prices over time.
- Customer_Dim could be a Type 2 SCD to track changes in customer attributes for accurate historical analysis.
- Additional Considerations:
- Inventory_Snapshot_Fact: A periodic snapshot fact table to track daily inventory levels. This supports the requirement to monitor product inventory levels.
- The Sales_Fact table at the order line level allows for easy calculation of AOV (by aggregating to the order level).
- CLV can be calculated by aggregating customer purchases over time.
- The Campaign_Dim allows for linking sales to specific marketing campaigns, supporting campaign effectiveness analysis.
This model supports all the required analyses:
- Daily sales totals by category can be calculated by aggregating Sales_Fact and joining with Product_Dim.
- Customer purchase history and segmentation can be analyzed using Sales_Fact and Customer_Dim.
- AOV and CLV can be calculated from Sales_Fact.
- Inventory levels are tracked in Inventory_Snapshot_Fact.
- Marketing campaign effectiveness can be evaluated by analyzing Sales_Fact in conjunction with Campaign_Dim.
The model balances the need for detailed data (supporting complex analyses) with performance considerations (using aggregate tables for common queries). It's also flexible enough to accommodate future requirements, such as adding new product attributes or campaign types.