Cloud-Native Distributed Video Processing & Adaptive Streaming Platform
Flux is a production-grade video platform that enables you to upload raw video files and stream them as adaptive HLS content delivered globally through AWS CloudFront. It demonstrates a full event-driven architecture with real-time status updates, signed cookie security, and Infrastructure as Code.
Live Demo: https://video-processing.masir-projects.me
| Feature | Implementation |
|---|---|
| π€ Direct-to-S3 Upload | Browser uploads directly to S3 via pre-signed POST URL (server never handles binary data) |
| βοΈ Asynchronous Transcoding | SQS decouples upload detection from FFmpeg processing; worker runs independently |
| π¬ Adaptive Bitrate Streaming | Three HLS variants: 360p / 480p / 720p with automatic quality switching via HLS.js |
| π Signed Cookie Security | CloudFront + OAC + RSA signed cookies; S3 buckets are fully private |
| β‘ Real-Time Status Updates | AWS API Gateway WebSocket pushes VIDEO_COMPLETED events to all browsers |
| π Global CDN Delivery | CloudFront with OAC (Origin Access Control) β faster and more secure than OAI |
| ποΈ Infrastructure as Code | All AWS resources provisioned via Terraform; zero click-ops |
| π Automated CI/CD | GitHub Actions deploys on every push to main |
Browser β Nginx (TLS) β Express API β S3 (presigned POST)
β
SQS Queue (S3 event)
β
Transcoder Worker (FFmpeg)
β
S3 (HLS artifacts) β CloudFront β Browser (HLS.js)
β
WebSocket (API Gateway) β Browser (real-time update)
For detailed architecture diagrams, see docs/architecture/overview.md.
| Layer | Technology |
|---|---|
| Frontend | Next.js 14, HLS.js, React |
| Backend API | Node.js, Express, Prisma |
| Worker | Node.js, FFmpeg (fluent-ffmpeg) |
| Database | PostgreSQL 16 |
| Cache | Redis 7 |
| Object Storage | AWS S3 (3 buckets) |
| Queue | AWS SQS (Standard + DLQ) |
| CDN | AWS CloudFront (OAC + Signed Cookies) |
| WebSocket | AWS API Gateway (WebSocket) |
| Compute | AWS EC2 t3.small (Docker Compose) |
| DNS/TLS | Namecheap + Let's Encrypt |
| IaC | Terraform (modular) |
| CI/CD | GitHub Actions |
| Monitoring | AWS CloudWatch (custom metrics + dashboard) |
.
βββ backend/
β βββ upload-service/ # Node.js REST API
β βββ src/
β β βββ controllers/ # Route handlers
β β βββ services/ # Business logic (S3, cookies, WebSocket)
β β βββ middleware/ # Rate limiting, error handling
β β βββ db/ # Prisma client
β βββ Prisma/ # Database schema + migrations
β
βββ workers/
β βββ transcoder-worker/ # FFmpeg processing worker
β βββ src/
β β βββ queue/ # SQS consumer
β β βββ processors/ # Job orchestration
β β βββ services/ # S3, HLS, thumbnail, notification
β βββ Prisma/ # Database schema + migrations
β
βββ frontend/
β βββ web/ # Next.js application
β βββ app/ # App Router pages
β βββ components/
β β βββ video/ # VideoPlayer, ManifestInspector, StatsForNerds
β βββ lib/ # API client utilities
β
βββ infra/
β βββ docker/ # Docker Compose + .env
β βββ nginx/ # nginx.conf
β βββ keys/ # CloudFront RSA key pair (gitignored)
β βββ terraform/
β βββ environments/dev/ # Environment-specific config
β βββ modules/ # vpc, ec2, iam, s3, sqs, cloudfront, websocket, acm
β
βββ docs/ # π Full documentation suite
β βββ architecture/
β βββ backend/
β βββ frontend/
β βββ infrastructure/
β βββ deployment/
β
βββ .github/workflows/
βββ deploy.yml # CI/CD pipeline
- Node.js 20+
- Docker & Docker Compose
- AWS Account with CLI configured
- Terraform 1.6+
git clone https://github.com/MasirJafri1/distributed-video-processing-platform.git
cd distributed-video-processing-platform
# Provision AWS infrastructure
cd infra/terraform/environments/dev
terraform init && terraform apply
# Configure environment
cp infra/docker/.env.example infra/docker/.env
# Edit .env with your terraform outputsmkdir -p infra/keys
openssl genrsa -out infra/keys/cloudfront-private.pem 2048
openssl rsa -pubout -in infra/keys/cloudfront-private.pem -out infra/keys/cloudfront-public.pemcd infra/docker
docker compose up -d --build
# Access frontend
open http://localhost:3001
# API health check
curl http://localhost:3000/healthFor full setup instructions, see docs/deployment/local-development.md.
| Document | Description |
|---|---|
| Architecture Overview | System design, ADRs, end-to-end flow |
| System Context | External systems and security boundaries |
| Container Diagram | Per-container responsibilities and interactions |
| Video Processing Pipeline | FFmpeg stages, HLS generation, failure handling |
| AWS Services | Per-service rationale, alternatives, and cost |
| Scalability | Current limits and upgrade path |
| Upload Service API | Complete API service documentation |
| Transcoder Worker | FFmpeg processing internals |
| Database Schema | ER diagram, query patterns, migrations |
| WebSocket Flow | Real-time notification architecture |
| API Reference | All endpoints with examples |
| HLS & Adaptive Streaming | HLS playlists, ABR algorithm, cookies |
| Terraform Infrastructure | Module structure, dependency graph |
| Networking | VPC, security groups, DNS, TLS |
| Security | OAC, signed cookies, IAM, risks |
| Cost Analysis | Service costs and optimization strategies |
| Local Development | Getting started guide |
| EC2 Deployment | Production server management |
| GitHub Actions CI/CD | Automated deployment pipeline |
| Environment Variables | Complete variable reference |
| Monitoring | CloudWatch dashboards and alerts |
| Troubleshooting | 14 common issues with solutions |
FFmpeg transcoding takes 3β15 minutes for typical files. AWS Lambda has a 15-minute maximum execution time with no CPU guarantee. SQS + long-running EC2 worker provides better reliability and cost predictability.
Docker Compose on EC2 provides identical container isolation at 1/10th the operational complexity of ECS for a single-instance deployment. The architecture is designed to migrate to ECS with minimal code changes.
HLS playback makes 300+ requests per video session (master playlist + variant playlists + all segments). Signed cookies authenticate all requests with a single cookie set, making them ideal for HLS.
CloudFront OAC (Origin Access Control) uses SigV4 signing and supports S3 SSE-KMS. OAI is deprecated. OAC is more secure and AWS's current recommendation.
Masir Jafri β Senior Full-Stack Engineer specializing in cloud-native architectures
- π masirjafri.in
- π masirjafri.hashnode.dev
- πΌ LinkedIn
- π GitHub