By: Fabrizio Pérez Peralta
Published on: Dev.to / Medium / Hashnode
Tags: #businessintelligence #duckdb #python #dataengineering #analytics #streamlit
⚡ Quick Project Links
- 📦 Public GitHub Repository: https://github.com/FabrizioPerezPeralta/olap-intelligence-hub.git
- 🚀 Live Interactive Web Application (Streamlit Cloud): https://olap-intelligence-app.streamlit.app
1. Introduction: The Analytical Dilemma in Modern Business Intelligence
In software and data engineering, there is a fundamental architectural divide between two computing paradigms:
- OLTP (Online Transaction Processing): Optimized for high-throughput, low-latency row-by-row operations (e.g., executing an e-commerce checkout, updating account balances, or inserting audit logs).
- OLAP (Online Analytical Processing): Engineered to execute complex, multi-dimensional queries across millions of historical records to compute aggregations, trends, cohort margins, and statistical distributions.
Running analytical queries directly on transactional production databases (like unindexed PostgreSQL or MySQL) frequently triggers table locks, exhausts CPU cores, and degrades user experience. For years, the traditional solution was to provision heavyweight cloud data warehouses, entailing steep subscription costs, infrastructure overhead, and deep cloud-provider lock-in (most notably AWS Redshift or BigQuery).
In this article, I demonstrate the end-to-end architecture and implementation of OLAP Intelligence Hub: a modern, serverless, high-performance analytical platform built with DuckDB, MotherDuck (Public Cloud SaaS), and Streamlit, fully automated through GitHub Actions CI/CD—without touching a single AWS service.
2. System Architecture
The architecture unifies local columnar in-memory vector execution with seamless synchronization to the public cloud via MotherDuck, wrapped in an interactive analytical dashboard:
Architectural Layer Breakdown:
- Data Storage Layer: Analytical data stored in Apache Parquet format compressed with ZSTD. This eliminates row-based serialization overhead and enables rapid column-pruning during scans.
-
Hybrid Serverless OLAP Engine:
- DuckDB (Local Engine): Executes vectorized queries in-process utilizing modern CPU SIMD registers, achieving sub-15ms response times over 150K+ records.
- MotherDuck Cloud (Public SaaS): Serverless cloud-hosted DuckDB that handles persistent data storage, elasticity, and cloud collaboration without cluster management.
- Presentation & Analytics Layer (Streamlit): An executive web dashboard offering interactive multi-dimensional exploration, time-series roll-ups, cross-tab pivot heatmaps, and an ad-hoc SQL console.
- DataOps & Automation Pipeline (CI/CD): GitHub Actions pipeline executing automated linting, Pytest test suites, and database schema synchronization, feeding directly into Streamlit Community Cloud for zero-downtime deployment.
3. Why DuckDB and MotherDuck?
DuckDB: The Vectorized Engine for Analytics
Often dubbed the "SQLite of Analytics", DuckDB transforms data processing through three architectural pillars:
-
Columnar Data Storage: When aggregating revenue (
SUM(gross_sales)), DuckDB only reads thegross_salesvector from disk/memory, bypassing unnecessary columns and slashing I/O latency. - Vectorized Query Execution Engine: Processes batches of data points (vectors) simultaneously via modern CPU SIMD instructions, evaluating complex window functions and mathematical aggregations in milliseconds.
-
Native Parquet Integration: Directly queries partitioned
.parquetfiles via zero-copy data pointers without requiring costly staging or ETL ingestion tables.
MotherDuck: Serverless Cloud DuckDB
MotherDuck extends DuckDB to the cloud as a true serverless platform:
- Provides persistent cloud databases accessible via standard token connections (
md:ecommerce_olap). - Eliminates the need to spin up, configure, and monitor cloud virtual machines or managed clusters.
- Completely cloud-agnostic, running serverlessly across modern cloud regions (Azure and GCP) while strictly avoiding AWS lock-in.
4. Dimensional Modeling & Synthetic E-Commerce Dataset
To evaluate the system under realistic analytical conditions, we synthesized an e-commerce transactional dataset containing 150,000 records structured around a classic analytical Star Schema:
-
Fact Metrics:
gross_sales,net_profit,unit_price,quantity,discount_rate,shipping_cost. -
Analytical Dimensions:
-
Time Dimension:
order_date,order_year,order_quarter,order_month,year_month,day_of_week. -
Geographic Dimension:
region(North America, Europe, Latin America, Asia-Pacific),country. -
Commercial Dimension:
category(Electronics, Furniture, Clothing, Home & Kitchen, Sports),sub_category,customer_segment. -
Logistics & Payment:
payment_method,shipping_mode,order_status.
-
Time Dimension:
The entire dataset was generated and compressed into a compact sample_ecommerce.parquet file, ready for instantaneous vectorized scanning.
5. Hands-On: Implementing the 4 Core OLAP Operations
Within the Streamlit application, we implemented the four fundamental operations of multi-dimensional analytical processing:
1. Slice & Dice (Dynamic Filtering)
Allows business analysts to slice across dimensions and isolate specific segments simultaneously (e.g., analyzing transactions in Europe within the Electronics category, paid via Credit Card within a custom date range).
2. Roll-Up & Drill-Down with Window Functions
Enables hierarchical navigation across time granularities (Yearly -> Quarterly -> Monthly -> Day of Week). Using DuckDB's advanced SQL window functions, we calculate running total sales and Month-over-Month (MoM) growth rates on the fly:
WITH aggregated AS (
SELECT
year_month AS time_period,
SUM(gross_sales) AS period_sales,
SUM(net_profit) AS period_profit,
COUNT(order_id) AS order_volume
FROM sales_fact
WHERE 1=1
GROUP BY 1
)
SELECT
time_period,
period_sales,
period_profit,
order_volume,
-- OLAP Window Function: Running total sales over time
SUM(period_sales) OVER (ORDER BY time_period) AS running_total_sales,
-- OLAP Window Function: Month-over-Month growth percentage
ROUND(
(period_sales - LAG(period_sales, 1) OVER (ORDER BY time_period))
/ NULLIF(LAG(period_sales, 1) OVER (ORDER BY time_period), 0) * 100, 2
) AS mom_growth_pct
FROM aggregated
ORDER BY time_period;
3. PIVOT Matrices & Heatmaps
Taking advantage of DuckDB's native PIVOT syntax, the dashboard pivots multi-dimensional intersections into cross-tabulated matrices (such as Geographic Region vs. Customer Segment) rendered with interactive heatmaps:
PIVOT (
SELECT region, customer_segment, gross_sales
FROM sales_fact
WHERE 1=1
)
ON customer_segment
USING ROUND(SUM(gross_sales), 2)
GROUP BY region;
4. Interactive Ad-Hoc SQL Console
For advanced business analysts, the platform exposes an interactive SQL query editor with real-time execution timing (in milliseconds) and support for analytical grouping operations like GROUP BY CUBE and ROLLUP.
6. DataOps: Automated Testing and CI/CD Pipeline
To ensure rigorous software engineering standards and prevent analytical regressions:
-
GitHub Actions Workflow (
.github/workflows/ci.yml):- Configured with Python 3.11/3.12 runners.
- Performs automated linting and code quality checks using Ruff.
- Seeds the analytical dataset and executes automatic cloud synchronization with MotherDuck via GitHub Repository Secrets (
${{ secrets.MOTHERDUCK_TOKEN }}). - Runs an end-to-end Pytest validation suite covering schema validation, metric calculations, and window function integrity.
-
Streamlit Community Cloud Deployment:
- Linked directly to the public GitHub repository.
- Auto-deploys upon every push to the
mainbranch, ensuring that tested code and data schema changes go live immediately without downtime: 👉 https://olap-intelligence-app.streamlit.app
7. Key Takeaways & Lessons Learned
- Sub-15ms Latency at Zero Infrastructure Cost: Pairing DuckDB with MotherDuck demonstrates that sub-second analytical processing on hundreds of thousands of records no longer requires complex, expensive cloud warehouses.
- Format Matters: Storing data in compressed Apache Parquet files enables columnar vectorization that outperforms legacy row-based queries by orders of magnitude.
- DataOps is Essential: Integrating unit testing for analytical SQL queries and automated CI/CD into Business Intelligence workflows guarantees reproducible, production-grade dashboards.
🔗 Project Resources & Live Demo
- 💻 Source Code & Documentation: GitHub Repository
- 🚀 Live Interactive Dashboard: Streamlit Application

Top comments (0)