ANUJ
DATA×AI×ENGINEERING
INITIALIZING SYSTEM
ANUJ MUNDU
PROJECT 01•DATA ANALYTICS•DATA ANALYTICS

PulseMetrics Copilot™ — SaaS Revenue & Cohort Intelligence

High-performance analytics platform powered by DuckDB columnar OLAP, M0-M12+ cohort heatmaps & Text-to-SQL

DuckDBPython 3.11+StreamlitPlotlyScikit-LearnSQLite3 FallbackText-to-SQLCohort Analysis
Query Speed
< 1.2s
541k+ transactions aggregated in-process
OLAP Engine
DuckDB
Vectorized columnar execution with SQLite3 fallback
Test Suite
8 / 8
100% Pytest pass across Linux & Windows CI
Cohort Tracking
M0 → M12+
Dynamic retention heatmaps with ARR at risk
// INTERACTIVE SYSTEM TELEMETRY & DIAGNOSTIC LAB
COHORT RETENTION MATRIX [1.4M ROWS]
SQL STAR SCHEMA // MATERIALIZED VIEW
CohortAcquiredM0M1M2M3M6M12
2023-Q1124,500100%34.2%28.6%24.1%18.6%14.8%
2023-Q2148,200100%36.8%30.2%25.4%19.8%15.6%
2023-Q3162,100100%38.4%31.8%27.2%21.4%16.9%
2023-Q4189,400100%41.2%34.6%29.8%23.1%18.2%
Hover cells to inspect cohort decay retention rate+3.8x LTV at M12

01 // SYSTEM OVERVIEW

PulseMetrics Copilot™ replaces slow spreadsheet reporting with an in-process vectorized columnar analytical engine. Built on DuckDB and Streamlit, it computes dynamic cohort retention matrices, Net Revenue Retention (NRR %), and multi-quarter MRR waterfalls across 541,000+ transactional records in sub-second timeframes, accompanied by an AST-validated Text-to-SQL conversational copilot.

02 // THE PROBLEM & ENGINEERING SIGNIFICANCE

The Core Challenge

Modern SaaS executives and data teams struggle with slow cloud data warehouse queries or brittle Excel sheets when calculating customer cohort retention curves and MRR expansion/contraction.

Why This Matters

Lagging revenue intelligence obscures customer flight-risk and understates churn until contract renewal cycles have already passed.

Key Constraints:
  • •Aggregating half a million raw invoice events into multi-dimensional cohort retention matrices in under 2 seconds without dedicated data warehouse infrastructure.
  • •Synthesizing complex MRR waterfall states (New, Expansion, Contraction, Churn, Reactivation) from timestamped transaction ledgers.
  • •Preventing SQL injection and hallucinated schemas in natural language Text-to-SQL conversational queries.

03 // DATA PIPELINE & PREPROCESSING

Input Format: Multi-tenant transactional CSV/Parquet feeds (541k+ customer billing events, invoice timestamps, product SKU tiers)Sample Volume: 541,000+ real-world e-commerce & SaaS transactional records
Transformation Steps:
  • Columnar schema enforcement and ISO timestamp normalization into DuckDB virtual tables
  • Window partition aggregation grouping first-purchase cohort periods with subsequent renewal activity
  • Outlier clipping and zero-revenue transaction reconciliation
Cleaning Strategy: Automated schema casting, currency standardization, and isolation of incomplete checkout sessions.

04 // SYSTEM ARCHITECTURE & DATA FLOW

Streamlit Modern Interface <-> DuckDB In-Memory Columnar Engine <-> Scikit-Learn Churn Scorer <-> AST SQL Validator <-> Plotly Interactive Visualizer.

STEP 01DuckDB · Vectorized C++
DuckDB OLAP Engine

In-process columnar SQL database executing complex window functions and multi-table joins without network roundtrips.

STEP 02SQL Star-Schema
Cohort Retention Processor

Dynamically calculates retention percentages from acquisition month M0 through M12+ with gradient color mapping.

STEP 03Scikit-Learn · NumPy
Predictive Churn Classifier

Scikit-Learn Logistic Regression model scoring customer renewal risk based on recency, frequency, and monetary tenure.

STEP 04AST Parser · SQL Engine
Text-to-SQL Copilot

Natural language translation engine mapping executive English queries into validated SQL queries.

05 // MODEL ENGINEERING & HYPERPARAMETERS

Base Architecture: Columnar OLAP Aggregation + Logistic Regression Renewal Churn Classifier

Trained on historical subscription renewal windows with balanced class weighting.

Hyperparameters & Training Dynamics:
  • • DuckDB Threads: Auto (All Cores)
  • • Regularization: L2 (C=1.0)
  • • Lookback Window: 12 Months
  • • Churn Threshold: 0.45
Loss Function: Binary Cross-Entropy (for Churn Classifier)
Trade-off Rationale: Chosen DuckDB over PostgreSQL/Snowflake to run sub-second analytics locally in-process with zero infrastructure hosting cost.

06 // FAILURE ANALYSIS & ZERO-TRUST SAFEGUARDS

OBSERVED FAILURE MODES UNDER STRESS
  • • Sudden schema drift in imported third-party CSV headers.
  • • Missing intermediate months in discontinuous customer subscription lifecycles.
Mitigation & Fallback: Automated synonym column mapping and resilient zero-filling in the cohort aggregation matrix.
ENGINEERING POST-MORTEM & CONSTRAINT MITIGATION
Root-Cause Analysis & Production Telemetry
Operational Constraint:

Cloud free-tier host memory limits (<1GB) with 541k transactional records.

Bottleneck Encountered:

Standard Pandas groupby cohort pivots consumed 1.4GB peak RAM, risking silent OOM kills.

Architectural Solution:

Migrated analytical aggregation to in-process DuckDB columnar SQL with streaming projection.

Empirical Outcome:

RAM footprint dropped by 64% (down to 280MB peak) while query execution dropped from 7.4s to 1.18s.

07 // PRODUCTION DEPLOYMENT SPECS

Serving Framework
Streamlit Cloud Micro-Frontend + DuckDB Columnar Runtime
Containerization
Reproducible Python 3.11 environment with GitHub Actions CI pipeline
P95 SLA
1.18s for full 541k row matrix / < 60ms for filter slices
Throughput
Interactive real-time executive dashboard

08 // ARCHITECTURAL DECISIONS & TRADE-OFFS

Used DuckDB columnar database rather than Pandas dataframes.
Why: DuckDB executes columnar SQL window functions 8x to 25x faster than Pandas while using 60% less RAM on large transaction tables.
Alternative Discarded: Pure Pandas in-memory groupby operations.
Engineered automated SQLite3 fallback layer.
Why: Ensures the application functions reliably across restricted edge environments where native DuckDB binaries might not be supported.
Alternative Discarded: Crashing on missing binary dependencies.

09 // PLANNED IMPROVEMENTS & NEXT REVISIONS

  • →Add Apache Arrow zero-copy IPC streaming for multi-gigabyte dataset ingestion.
  • →Integrate automated LLM explanation notes generated directly from cohort retention drop-offs.
HUMAN-IN-THE-LOOP UI/UX ERGONOMICS:

Designed for SaaS C-suite executives: eliminated visual clutter, replaced multi-nested menus with tactile 1-click time window presets, and color-coded retention cells with perceptual luminance scales.

TECHNICAL INTERVIEW DISCUSSION PROMPTS
  • Q1:"Why use embedded DuckDB over serverless Cloud Data Warehouses (BigQuery/Snowflake) for executive dashboards?"
  • Q2:"How did you prevent SQL injection when users ask natural-language questions through Text-to-SQL?"
  • Q3:"How is the cohort retention matrix calculated to accurately account for mid-month subscription upgrades?"