Open Source Ad Serving Platform with ML-Powered CTR Prediction
Production-ready ad server for SMBs, startups, and developers
Features โข Quick Start โข Docs โข Benchmarks โข Roadmap
๐ If this project helps you, please give it a star! ๐
Most ad servers are either too simple (just serving static banners) or too complex (requiring Google-scale infrastructure).
OpenAdServer is the sweet spot โ a production-ready, self-hosted ad platform with machine learning powered CTR prediction, designed for teams who want full control without the complexity.
| Feature | OpenAdServer | Google Ad Manager | Revive Adserver | AdButler |
|---|---|---|---|---|
| Self-hosted | โ | โ | โ | โ |
| ML CTR Prediction | โ DeepFM/LR | โ | โ | โ |
| Real-time eCPM Bidding | โ | โ | โ | |
| Modern Tech Stack | โ Python/FastAPI | N/A | โ PHP | โ |
| One-click Deploy | โ Docker | โ | โ | |
| Free & Open Source | โ | โ | โ | โ |
| No Revenue Share | โ | โ ๐ฐ | โ | โ ๐ฐ |
- ๐ข SMBs building their own ad network
- ๐ฎ Gaming companies monetizing in-app traffic
- ๐ฑ App developers running house ads or direct deals
- ๐ E-commerce platforms with sponsored listings
- ๐ฌ Researchers studying computational advertising
- ๐ Students learning ad-tech systems
- High-Performance API โ <10ms P99 latency with FastAPI
- Multiple Ad Formats โ Banner, native, video, interstitial
- Smart Targeting โ Geo, device, OS, demographics, interests
- Frequency Capping โ Daily/hourly limits per user
- Budget Pacing โ Smooth delivery throughout the day
- CTR Prediction Models โ DeepFM, Logistic Regression, FM
- Real-time Inference โ <5ms prediction latency
- Automatic Feature Engineering โ Sparse/dense feature processing
- Model Hot-swap โ Update models without downtime
- eCPM Ranking โ Maximize revenue automatically
- Multiple Bid Types โ CPM, CPC, CPA, oCPM
- Real-time Bidding Ready โ OpenRTB compatible (roadmap)
- Event Tracking โ Impressions, clicks, conversions
- Real-time Dashboards โ Grafana integration
- Prometheus Metrics โ Full observability
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Ad Request Flow โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ ๐ฑ Client โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโ โ
โ โ FastAPI โโโโโถโ Retrieval โโโโโถโ Ranking โโโโโถโResponse โ โ
โ โ Router โ โ(Targeting)โ โ (eCPM) โ โ โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโ โ
โ โ โ โ โ
โ โผ โผ โผ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโ โ
โ โPostgreSQLโ โ Redis โ โ PyTorch โ โ
โ โ(Campaigns)โ โ (Cache) โ โ (Models) โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโโ โโโโโโโโโโโโ โ
โ โ
โ Pipeline: Retrieve โ Filter โ Predict โ Rank โ Return โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Clone the repository
git clone https://github.com/pysean/openadserver.git
cd openadserver
# Start all services (PostgreSQL, Redis, Ad Server)
docker compose up -d
# Initialize sample data
python scripts/init_test_data.py
# Verify it's running
curl http://localhost:8000/health
# {"status":"healthy","version":"1.0.0"}# Prerequisites: Python 3.11+, PostgreSQL 14+, Redis 6+
# Install dependencies
pip install -e ".[dev]"
# Start databases
docker compose up -d postgres redis
# Run the server
OPENADSERVER_ENV=dev python -m openadserver.ad_server.maincurl -X POST http://localhost:8000/api/v1/ad/request \
-H "Content-Type: application/json" \
-d '{
"slot_id": "banner_home",
"user_id": "user_12345",
"device": {"os": "ios", "os_version": "17.0"},
"geo": {"country": "US", "city": "new_york"},
"num_ads": 3
}'Response:
{
"request_id": "req_a1b2c3d4",
"ads": [
{
"ad_id": "ad_1001_5001",
"campaign_id": 1001,
"creative": {
"title": "Summer Sale - 50% Off!",
"description": "Limited time offer",
"image_url": "https://cdn.example.com/ads/summer-sale.jpg",
"landing_url": "https://shop.example.com/sale"
},
"tracking": {
"impression_url": "http://localhost:8000/api/v1/event/track?type=impression&req=req_a1b2c3d4&ad=1001",
"click_url": "http://localhost:8000/api/v1/event/track?type=click&req=req_a1b2c3d4&ad=1001"
},
"metadata": {
"ecpm": 35.50,
"pctr": 0.0355
}
}
],
"count": 1
}| Endpoint | Method | Description |
|---|---|---|
/api/v1/ad/request |
POST | Request ads for a placement |
/api/v1/event/track |
GET/POST | Track impression/click/conversion |
/api/v1/campaign |
CRUD | Manage campaigns |
/api/v1/creative |
CRUD | Manage creatives |
/api/v1/advertiser |
CRUD | Manage advertisers |
/health |
GET | Health check |
/metrics |
GET | Prometheus metrics |
# configs/production.yaml
server:
host: "0.0.0.0"
port: 8000
workers: 4
database:
host: "postgres"
port: 5432
name: "openadserver"
user: "adserver"
password: "${DB_PASSWORD}"
redis:
host: "redis"
port: 6379
db: 0
ad_serving:
enable_ml_prediction: true
model_path: "models/deepfm_ctr.pt"
default_pctr: 0.01
default_pcvr: 0.001# Prepare training data from your logs
python scripts/prepare_training_data.py \
--input logs/events/ \
--output data/training/
# Train DeepFM model
python -m openadserver.trainer.train_ctr \
--model deepfm \
--data data/training/train.parquet \
--epochs 10 \
--output models/
# Or train a simpler LR model (faster, good baseline)
python -m openadserver.trainer.train_ctr \
--model lr \
--data data/training/train.parquet \
--output models/
# Evaluate model
python -m openadserver.trainer.evaluate \
--model models/deepfm_ctr.pt \
--data data/training/test.parquet
# AUC: 0.72, LogLoss: 0.45Test Environment: MacBook Pro M1, 8GB RAM
| Scenario | QPS | P50 | P99 | Notes |
|---|---|---|---|---|
| Ad Request (no ML) | 2,500 | 2ms | 8ms | Baseline |
| Ad Request (with LR) | 1,800 | 3ms | 12ms | Recommended |
| Ad Request (with DeepFM) | 1,200 | 4ms | 15ms | Best accuracy |
| Event Tracking | 5,000 | 1ms | 3ms | Async write |
| Scale | Daily Requests | Setup | Monthly Cost |
|---|---|---|---|
| Starter | 1M | 1x 2vCPU 4GB | ~$40 |
| Growth | 10M | 2x 4vCPU 8GB | ~$150 |
| Scale | 100M | 4x 8vCPU 16GB + Redis Cluster | ~$600 |
openadserver/
โโโ ad_server/ # FastAPI application
โ โโโ routers/ # API endpoints (ad, event, campaign)
โ โโโ services/ # Business logic
โ โโโ middleware/ # Logging, metrics, auth
โโโ rec_engine/ # Recommendation engine
โ โโโ retrieval/ # Candidate retrieval & targeting
โ โโโ ranking/ # eCPM bidding & ranking
โ โโโ filter/ # Budget, frequency, quality filters
โ โโโ reranking/ # Diversity & exploration
โโโ ml_engine/ # Machine learning
โ โโโ models/ # DeepFM, LR, FM implementations
โ โโโ features/ # Feature engineering pipeline
โ โโโ serving/ # Online prediction server
โโโ common/ # Shared utilities
โ โโโ config.py # Configuration management
โ โโโ database.py # PostgreSQL connection
โ โโโ cache.py # Redis client
โ โโโ logger.py # Structured logging
โโโ trainer/ # Model training
โโโ scripts/ # Utility scripts
โโโ configs/ # YAML configurations
โโโ deployment/ # Docker, K8s, Nginx
โโโ tests/ # Test suite
- Core ad serving API
- eCPM-based ranking (CPM/CPC/CPA)
- Targeting engine (geo, device, demographics)
- DeepFM & LR CTR models
- Event tracking (impression/click/conversion)
- Docker Compose deployment
- Prometheus + Grafana monitoring
- Admin dashboard UI (React)
- Campaign management API
- Audience segments
- A/B testing framework
- OpenRTB 2.5 support
- Header bidding
- Multi-tenant SaaS mode
- Kubernetes Helm charts
- Video ad support (VAST)
- ๐ฐ Takes 20-30% revenue share
- ๐ Your data belongs to Google
- ๐ซ Limited customization
- OpenAdServer: Keep 100% revenue, own your data
- ๐ด Legacy PHP codebase
- ๐ No ML capabilities
- ๐ Basic reporting only
- OpenAdServer: Modern Python, ML-powered, real eCPM
- โฐ 6-12 months development
- ๐ธ $100K+ engineering cost
- ๐ Countless edge cases
- OpenAdServer: Production-ready in hours
We love contributions! See CONTRIBUTING.md for guidelines.
# Setup development environment
make setup
# Run tests
make test
# Run linting
make lint
# Format code
make formatApache License 2.0 โ See LICENSE for details.
Free for commercial use. No attribution required (but appreciated! ๐)
- ๐ Documentation Wiki
- ๐ฌ GitHub Discussions
- ๐ Issue Tracker
- ๐ฆ Twitter @OpenAdServer
Built with โค๏ธ by engineers who've scaled ad systems to 100M+ daily requests
Extracted from production systems serving billions of ad impressions
Keywords: open source ad server, self-hosted ad platform, ad serving, programmatic advertising, CTR prediction, DeepFM, ad tech, digital advertising platform, ad network software, DSP, SSP, advertising API, ad management system, Python ad server