A production-grade, horizontally scalable YouTube audio/video downloader built with FastAPI, Celery, Redis, PostgreSQL, and Next.js.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Users (10,000+) β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β HTTP / WebSocket
ββββββββΌβββββββ
β Nginx β Rate limiting, SSL termination,
β (Reverse β load balancing, static files
β Proxy) β
ββββ¬ββββ¬ββββ¬βββ
β β β
ββββββββββββββΌβ ββΌββββΌβββββ
β Next.js β β FastAPI β 3 replicas (horizontal)
β Frontend β β Backend β uvicorn + uvloop
βββββββββββββββ ββββββ¬βββββ
β Celery tasks
ββββββββββββΌβββββββββββ
β Redis β
β βββββββββββββββββ β
β β Broker Queue β β Task queues: downloads,
β β Result Cache β β metadata, cleanup
β β Pub/Sub (WS) β β
β βββββββββββββββββ β
ββββββββββββ¬βββββββββββ
β
ββββββββββββΌβββββββββββ
β Celery Workers β 5 replicas, auto-scaling
β βββββββββββββββββ β yt-dlp + ffmpeg
β β yt-dlp β β ID3 tag embedding
β β ffmpeg β β MP3/MP4 conversion
β βββββββββββββββββ β
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β PostgreSQL β
β download_jobs table β
β Async SQLAlchemy β
βββββββββββββββββββββββββββββββββ
| Feature | Implementation |
|---|---|
| Multi-URL input | Textarea + drag-drop .txt files |
| Playlist expansion | yt-dlp extract_flat |
| Real-time progress | WebSocket + Redis pub/sub |
| MP3 / MP4 | yt-dlp + ffmpeg postprocessors |
| Quality: 128/192/320kbps | yt-dlp audio bitrate selector |
| ID3 tags | FFmpegMetadata + EmbedThumbnail |
| Duplicate detection | DB unique check per session |
| Job cancellation | Celery task revoke |
| ZIP download | Python zipfile streaming |
| Auto cleanup | Celery Beat (hourly) |
| Daily yt-dlp update | Celery Beat (daily) |
| Rate limiting | SlowAPI (per IP) + Nginx |
| Caching | Redis (metadata 1h TTL) |
| Observability | Prometheus + Grafana |
| Horizontal scaling | Docker Compose replicas |
git clone <repo>
cd melodex
./scripts/dev.shThen open:
- App: http://localhost:3000
- API docs: http://localhost:8000/api/docs
- Celery monitor: http://localhost:5555
- Docker + Docker Compose v2
- 4+ CPU cores, 8GB+ RAM for 10k users
- (Optional) AWS account for S3 storage
# 1. Configure
cp .env.example .env
nano .env # Set SECRET_KEY, DATABASE_URL, etc.
# 2. Deploy
./scripts/deploy.sh
# 3. Scale workers for more throughput
docker compose up -d --scale worker=10
# 4. Monitor
open http://localhost:3001 # Grafana (admin/melodex_grafana)| Component | Default | Recommended (10k users) |
|---|---|---|
| Backend replicas | 3 | 5β10 |
| Celery workers | 5 | 20β50 |
| Worker concurrency | 4 | 4 (keep low β yt-dlp is CPU-bound) |
| Redis maxmemory | 512MB | 2β4GB |
| PostgreSQL max_connections | 200 | 500 |
| Nginx worker_connections | 4096 | 16384 |
# Scale up:
docker compose up -d \
--scale backend=8 \
--scale worker=30Submit URLs for download.
{
"urls": ["https://youtube.com/watch?v=..."],
"format": "mp3",
"quality": "320",
"session_id": "uuid-v4-string"
}List all jobs for a session.
Queue statistics (total, pending, downloading, completed, failed).
Cancel a job.
Download the completed file.
Download all completed files as ZIP.
Preview metadata before queuing.
{ "url": "https://youtube.com/watch?v=..." }Real-time progress stream. Messages:
{ "type": "progress", "job_id": "...", "status": "downloading", "progress": 45.2 }
{ "type": "metadata", "job_id": "...", "title": "Song Title", "thumbnail_url": "..." }
{ "type": "ping" }- youtube-dl hasn't been updated since December 2021 β YouTube's internal player changes broke it completely (the errors you saw:
Signature extraction failed,decodeURIComponent not found) - yt-dlp is an actively maintained fork, updated weekly, handles all YouTube changes
- We also auto-update yt-dlp daily via Celery Beat so it stays current
This software is for personal use only. Do not download copyrighted content you don't have rights to. The developer is not responsible for misuse. Respect YouTube's Terms of Service.
| Layer | Technology |
|---|---|
| API | FastAPI 0.111 + uvicorn + uvloop |
| Task Queue | Celery 5.4 + Redis 7 |
| Database | PostgreSQL 16 + SQLAlchemy 2 async |
| Download Engine | yt-dlp (latest) + ffmpeg |
| Frontend | Next.js 14 + React 18 + Zustand |
| Real-time | WebSockets + Redis Pub/Sub |
| Proxy | Nginx 1.25 |
| Monitoring | Prometheus + Grafana |
| CI/CD | GitHub Actions |
| Containers | Docker + Docker Compose |