Technical Architecture • APIs • Data • AI

AdTech APIs, Data Pipelines & Integrations

Modern advertising technology is a distributed ecosystem connected by APIs, streaming protocols, databases, and automated telemetry. Explore how REST APIs, Python analytics, SQL discrepancy queries, and Model Context Protocol (MCP) AI agents integrate across ad serving, programmatic bidding, and attribution.

⚡ Live API Explorer 🔄 Data Workflow 📊 SQL Query Library 🤖 MCP AI Integration
🌐 Hosted on Hostinger (Production Web Server)

PHP • MySQL • REST APIs • JavaScript

Powers this website, database-backed read-only JSON API endpoints (/api/v1/), and client-side interactive diagnostic sandboxes (OpenRTB Validator, GAM Simulator, VAST Inspector).

💻 External Engineering (GitHub / Separate Runtime)

Python • Pandas • MCP Server • AI Agents

External standalone Python clients, Pandas data analytics scripts, and Model Context Protocol (MCP) servers that query the PHP REST API over HTTPS. Python and MCP are not executed on Hostinger.

1. The End-to-End AdTech Communication Chain

AdTech systems communicate via distinct synchronous auction protocols (OpenRTB/VAST) and asynchronous REST/JSON management APIs across 5 core tiers:

┌─────────────────────────┐ REST API / OAuth 2.0 ┌─────────────────────────┐ │ Advertiser / DSP UI │ ─────────────────────────────► │ Google Ad Manager 360 │ │ (Campaigns & Budgets) │ ◄───────────────────────────── │ (Inventory & Orders) │ └─────────────────────────┘ Sync Status & Yield └─────────────────────────┘ │ │ │ Programmatic OpenRTB (ms latency) │ Line Item Allocation ▼ ▼ ┌─────────────────────────┐ Real-Time S2S Auction ┌─────────────────────────┐ │ SSP / Ad Exchange │ ◄────────────────────────────► │ Prebid Server (PBS) │ │ (Floors, Deals, SChain) │ │ (Multi-Bidder Routing) │ └─────────────────────────┘ └─────────────────────────┘ │ │ │ VAST XML / SSAI Stitched Chunks │ Impression / Quartile Pings ▼ ▼ ┌─────────────────────────┐ Attribution Pull API ┌─────────────────────────┐ │ Smart TV / Mobile App │ ─────────────────────────────► │ Measurement (AppsFlyer) │ │ (Player & Impression) │ │ & Verification (IAS/DV)│ └─────────────────────────┘ └─────────────────────────┘ │ │ └─────────────────────────┬─────────────────────────────────┘ │ Log Transfer / S3 Export ▼ ┌───────────────────────────┐ │ Cloud Data Warehouse │ │ (BigQuery, Snowflake) │ │ Python / SQL / Dashboards│ └───────────────────────────┘

2. REST API Protocols & Enterprise Integration Mechanics

Robust AdTech integrations require strict protocol compliance, deterministic error handling, and secure authentication standards:

HTTP Methods & Payloads

RESTful Resource Operations

GET Fetch inventory, performance reports, and line item statuses.
POST Create campaigns, submit bids, generate bulk report jobs.
PUT Full replacement of targeting or creative flight dates.
DELETE Archive deal IDs or deactivate underperforming creatives.

Authentication & Security

OAuth 2.0 & Token Lifecycles

OAuth 2.0 Client Credentials: Machine-to-machine server communication (GAM API, Google Cloud).
Bearer Tokens: Ephemeral JWTs passed in Authorization: Bearer <token>.
API Keys: Parameterized validation for read-only telemetry and webhook verification.

Resilience & Idempotency

Rate Limits & Safe Retries

Rate Limiting: Respecting 429 Too Many Requests and Retry-After headers.
Exponential Backoff: Retrying transient 5xx errors with jitter (e.g. 2s, 4s, 8s).
Idempotency Keys: Passing Idempotency-Key in POST requests to prevent duplicate ad credit billing.

Event Delivery

Webhooks & Stream Alerts

Real-Time Postbacks: MMP attribution alerts (AppsFlyer install postbacks).
Payload Signing: HMAC-SHA256 signature verification in X-Signature header.
Dead-Letter Queues (DLQ): Capturing malformed webhook events for automated triage.

