Customer ML Feature Engineering Pipeline
Design and implement a production-grade ML feature engineering pipeline that transforms trusted historical customer transactions into point-in-time accurate, reusable features with strict data leakage prevention, rolling time-window aggregations, and seamless Snowflake feature store publishing.
Project Brief
Understand data engineering for machine learning and point-in-time feature computation.
Business Scenario
The Data Science team at an omnichannel retail enterprise is developing customer lifetime value (LTV) and churn prediction models. To train reliable models and power real-time inference, data scientists require dozens of behavioral features computed across historical customer interactions.
Currently, individual data scientists write ad-hoc SQL and pandas scripts on their local laptops, leading to duplicated feature code, subtle calculation discrepancies, and severe **data leakage**βwhere future transaction data accidentally leaks into historical training observations.
Development Objective
Design and develop a production data engineering feature pipeline in Databricks and PySpark. The pipeline must ingest trusted Silver customer and transaction tables, calculate standardized behavioral feature sets (RFM metrics, category diversity, rolling 30/90/180-day spend), enforce point-in-time correctness without future leakage, generate reproducible training snapshots, support daily incremental feature refreshes, and publish curated feature tables to Snowflake.
Expected Outcome
This is a **Data Engineering for ML** challenge, not model tuning. Your responsibility is to engineer scalable, deterministic, and leakage-free feature pipelines that serve both offline model training and online feature lookup.
Source System
Inspect the input Silver entity datasets: customer master profiles and line-item sales transactions.
Input Datasets Overview
The feature pipeline consumes from trusted Silver customer master records and validated line-item transaction tables.
Source Schema Entities
Key Feature Categories to Derive
When computing features for observation date `T` (e.g. `2026-06-01`), **NO transaction with timestamp > `T`** may enter the calculation window. Even a 1-second future timestamp leak invalidates ML model safety.
Expected Architecture
Point-in-time feature generation architecture: observation spine, windowed joins, validation, and serving.
Feature Pipeline Flow
The architecture uses point-in-time observation spines (as-of date grids) to compute historical feature snapshots without data leakage, persisting versioned feature sets in Delta Lake and Snowflake.
Architecture Expectations
Separate your feature engineering pipeline into two modes: **Historical Backfill** (generating multi-timestamp training spines) and **Daily Production Refresh** (computing latest feature vectors for live model inference).
Development Requirements
Implement feature calculation modules, point-in-time joins, leakage prevention, and serving tables.
Developer Responsibilities
The implementation must address the following 15 engineering requirements across feature engineering, leakage testing, data validation, and deployment.
Source Preparation & Customer Cohorts
Prepare trusted customer master and transaction datasets.
Observation Spine Generation
Create point-in-time observation grids for historical feature calculation.
Point-in-Time Join & Leakage Prevention
Prevent future transaction data from leaking into past features.
Recency (R) Feature Calculations
Derive customer purchase recency and tenure metrics.
Frequency (F) Rolling Window Metrics
Derive transaction volume across multiple time horizons.
Monetary (M) Rolling Spend Metrics
Derive financial value and order size statistics.
Product Category Diversity Metrics
Capture customer category preferences and shopping breadth.
Velocity & Spending Acceleration Indicators
Derive momentum features capturing changes in customer behavior.
Deterministic Null Imputation & Encoding
Ensure feature vectors are directly consumable by ML models.
Incremental Daily Feature Refresh
Compute current feature vectors efficiently for daily production runs.
Delta Feature Store & MLflow Integration
Persist feature tables with versioning and lineage tracking.
Snowflake ML Serving Table Publishing
Publish curated feature tables to Snowflake.
Data Quality & Distribution Assertions
Validate feature statistical distributions.
Feature Lineage & Data Dictionary
Publish complete feature definitions and formulas.
Configuration Externalization
Externalize window sizes and serving paths across environments.
Structuring feature engineering logic into modular transformer classes allows data scientists to register new features without rewriting core windowing and join logic.
Testing Requirements
Demonstrate point-in-time correctness, data leakage prevention, null imputation, and incremental refreshes.
Required Test Scenarios
Validate the feature pipeline against the following 11 test scenarios:
Data leakage is the most dangerous bug in ML engineering because models trained on leaked data show 99% accuracy in testing but fail catastrophically in production. The point-in-time leakage test is non-negotiable.
Acceptance Criteria
Verify that the ML feature pipeline fulfills all production Definition of Done criteria.
Definition of Done
The implementation is complete when all 10 criteria are satisfied:
Sign-off requires execution test logs explicitly demonstrating that injecting future events does not alter historical feature outputs.
Developer Deliverables
Submit all feature engineering code, leakage tests, schema catalogs, and validation evidence.
Required Deliverables
The submission must include the following 10 artifacts:
Ensure your test suite can be run on synthetic test data to demonstrate leakage prevention without external DB dependencies.
Engineering Constraints
Adhere to strict operational and architectural boundaries for ML data engineering.
Required Boundaries
The solution must strictly comply with the following 10 constraints:
Any code that uses `current_date()` inside historical training backfill queries will result in immediate rejection due to data leakage violation.
Suggested Project Structure
Recommended repository layout for production ML feature engineering.
Recommended Project Layout
Structure your repository to separate spine generation, feature transformers, point-in-time joins, tests, and documentation:
DEV-007-ml-feature-pipeline/
β
βββ README.md
β
βββ config/
β βββ dev.yaml
β βββ prod.yaml
β
βββ src/
β βββ spine/
β β βββ observation_spine.py # (customer_id, as_of_date) grid builder
β βββ transformers/
β β βββ recency_features.py # Days since last purchase & tenure
β β βββ frequency_features.py # Rolling 30d/90d/180d order counts
β β βββ monetary_features.py # Rolling spend, AOV & discounts
β β βββ diversity_features.py # Distinct categories & preferred brand
β β βββ velocity_features.py # 30d vs 90d acceleration metrics
β βββ pipeline/
β β βββ point_in_time_join.py # Leakage-free range join engine
β β βββ null_imputer.py # Deterministic default values
β β βββ backfill_job.py # Multi-timestamp historical generator
β β βββ daily_refresh_job.py # Incremental as-of-today refresh
β βββ sinks/
β βββ delta_feature_store.py # Delta Lake feature store writer
β βββ snowflake_publisher.py # Snowflake staging & merge loader
β
βββ tests/
β βββ test_leakage_prevention.py # Future-timestamp injection test
β βββ test_window_monotonicity.py
β βββ test_recency_calculation.py
β βββ test_null_imputation.py
β βββ test_daily_incremental.py
β
βββ docs/
βββ feature_dictionary.md # Full formulas & schema metadata
βββ point_in_time_design.md # Mathematical proof of leakage preventionModule Responsibilities
Decoupling individual feature transformers from the point-in-time join engine ensures new business features can be added and unit-tested in isolation without re-engineering the complex time-window join machinery.
Submission Checklist
Final engineering quality checklist before submitting DEV-007.
Final Review Checklist
Verify every checklist item before submitting your feature engineering pipeline:
Submit DEV-007 only after the point-in-time joins, RFM feature transformers, leakage tests, Snowflake sync, incremental refresh, and data dictionary have been thoroughly validated.