Data Warehouse
Data Warehouse
A repository of data cleaned for analysis. Snowflake, BigQuery, Redshift.
Data Warehouse
A repository of data cleaned for analysis. Snowflake, BigQuery, Redshift.
A data warehouse is a centralized repository that integrates, cleanses, and stores data collected from multiple sources for analytical purposes. Unlike OLTP (Online Transaction Processing) systems, it is optimized for OLAP (Online Analytical Processing), so it can run complex analytical queries quickly.
The core design pattern of a data warehouse is the Star Schema. A Fact Table sits in the center, and Dimension Tables are connected around it in a star shape. The fact table stores measures (sales amount, quantity, etc.), while the dimension tables store analytical perspectives (date, product, region, etc.).
Cloud-based data warehouses such as Snowflake, BigQuery, and Redshift separate compute from storage, enabling elastic scaling. You can scale up compute resources only when needed and scale them back down once the analysis is finished, which makes them cost-efficient. In particular, Snowflake's virtual warehouse concept lets multiple teams run queries independently while accessing the same data.
Recently, the Data Lakehouse architecture has emerged, combining the low-cost storage of a data lake with the performance of a data warehouse. Table formats such as Delta Lake and Apache Iceberg make this possible.
-- Star Schema μ€κ³ μμ : νλ§€ λΆμ λ°μ΄ν° μ¨μ΄νμ°μ€
-- 1. μ°¨μ ν
μ΄λΈ: λ μ§ μ°¨μ
CREATE TABLE dim_date (
date_key INT PRIMARY KEY,
full_date DATE NOT NULL,
year INT,
quarter INT,
month INT,
month_name VARCHAR(20),
week INT,
day_of_week INT,
day_name VARCHAR(20),
is_weekend BOOLEAN,
is_holiday BOOLEAN
);
-- 2. μ°¨μ ν
μ΄λΈ: μ ν μ°¨μ
CREATE TABLE dim_product (
product_key INT PRIMARY KEY,
product_id VARCHAR(50),
product_name VARCHAR(200),
category VARCHAR(100),
subcategory VARCHAR(100),
brand VARCHAR(100),
unit_price DECIMAL(10, 2)
);
-- 3. μ°¨μ ν
μ΄λΈ: κ³ κ° μ°¨μ
CREATE TABLE dim_customer (
customer_key INT PRIMARY KEY,
customer_id VARCHAR(50),
customer_name VARCHAR(200),
segment VARCHAR(50), -- Enterprise, SMB, Consumer
region VARCHAR(100),
country VARCHAR(100),
city VARCHAR(100)
);
-- 4. μ¬μ€ ν
μ΄λΈ: νλ§€ μ¬μ€ (μ€μ)
CREATE TABLE fact_sales (
sale_key BIGINT PRIMARY KEY,
date_key INT REFERENCES dim_date(date_key),
product_key INT REFERENCES dim_product(product_key),
customer_key INT REFERENCES dim_customer(customer_key),
-- μΈ‘μ κ° (Measures)
quantity INT,
unit_price DECIMAL(10, 2),
discount_amount DECIMAL(10, 2),
total_amount DECIMAL(12, 2),
profit DECIMAL(10, 2)
);
-- λΆμ 쿼리 μμ : μλ³ μΉ΄ν
κ³ λ¦¬λ³ λ§€μΆ
SELECT
d.year,
d.month_name,
p.category,
SUM(f.total_amount) AS total_sales,
SUM(f.profit) AS total_profit,
COUNT(DISTINCT f.customer_key) AS unique_customers
FROM fact_sales f
JOIN dim_date d ON f.date_key = d.date_key
JOIN dim_product p ON f.product_key = p.product_key
WHERE d.year = 2024
GROUP BY d.year, d.month, d.month_name, p.category
ORDER BY d.month, total_sales DESC;
Data Engineer: "We're currently running report queries directly on the OLTP DB, and it's putting load on the production DB. I propose building a data warehouse."
Analyst: "So does that mean we won't be able to see real-time data?"
Senior: "Syncing in batches every hour is enough for most analyses. For dashboards that truly need real-time data, it's better to build a separate streaming pipeline."
Interviewer: "Please explain the difference between a star schema and a snowflake schema."
Candidate: "In a star schema, dimension tables are denormalized, so joins are simple. A snowflake schema normalizes the dimensions, which saves storage space but makes joins more complex. Modern cloud DWs have plenty of compute power, so they prefer the star schema. Query performance and ease of understanding matter more."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Reviewer: "This fact table uses a natural key instead of a surrogate key. Why did you do that?"
Author: "Oh, I'll change it to a surrogate key. It could cause problems when handling SCD (Slowly Changing Dimension)."
Cause: An analyst accidentally ran a full-table-scan query in an infinite loop, with no cost limit configured
Impact: A 5TB table was scanned 1,000 times over the weekend, resulting in an unexpected $30,000 charge
Resolution: Forcibly terminated the query and asked Google Support to review the charges
Lesson: Set query byte limits, use slot reservations, and configure cost alerts
Cause: The ETL pipeline failed to detect a schema change in the source system
Impact: Sales report figures were wrong for two weeks, leading to poor decisions by executives
Resolution: Verified consistency between source data and DW data, then reloaded
Lesson: Automate data quality validation, set up schema change detection alerts, and establish a data reconciliation process
Q1. In a Star Schema, what is stored in the Fact Table?
Q2. What is the key advantage of cloud data warehouses (Snowflake, BigQuery)?
Q3. What is a characteristic of SCD Type 2 (Slowly Changing Dimension Type 2)?
If this page has any errors or you would like to add something, please let us know!