Building Robust Data Architecture
A data pipeline is a system that moves data from a source to a destination.
Modern SQL pipelines generally follow one of two patterns:
Data originates from multiple distinct sources:
Goal: Move this raw data into a central “Staging Area” with minimal changes.
This is where SQL shines. Raw data is converted into clean models.
Bad data breaks downstream dashboards. Pipelines must validate data automatically.
completed, pending).dbt tests, Great Expectations, or custom SQL assertions.You can write tests as SQL queries. A test passes if it returns zero rows.
How do we update our tables every day?
Best for immutable log data like page clicks or transactional history.
-- Find the latest record we already processed
DECLARE last_update TIMESTAMP;
SET last_update = (SELECT MAX(created_at) FROM analytics.clickstream);
-- Insert only new rows generated after that timestamp
INSERT INTO analytics.clickstream
SELECT click_id, user_id, page_url, created_at
FROM staging.raw_clicks
WHERE created_at > last_update;Best for mutable data like user profiles or order statuses that change over time.
-- MERGE updates existing records and inserts brand new ones
MERGE INTO analytics.customers target
USING staging.raw_customers source
ON target.customer_id = source.customer_id
WHEN MATCHED AND target.updated_at < source.updated_at THEN
UPDATE SET target.email = source.email, target.updated_at = source.updated_at
WHEN NOT MATCHED THEN
INSERT (customer_id, email, updated_at)
VALUES (source.customer_id, source.email, source.updated_at);Cleaned data is structured into schemas optimized for quick reporting.
This structure is commonly known as a Star Schema.
Pipelines must run automatically, reliably, and in the correct order.
Why build your pipeline around SQL?
Thank you for attending!
Please use the arrow keys on your keyboard to navigate the slides.