Production-Grade ML System

Intelligent Dynamic
Pricing
Engine

A production-style pricing system combining ML-based optimization, deterministic batch execution, and human-in-the-loop safety controls — auditable, reproducible, and built to scale.

View Source Explore Architecture →
0% Audit Coverage
0 layers Safety Controls
0 strategies Pricing Modes
0ms API Read-only Latency

Production-Grade
Architecture

Built on strict separation of concerns — feature generation, pricing execution, and the UI are fully decoupled layers that communicate via a read-only API contract.

⚙️
Feature Job
backend/feature_job.py
Daily batch that computes pricing signals — inventory levels, demand trends, elasticity — and writes a snapshot per SKU. Guarantees reproducibility and prevents data leakage into future runs.
🧮
Pricing Job
backend/pricing_job.py
Consumes feature snapshots, enforces manual overrides, selects strategy (ML / rule-based / freeze), and writes every decision to the audit trail with full explainability metadata.
🔬
Pricing Optimizer
backend/pricing_runner.py
Runs the constrained optimization pass — calls the ML model, applies margin and inventory constraints, then persists final prices alongside reasoning artifacts for the UI.
🛡️
FastAPI Layer
backend/api/
Read-only data contract. Exposes system health, alerts, global pricing status, and per-SKU history. The UI never touches the DB directly — all reads flow through this verified boundary.
🖥️
Operations UI
frontend/ (Flask)
Material-inspired internal dashboard. Shows health status, alert tables, SKU explorer with price history charts, and admin controls to freeze or force rule-based pricing.
📊
Monitoring & Alerts
monitoring_spec.md
Drift detection triggers retraining events that require human approval before any model version is promoted — preventing silent regressions from reaching production pricing.

System Metrics

Illustrative simulation outputs from the offline evaluation pipeline.

Price Optimization Over Time
ML vs Rule-Based vs Static — SKU sample
Strategy Distribution
Pricing mode selection across SKUs
Demand Forecast Accuracy
Predicted vs Actual Units (30-day window)
Alert Volume by Type
Monitoring signal distribution

Built for the
Real World

01
Deterministic Execution
Pricing runs as a batch job on snapshotted inputs. Every run is replayable and produces identical output given the same state — no hidden nondeterminism.
02
Human-in-the-Loop Controls
Ops can issue PRICE_FREEZE or FORCE_RULE_BASED overrides at any time. Overrides expire automatically and are enforced at execution, not at API call time.
03
Full Auditability
Every pricing decision is stored with its feature snapshot, chosen strategy, and explainability metadata. Nothing is silently overwritten — the audit trail is append-only.
04
Drift Detection
The monitoring layer continuously tracks model performance degradation. Retraining events require explicit human approval before any new model version affects live prices.
05
Strict Separation of Layers
Feature generation ≠ pricing. Pricing ≠ UI. The UI records intent and reads state — it never directly executes pricing logic or writes to the decisions table.
06
Scheduler Agnostic
Daily jobs can run on Windows Task Scheduler, cron, Airflow, or Kubernetes Jobs. The system makes no assumptions about the orchestration layer.

The Pricing Pipeline

Five deterministic stages run every day. Each stage has a single responsibility and a clean contract with the next.

02:00 UTC
Feature Job
Compute inventory, demand signals, and elasticity. Write daily snapshot per SKU.
02:10 UTC
Pricing Job
Read snapshots, check overrides, select strategy per SKU.
02:12 UTC
Optimizer
Run constrained ML optimization. Apply margin & inventory constraints.
02:15 UTC
Persist & Explain
Write final prices and explainability artifacts to audit trail.
Continuous
Monitoring
Detect drift, fire alerts, surface issues in the ops dashboard.
for sku_id, features in snapshots.iterrows():
  override = overrides.get(sku_id)
  if override == "PRICE_FREEZE":
    strategy = "static"
    price = features["last_price"]
  elif override == "FORCE_RULE_BASED":
    strategy, price = rule_based_price(features)
  else:
    strategy, price = ml_optimizer.run(features) # constrained

  decisions.write(sku_id, price, strategy,
    explain=True, snapshot_id=features["id"]) # full audit trail

Tech Stack

🐍
Python
Core logic
FastAPI
Read-only API
🌶️
Flask
Ops UI
🗄️
SQLite / DB
Audit trail
🤖
scikit-learn
ML models
📦
pandas
Feature jobs
// open source

Explore the Full Codebase

Architecture docs, pricing specs, drift logic, and a complete monitoring schema — all designed to be readable and reasoned about.

github.com/samadrehan02/Dynamic-Pricing-System