Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Flux

Cloud-Native Distributed Video Processing & Adaptive Streaming Platform

Deploy to EC2 Live Demo [License: MIT


What is Flux?

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


Key Features

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

Architecture Overview

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.


Tech Stack

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)

Repository Structure

.
β”œβ”€β”€ 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

Quick Start

Prerequisites

  • Node.js 20+
  • Docker & Docker Compose
  • AWS Account with CLI configured
  • Terraform 1.6+

1. Clone and Setup

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 outputs

2. Generate CloudFront Key Pair

mkdir -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.pem

3. Run

cd infra/docker
docker compose up -d --build

# Access frontend
open http://localhost:3001

# API health check
curl http://localhost:3000/health

For full setup instructions, see docs/deployment/local-development.md.


Documentation

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

Key Design Decisions

ADR-001: SQS over Lambda for Transcoding

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.

ADR-002: EC2 over ECS/Fargate

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.

ADR-003: CloudFront Signed Cookies over Signed URLs

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.

ADR-004: OAC over Legacy OAI

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.


Author

Masir Jafri β€” Senior Full-Stack Engineer specializing in cloud-native architectures

About

Cloud-native, event-driven distributed video processing & adaptive streaming platform. Direct-to-S3 uploads, FFmpeg worker queue (SQS), HLS/ABR streaming, CloudFront Signed Cookies security, and modular Terraform IaC.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages