Modern video platforms need to balance delivery quality, infrastructure cost, and edge capacity. This project simulates that workflow with a small but end-to-end analytics system.
The system answers questions such as:
- Did the treatment delivery strategy reduce latency?
- Did startup time and rebuffer ratio improve as guardrail metrics?
- Did the improvement increase CDN cost?
- Which regions or edge PoPs contributed most to the change?
- Are any edge PoPs approaching capacity risk?
- Can a local LLM generate a readable experiment readout without inventing unsupported causes?
- YouTube API ingestion for real video metadata.
- Synthetic CDN delivery log generation for latency, startup time, rebuffer ratio, cache hit, cost, protocol, IP version, region, and edge PoP signals.
- PostgreSQL metrics layer for quality, cost, capacity, and segment diagnostics.
- A/B testing framework with relative lift, Welch two-sample t-test, and bootstrap confidence intervals.
- Cost governance report covering cost per 1K events, cache hit rate, and cost-quality tradeoffs.
- Capacity monitoring using simulated edge PoP capacity snapshots, CPU utilization, memory utilization, and high-utilization thresholds.
- Grounded root-cause workflow using deterministic SQL/Python diagnostics first, followed by local LLM rewriting.
- Local Ollama LLM integration for experiment readouts and hypothesis summarisation.
- Streamlit dashboard for interactive exploration of quality, cost, capacity, and LLM readouts.
- Bash pipeline automation for reproducible local execution.
YouTube Data API
|
v
Raw JSON / Processed Parquet
|
v
Synthetic CDN Delivery Logs
|
v
PostgreSQL
|
+-----------------------------+
| |
v v
SQL Metrics Python Analytics
| |
| +--> A/B testing
| +--> Bootstrap CI
| +--> Cost-quality report
| +--> Capacity report
| +--> Rule-based diagnostics
|
v
Streamlit Dashboard
|
v
Local Ollama LLM
|
+--> Experiment readout rewriting
+--> Grounded root-cause summary rewriting
llm-video-delivery-analytics/
├── data/
│ ├── raw/
│ ├── processed/
│ ├── synthetic_delivery/
│ └── llm_enriched/
│
├── sql/
│ ├── schema.sql
│ └── metrics/
│ ├── quality_metrics.sql
│ ├── cost_metrics.sql
│ ├── capacity_metrics.sql
│ └── network_segment_metrics.sql
│
├── src/
│ ├── data/
│ │ ├── ingest_youtube_api.py
│ │ ├── generate_delivery_logs.py
│ │ ├── generate_capacity_snapshots.py
│ │ └── load_to_postgres.py
│ │
│ ├── experiments/
│ │ └── ab_test_latency.py
│ │
│ ├── metrics/
│ │ ├── cost_quality_report.py
│ │ ├── capacity_report.py
│ │ ├── root_cause_diagnostics.py
│ │ └── rule_based_root_cause.py
│ │
│ ├── llm/
│ │ ├── experiment_summariser.py
│ │ └── root_cause_assistant.py
│ │
│ └── dashboard/
│ └── app.py
│
├── reports/
│ ├── metric_dictionary.md
│ ├── experiment_readout.md
│ ├── cost_quality_report.md
│ ├── capacity_report.md
│ ├── diagnostics/
│ └── llm_outputs/
│
├── scripts/
│ ├── run_pipeline.sh
│ └── run_dashboard.sh
│
├── docker-compose.yml
├── Makefile
├── requirements.txt
├── .env.example
└── README.md
Video metadata is collected through the YouTube Data API. The ingestion script fetches popular videos by region and stores both raw JSON responses and processed Parquet/CSV files.
Example fields:
video_idchannel_idchannel_titletitledescriptiontagscategory_idpublished_atview_countlike_countcomment_count
Public datasets usually do not contain internal CDN delivery logs, so this project generates synthetic delivery events based on the collected video metadata.
Example fields:
region_codeedge_popprotocolip_versionlatency_msstartup_time_msrebuffer_ratiobitrate_kbpscache_hitcdn_cost_usdexperiment_idvariant
The project also simulates hourly edge capacity snapshots for resource capacity analysis.
Example fields:
snapshot_timeedge_popregion_codemax_capacity_mbpsused_capacity_mbpsutilization_ratioactive_connectionscpu_utilizationmemory_utilization
The project defines metrics across four groups.
- Average latency
- Startup time
- Rebuffer ratio
- Cache hit rate
- Total CDN cost
- Average cost per event
- Cost per 1K events
- Cost-quality tradeoff by region and edge PoP
- Average utilization
- Peak utilization
- High-utilization hours
- Critical-utilization hours
- High-utilization share
- CPU utilization
- Memory utilization
- Absolute treatment-control difference
- Relative lift
- Welch two-sample t-test
- Bootstrap confidence interval
- Guardrail metric checks
Detailed definitions are available in reports/metric_dictionary.md.
The project simulates a delivery strategy experiment with control and treatment variants.
Example result:
Control mean latency: 33.81 ms
Treatment mean latency: 30.42 ms
Relative lift: -10.01%
Bootstrap 95% CI: [-3.47 ms, -3.30 ms]
P-value: < 0.001
Interpretation:
The treatment reduces average delivery latency by approximately 10%, and the result is statistically significant. Startup time and rebuffer ratio also improve, while CDN cost remains a guardrail metric during rollout.
The LLM is not used as the source of truth for analytical decisions.
The project uses a local Ollama model for:
- Rewriting statistical experiment outputs into business-facing readouts.
- Rewriting deterministic root-cause summaries into concise hypothesis reports.
- Making technical reports easier to read.
The LLM must not invent causes that are not measured in the data, such as packet loss, routing changes, cache misses, CPU bottlenecks, or origin-server latency.
Final decisions are grounded in:
SQL metrics
statistical tests
bootstrap confidence intervals
rule-based diagnostics
The root-cause workflow is intentionally designed as:
SQL/Python diagnostics
↓
rule-based source-of-truth summary
↓
local LLM rewrite
This avoids LLM-dependent decision making.
The Streamlit dashboard includes five pages:
- Overview — high-level quality, cost, and capacity summary.
- Quality Experiment — control vs treatment metrics and segment diagnostics.
- Cost Governance — cost per 1K events and cost breakdowns.
- Capacity Risk — edge PoP utilization and capacity risk monitoring.
- LLM Readouts — experiment readout, root-cause hypothesis summary, and metric dictionary.
docs/images/dashboard_overview.png
Then include it with:
git clone https://github.com/<your-username>/llm-video-delivery-analytics.git
cd llm-video-delivery-analyticspython3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtcp .env.example .envFill in the required values:
DATABASE_URL=postgresql+psycopg2://delivery:delivery@localhost:55434/video_delivery_analytics
DB_HOST=localhost
DB_PORT=55434
DB_USER=delivery
DB_PASSWORD=delivery
DB_NAME=video_delivery_analytics
LLM_PROVIDER=ollama
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_GENERATE_URL=http://localhost:11434/api/generate
OLLAMA_MODEL=llama3.2:3b
YOUTUBE_API_KEY=your_youtube_api_key_here
PROJECT_NAME=llm-video-delivery-analytics
ENV=localDo not commit .env.
docker compose up -dOr:
make db-uppython src/data/ingest_youtube_api.pyThis creates:
data/raw/youtube/*.json
data/processed/youtube_videos.csv
data/processed/youtube_videos.parquet
./scripts/run_pipeline.shOr:
make pipelineThe pipeline runs synthetic data generation, schema setup, database loading, SQL metrics, Python reports, and optional local LLM readouts.
./scripts/run_dashboard.shOr:
make dashboardThen open:
http://localhost:8501
The automated Bash pipeline performs:
- Docker/Postgres startup
- Required data checks
- Synthetic CDN delivery log generation
- Edge capacity snapshot generation
- Database schema setup
- Database reset and Parquet-to-Postgres loading
- SQL metric execution
- A/B test analysis
- Cost-quality report generation
- Capacity report generation
- Root-cause diagnostics
- Rule-based root-cause summary generation
- Optional local Ollama LLM readout generation
Key generated outputs include:
reports/experiment_readout.md
reports/cost_quality_report.md
reports/capacity_report.md
reports/diagnostics/rule_based_root_cause.md
reports/llm_outputs/protocol_test_readout.md
reports/llm_outputs/root_cause_hypotheses.md
reports/metric_dictionary.md
Run quality metrics:
psql -h localhost -p 55434 -U delivery -d video_delivery_analytics -f sql/metrics/quality_metrics.sqlRun A/B test:
python src/experiments/ab_test_latency.pyRun cost report:
python src/metrics/cost_quality_report.pyRun capacity report:
python src/metrics/capacity_report.pyRun root-cause workflow:
python src/metrics/root_cause_diagnostics.py
python src/metrics/rule_based_root_cause.py
python src/llm/root_cause_assistant.pyRun dashboard:
streamlit run src/dashboard/app.pymake install # install dependencies
make db-up # start Postgres
make pipeline # run full local analytics pipeline
make dashboard # launch Streamlit dashboard
make test # run tests
make clean # remove generated intermediate outputsThe CDN delivery and capacity data are synthetic by design. They are used to simulate a realistic analytics workflow where internal delivery logs are not publicly available.
The project focuses on:
- metric design
- data pipeline structure
- SQL analytics
- statistical decision-making
- cost and capacity governance
- safe LLM-assisted reporting
The synthetic data should not be interpreted as real network performance data.
- Python
- pandas / NumPy / SciPy
- PostgreSQL
- SQLAlchemy
- Docker Compose
- Streamlit
- Plotly
- Bash scripting
- Ollama local LLM
- YouTube Data API
Current project status:
- API ingestion: complete
- Synthetic delivery log generation: complete
- PostgreSQL schema and loading: complete
- Quality metrics and A/B testing: complete
- Cost governance report: complete
- Capacity report: complete
- Grounded root-cause workflow: complete
- Local LLM readouts: complete
- Streamlit dashboard: complete
- Pipeline automation: complete
