Skip to content

srikeerthis/Real-Time-Bidding-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Distributed Real-Time Bidding (RTB) Engine

Contextual Bandit Marketplace Optimizer

A high-performance, containerized microservice simulating a marketplace auction system. This project implements a LinUCB-based Contextual Bandit agent to optimize real-time bidding strategies, balancing exploration and exploitation based on dynamic user context (e.g., Time of Day, User Segment).

🏗️ System Architecture

The engine is architected as a decoupled microservice to handle high-concurrency marketplace constraints:

  1. Inference Path (POST /predict): Receives user context and returns an optimal bidding strategy in sub-20ms.
  2. Feedback Path (POST /update): Receives reward signals (conversions/clicks) from the marketplace.
  3. Asynchronous Learning: Model updates are handled via FastAPI Background Tasks to ensure that the learning process never blocks the inference path.
  4. Containerization: The entire stack is Dockerized for reproducible, horizontal scaling in distributed environments.

🧠 The Math Behind the Bidding

The agent models the expected reward $r$ for an arm $a$ as a linear function of the context $x$: $$r_{t,a} = x_{t,a}^\top \theta_a^*$$

To handle the Exploration-Exploitation trade-off, the engine calculates the Upper Confidence Bound (UCB) for each strategy: $$p_{t,a} = \hat{\theta}a^\top x{t,a} + \alpha \sqrt{x_{t,a}^\top A_a^{-1} x_{t,a}}$$

  • $\hat{\theta}a^\top x{t,a}$: The predicted reward based on current weights (Exploitation).
  • $\alpha \sqrt{\dots}$: The uncertainty bonus (Exploration). As the covariance matrix $A$ accumulates data, the uncertainty shrinks, and the agent converges on the optimal bidding strategy.

🛠️ Tech Stack

  • Modeling: Python, NumPy (Linear Algebra)
  • API Framework: FastAPI, Uvicorn, Pydantic
  • DevOps: Docker
  • Simulation: Synthetic Marketplace Environment

🚀 Setup & Usage

Running with Docker (Recommended)

  1. Build the image:
    docker build -t bidding-engine .
  2. Run the container:
    docker run -p 8000:8000 bidding-engine

Running Locally

  1. Install dependencies:
    pip install -r requirements.txt
  2. Start the server:
    uvicorn app:app --reload
  3. Run the marketplace simulation:
    python test_api.py

📈 Performance Metrics

  • Conversion Rate: Achieved ~74% conversion in a 1,000-auction simulation against a stochastic environment.
  • Inference Latency: Average response time $< 20$ms.
  • Scalability: Stateless design allows for horizontal scaling via load balancers.

🗺️ Roadmap

  • Phase 1: Environment Simulation & RL Brain
  • Phase 2: High-Concurrency API (FastAPI)
  • Phase 3: Dockerization & Container Orchestration
  • Phase 4: Distributed State Management (Redis for shared weights)
  • Phase 5: Deep RL implementation (DQN Agent)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors