Design a Snowflake Data Model for an E-commerce Platform

Instruction: Considering the various aspects of an e-commerce business, such as inventory, orders, customers, and shipping, design a scalable and efficient data model using Snowflake. Discuss the schema design, data types, and any considerations for optimizing query performance.

Context: This question evaluates the candidate's ability to design complex data models tailored to specific business needs while leveraging Snowflake's capabilities. It tests their understanding of Snowflake's data warehousing concepts, data modeling best practices, and their ability to optimize data structures for performance and scalability.

Updated

Official answer

Define each fact table's grain before choosing columns. For sales, use one row per order line, identified by order_id and line_id, with customer/product/date keys, quantity, accepted unit price, discounts and net amount. An order may contain several products; one order is not one product or inventory record.

Use customer, product and date dimensions. Decide which attributes need historical versions so a report can reproduce the customer segment or product category used at the time. Store accepted prices on the sales fact rather than recomputing historical revenue from the current catalog.

Use separate facts for inventory snapshots at product-location-snapshot-time grain and shipment lines at shipment-order-line grain. This handles changing stock and partial deliveries. Aggregate each fact to a compatible grain before joining: joining two order lines directly to three shipment records can produce six rows and inflate revenue.

Choose fixed-point NUMBER with an appropriate scale for money, integer quantities where applicable, and explicit DATE/TIMESTAMP types and timezone conventions. Store currency and define conversion rules. Reserve VARIANT for useful raw or variable attributes rather than making every governed field untyped.

Standard Snowflake tables do not enforce primary/foreign/unique keys. Validate uniqueness and relationships in ingestion and reconciliation; do not assume declaring a key prevents duplicates. Use query profiles and pruning evidence before adding clustering or other paid optimization. Test refunds, split shipments, late facts and historical dimension changes.

Table design, constraint behavior, micro-partitions

Related Questions