Interactive Testbench

Live AdTech Read-Only API Explorer

🔒 Safe Read-Only Endpoints Active

Select an endpoint below or click Send Request to query live structured AdTech campaign telemetry and auction diagnostics:

GET /api/v1/campaigns.php
Response Payload (HTTP 200 OK):
Loading API response...

3. The Engineering Data Pipeline: API → Database → Python → SQL

Technical AdTech roles require transforming raw API logs and SQL tables into actionable business decisions using Python automation:

Step 1: Ingest Step 2: Store Step 3: Analyze Step 4: Action ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │ AdTech REST API │ ───────► │ SQL Database │ ──────► │ Python + Pandas │ ──────► │ Root-Cause (RCA) │ │ (GAM/SSP Logs) │ │ (Data Warehouse) │ │ (KPI Automation) │ │ & Floor Decision │ └──────────────────┘ └──────────────────┘ └──────────────────┘ └──────────────────┘
Python Client Script scripts/adtech_api_client.py

The standalone Python client executes authenticated HTTP GET requests with exponential backoff, parses the JSON payload into a Pandas DataFrame, and detects campaigns with low CTR (< 0.5%) or high CPA:

import urllib.request, json, time
import pandas as pd

class AdTechApiClient:
    def __init__(self, base_url="https://adtechsanto.fun/api/v1"):
        self.base_url = base_url
        self.headers = {"Accept": "application/json", "X-API-Key": "client_token"}

    def fetch_campaigns(self):
        req = urllib.request.Request(f"{self.base_url}/campaigns.php", headers=self.headers)
        with urllib.request.urlopen(req, timeout=5) as resp:
            return json.loads(resp.read().decode("utf-8"))["data"]

# Transform to Pandas DataFrame for KPI Analysis
client = AdTechApiClient()
df = pd.DataFrame(client.fetch_campaigns())
underperforming = df[df["ctr_percent"] < 0.5]
print(f"[ALERT] Flagged {len(underperforming)} underperforming campaigns for floor review.")

4. AdTech SQL Query Library (MySQL 8.0)

Standard MySQL 8.0 Syntax

How SQL is used to solve real-world AdTech operational challenges, from aggregated KPI calculations to multi-partner impression discrepancy reconciliation:

Executable Demo SQL Table: campaigns

Campaign Channel Aggregations & eCPM

Business Question: What is the total spend, aggregate CTR, and average eCPM across active campaigns grouped by delivery channel?

-- Executable MySQL Query
SELECT 
    channel,
    COUNT(id) AS total_campaigns,
    SUM(spend) AS total_spend_usd,
    SUM(impressions) AS total_impressions,
    SUM(clicks) AS total_clicks,
    ROUND((SUM(clicks) / NULLIF(SUM(impressions), 0)) * 100, 3) AS aggregate_ctr_pct,
    ROUND((SUM(spend) / NULLIF(SUM(impressions), 0)) * 1000, 2) AS aggregate_ecpm_usd
FROM campaigns
WHERE status = 'active'
GROUP BY channel
ORDER BY total_spend_usd DESC;

Expected Output: Rows for CTV ($42.1k spend, $22.78 eCPM), Mobile Display ($18.4k spend, $5.00 eCPM), etc.

Illustrative SQL Example Tables: gam_logs, dsp_logs

GAM vs. DSP Hourly Discrepancy Reconciliation

Business Question: Where does the billing variance between publisher ad server impressions and DSP billed logs exceed 15%?

-- Illustrative MySQL 8.0 CTE Query
WITH hourly_metrics AS (
    SELECT 
        DATE_FORMAT(g.event_time, '%Y-%m-%d %H:00:00') AS log_hour,
        g.ad_unit_id,
        COUNT(g.impression_id) AS gam_impressions,
        COUNT(d.dsp_impression_id) AS dsp_impressions
    FROM gam_data_transfer g
    LEFT JOIN dsp_billing_logs d 
      ON g.auction_id = d.auction_id
    WHERE g.event_time >= NOW() - INTERVAL 24 HOUR
    GROUP BY log_hour, g.ad_unit_id
)
SELECT 
    log_hour,
    ad_unit_id,
    gam_impressions,
    dsp_impressions,
    ROUND(((gam_impressions - dsp_impressions) / CAST(gam_impressions AS DECIMAL(10,2))) * 100, 2) AS discrepancy_pct
