How amitzore71/airflow-feature-engineering works
Purpose and Entry Points
This is an Airflow-orchestrated feature-engineering platform for recommendation systems. It transforms raw/synthetic events into contract-governed offline features, validates them, selectively publishes serving features to Redis, monitors their quality, and signals MLflow retraining. Operational entry points are the DAGs in airflow/dags/, especially airflow/dags/dag_feature_build.py; local stack startup is defined by docker-compose.yml and Dockerfile.airflow.
Contract and Configuration Boundary
The feature contract is the central compatibility boundary between generation, validation, publishing, and monitoring. It specifies feature schema, constraints, freshness, leakage rules, and publish policy in contracts/recommendation_features.yaml. Contract parsing and typed representation live in src/contracts/loader.py and src/contracts/models.py; shared runtime settings are centralized in src/config.py.
Build and Offline Feature Store
The build stage generates/consumes raw events and materializes offline feature snapshots. airflow/dags/dag_feature_build.py orchestrates the workflow, delegating transformation/materialization to src/build/feature_builder.py and shared DuckDB transformation SQL in sql/feature_build.sql. Raw inputs, offline Parquet outputs, and local online-state files are separated under data/raw/, data/offline/, and data/online/. DuckDB is the offline compute/store runtime; Parquet is the durable interchange format.
Validation and Promotion Gate
Validation is an explicit gate before online promotion. airflow/dags/dag_feature_validate.py runs contract quality and leakage checks from src/validation/checks.py, including SQL leakage validation in sql/validation_leakage.sql. Validation results/checkpoints are persisted under artifacts/validation/; a failed contract blocks downstream publishing rather than allowing an unsafe partial promotion.
Online Publish and Serving Parity
The publish path moves approved offline features into Redis with canary and rollback decisioning. airflow/dags/dag_feature_publish.py coordinates src/publish/decision.py and src/publish/online_store.py; src/parity/checker.py verifies offline/online feature equivalence. Publish artifacts reside in artifacts/publish/. Redis is the online retrieval service boundary; recommendation serving is downstream and not implemented in this repository.
Monitoring and Retraining Control Loop
Post-publish monitoring evaluates freshness and distribution drift. airflow/dags/dag_feature_monitor.py invokes src/monitor/freshness.py and src/drift/metrics.py, writing signals to artifacts/monitoring/. airflow/dags/dag_retrain_trigger.py uses src/triggers/retrain.py to turn sustained threshold breaches into MLflow retraining signals, with trigger state in artifacts/triggers/. MLflow is an external training-system integration, not the feature pipeline’s execution engine.
Historical Recovery and Orchestration
Airflow owns scheduling, dependencies, retries, and stage isolation across build, validation, publish, monitoring, retraining, and historical rebuilds. airflow/dags/dag_backfill_features.py drives deterministic reconstruction using src/backfill/deterministic.py, producing historical artifacts under artifacts/backfill/. src/tasks.py is the likely shared task-level integration layer across DAGs. Metadata artifacts and contracts decouple stages so a stage can be audited or rerun without changing the core feature specification.
Main entry points: feature_builder.py Feature builder · checks.py Quality & leakage checks · loader.py Contract loader & models · freshness.py Freshness & drift analysis
Components 24
Airflow orchestration
- Airflow DAG runtime · Schedules, isolates, and retries pipeline stages.
- Shared task layer
src/tasks.py
Contract boundary
- Recommendation feature contract · Defines schema, constraints, freshness, leakage, and publish policy.
contracts/recommendation_features.yaml - Contract loader & models
src/contracts/loader.py - Runtime settings
src/config.py
Offline build
- Feature build DAG
airflow/dags/dag_feature_build.py - Feature builder
src/build/feature_builder.py - Feature transformation SQL
sql/feature_build.sql - Raw events
- Offline feature snapshots · Durable offline interchange snapshots.
Validation & serving
- Feature validation DAG
airflow/dags/dag_feature_validate.py - Quality & leakage checks
src/validation/checks.py - Leakage validation SQL
sql/validation_leakage.sql - Validation checkpoints · Failed results block online promotion.
- Feature publish DAG
airflow/dags/dag_feature_publish.py - Canary & rollback decisions
src/publish/decision.py - Redis publisher
src/publish/online_store.py - Offline/online parity checker
src/parity/checker.py - Redis serving features · Serving consumers are outside this repository.
Monitoring & recovery
- Feature monitor DAG
airflow/dags/dag_feature_monitor.py - Freshness & drift analysis
src/monitor/freshness.py - MLflow retrain trigger · Signals retraining after sustained breaches.
src/triggers/retrain.py - Historical backfill DAG
airflow/dags/dag_backfill_features.py - Deterministic reconstruction
src/backfill/deterministic.py
Connections 24
- Airflow DAG runtime → Shared task layer: runs shared tasks
- Feature build DAG → Feature builder: orchestrates
- Feature builder → Raw events: reads
- Feature builder → Feature transformation SQL: executes
- Feature builder → Offline feature snapshots: materializes Parquet
- Recommendation feature contract → Contract loader & models: parsed as typed policy
- Contract loader & models → Feature builder: governs schema
- Feature validation DAG → Quality & leakage checks: orchestrates
- Offline feature snapshots → Quality & leakage checks: validates
- Contract loader & models → Quality & leakage checks: supplies rules
- Leakage validation SQL → Quality & leakage checks: used for leakage checks
- Quality & leakage checks → Validation checkpoints: writes results
- Validation checkpoints → Feature publish DAG: approval gate
- Feature publish DAG → Canary & rollback decisions: orchestrates
- Offline feature snapshots → Offline/online parity checker: comparison source
- Canary & rollback decisions → Redis publisher: approved canary/promotion
- Redis publisher → Redis serving features: publishes features
- Redis serving features → Offline/online parity checker: comparison target
- Feature monitor DAG → Freshness & drift analysis: orchestrates
- Redis serving features → Freshness & drift analysis: observes serving state
- Freshness & drift analysis → MLflow retrain trigger: threshold breaches
- Historical backfill DAG → Deterministic reconstruction: orchestrates
- Deterministic reconstruction → Offline feature snapshots: rebuilds history
- Runtime settings → Airflow DAG runtime: configures runtime