FROM hourly_metrics
WHERE gam_impressions > 0 
  AND ((gam_impressions - dsp_impressions) / CAST(gam_impressions AS DECIMAL(10,2))) > 0.15
ORDER BY discrepancy_pct DESC;

Expected Output: Log hours with discrepancy > 15% flagged for VAST render abort or tracking beacon drop triage.

Advanced Integration Protocol

Model Context Protocol (MCP) in AdTech

AI Agent ↔ Data Integration Standard

Protocol Distinction: OpenRTB is an advertising auction protocol; VAST is a video delivery protocol. Model Context Protocol (MCP) is an open integration standard developed by Anthropic that connects AI agents securely to tools, databases, and enterprise APIs.

Hosting & Runtime Architecture Separation:
Production Website (Hostinger): Runs the lightweight PHP + MySQL + JavaScript stack serving HTML and secure read-only JSON REST API endpoints.
External Data & AI Layer (GitHub / Local Runtime): The Python client, Pandas analytics, and MCP Server run in separate external environments, querying the Hostinger PHP API over HTTPS. Python and MCP are NOT executed on the Hostinger shared server.
AdTech Systems (OpenRTB, GAM, VAST, AppsFlyer) │ ┌──────────┴──────────┐ ▼ ▼ REST APIs AdTech Data │ │ └──────────┬──────────┘ ▼ PHP + MySQL ◄─── [Hosted on Hostinger] │ JSON APIs ◄─── [Hosted on Hostinger] │ ┌──────────┴──────────┐ ▼ ▼ JavaScript Python ◄─── [External / GitHub / Local Runtime] │ │ ▼ ▼ Web Diagnostics Data Analysis ◄─── [Pandas ETL & Discrepancy Logic] (In-Browser Sandbox) │ ▼ MCP Server ◄─── [External AI Host / JSON-RPC] │ ▼ AI Agent ◄─── [Claude / Antigravity / LLM]

Documented MCP Server Tools

search_campaigns Implemented

Queries PHP REST endpoint to filter campaigns by channel, advertiser, or status.

get_campaign_performance Implemented

Fetches single campaign JSON and returns calculated CTR, eCPM, CPC, and CPA.

compare_campaigns Implemented

Multi-campaign comparison across spend, impressions, and conversion rates.

get_underperforming_campaigns Implemented

Calls ?action=underperforming to alert on low CTR campaigns (CTR < 0.5%).

get_top_performing_campaigns Implemented

Ranks active campaigns by conversion efficiency and volume.

auto_adjust_floors Planned

Automated floor price modification based on win-rate elasticity (Future enhancement).

5. External Python & AI Engineering Projects (GitHub)

Standalone repositories • External runtimes

Concrete Python, SQL, and AI/MCP projects demonstrating hands-on technical development outside the website:

Python + MCP Project Working Prototype

Ad Campaign Analyst

Problem: Manually pulling and cross-referencing multi-network campaign performance data to identify yield leaks is slow and fragmented.
What I Built: A Python analytics engine and Model Context Protocol (MCP) server that connects AI assistants to campaign performance data for automated KPI analysis and anomaly detection.
Stack: Python 3.13, Pandas, Model Context Protocol (MCP), REST APIs, JSON-RPC.

Data Analysis Analytics Prototype

Bid Analyzer

Problem: Debugging high No-Bid rates and bid floor rejections requires parsing large OpenRTB log files.
What I Built: A Python log parsing script for analyzing OpenRTB bid request distributions, win rates, and clearing price densities across programmatic buyers.
Stack: Python, Requests, Pandas, OpenRTB 2.5/2.6 JSON schemas.

System Simulation Technical Demonstration

AdFlow Simulator

Problem: Testing ad server priority resolutions requires a deterministic sandbox environment.
What I Built: An auction simulation engine modeling waterfall decision logic, floor price checks, and competitive separation rules.
Stack: PHP, JavaScript, OpenRTB Schemas, GAM Decision Logic.

AdTech Toolkit

Enter any two values
to calculate the third

More tools coming soon