Skip to content

A high-performance, production-ready video/audio streaming service built in Go, designed for 100M+ RPS with HLS adaptive bitrate streaming.

Notifications You must be signed in to change notification settings

ichbingautam/streaming-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Streaming Service

Go Version License

A high-performance, production-ready video/audio streaming service built in Go, designed for 100M+ RPS with HLS adaptive bitrate streaming.

🎯 Overview

This streaming platform provides enterprise-grade video delivery with:

  • HLS Adaptive Streaming - Automatic quality adjustment based on viewer bandwidth
  • Multi-Bitrate Encoding - 1080p, 720p, 480p, 360p renditions
  • Audio Support - Standalone audio streaming and video audio extraction
  • AWS Native - S3 storage, DynamoDB metadata, CloudFront CDN
  • Kubernetes Ready - Terraform-managed infrastructure for auto-scaling

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                              CLIENT LAYER                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚
β”‚  β”‚   Web    β”‚  β”‚  Mobile  β”‚  β”‚ Smart TV β”‚  β”‚   OTT    β”‚                     β”‚
β”‚  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚             β”‚             β”‚             β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                           CDN / EDGE LAYER                                   β”‚
β”‚                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                   β”‚
β”‚                        β”‚   CloudFront    β”‚  ◄── Cached HLS Segments         β”‚
β”‚                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         API GATEWAY LAYER                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”‚
β”‚  β”‚ Load Balancer │──│  API Server   │──│     Auth      β”‚                    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
β”‚                             β”‚                                                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        MICROSERVICES LAYER                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚   Upload    β”‚  β”‚  Transcode  β”‚  β”‚   Stream    β”‚  β”‚    Audio    β”‚         β”‚
β”‚  β”‚   Service   β”‚  β”‚   Service   β”‚  β”‚   Service   β”‚  β”‚   Service   β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                β”‚                β”‚                β”‚
          β–Ό                β–Ό                β–Ό                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         DATA & PROCESSING LAYER                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚     S3      β”‚  β”‚   FFMPEG    β”‚  β”‚  DynamoDB   β”‚  β”‚    Redis    β”‚         β”‚
β”‚  β”‚  (Storage)  β”‚  β”‚  (Encoding) β”‚  β”‚ (Metadata)  β”‚  β”‚   (Queue)   β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

streaming-service/
β”œβ”€β”€ cmd/
β”‚   β”œβ”€β”€ api/                 # API server entrypoint
β”‚   └── worker/              # Transcoding worker entrypoint
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ api/                 # HTTP handlers & Chi router
β”‚   β”œβ”€β”€ config/              # Viper configuration management
β”‚   β”œβ”€β”€ domain/              # Business entities (Media, Video, Audio)
β”‚   β”œβ”€β”€ media/
β”‚   β”‚   β”œβ”€β”€ ffmpeg/          # FFMPEG video/audio processors
β”‚   β”‚   └── processor/       # Factory & Strategy pattern implementations
β”‚   β”œβ”€β”€ queue/               # Redis job queue with priority support
β”‚   β”œβ”€β”€ repository/
β”‚   β”‚   β”œβ”€β”€ dynamodb/        # Metadata CRUD operations
β”‚   β”‚   └── s3/              # Object storage with presigned URLs
β”‚   └── service/
β”‚       β”œβ”€β”€ audio/           # Audio extraction & processing
β”‚       β”œβ”€β”€ stream/          # Playback URL generation
β”‚       β”œβ”€β”€ transcode/       # HLS transcoding pipeline
β”‚       └── upload/          # File upload handling
β”œβ”€β”€ pkg/
β”‚   └── logger/              # Zap structured logging
β”œβ”€β”€ deployments/
β”‚   β”œβ”€β”€ docker/              # Multi-stage Dockerfiles
β”‚   β”œβ”€β”€ kubernetes/          # K8s manifests
β”‚   └── terraform/           # Infrastructure as Code
└── config.yaml              # Application configuration

🎨 Design Patterns

Factory Pattern

Creates appropriate media processors based on content type:

processor := factory.CreateProcessor(domain.MediaTypeVideo) // or MediaTypeAudio

Strategy Pattern

Interchangeable transcoding strategies for different output formats:

executor.AddStrategy(NewHLSTranscodeStrategy(profile1080p))
executor.AddStrategy(NewHLSTranscodeStrategy(profile720p))
executor.Execute(ctx, input, outputDir, cmdExecutor)

Worker Pool Pattern

Concurrent job processing with configurable parallelism:

worker := transcode.NewWorker(queue, service, concurrency, logger)
worker.Start(ctx)

πŸš€ Quick Start

Prerequisites

  • Go 1.22+
  • Docker & Docker Compose
  • FFMPEG (for local development)
  • AWS CLI (configured)

Local Development

# Clone repository
git clone https://github.com/ichbingautam/streaming-service.git
cd streaming-service

# Install dependencies
go mod download

# Start infrastructure (Redis + LocalStack)
docker-compose up -d redis localstack

# Run API server
make run-api

# Run transcoding worker (in another terminal)
make run-worker

Docker Compose (Full Stack)

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f api worker

πŸ“‘ API Endpoints

Method Endpoint Description
GET /health Health check
GET /ready Readiness probe
POST /api/v1/upload Upload media file (multipart)
POST /api/v1/upload/presign Get presigned upload URL
POST /api/v1/upload/{id}/confirm Confirm presigned upload
GET /api/v1/media List user's media
GET /api/v1/media/{id} Get media details
DELETE /api/v1/media/{id} Delete media
GET /api/v1/media/{id}/playback Get HLS playback URL

Example: Upload Video

curl -X POST http://localhost:8080/api/v1/upload \
  -H "X-User-ID: user123" \
  -F "file=@video.mp4" \
  -F "title=My Video" \
  -F "description=Sample video"

Example: Get Playback URL

curl http://localhost:8080/api/v1/media/{media_id}/playback \
  -H "X-User-ID: user123"

βš™οΈ Configuration

Configuration via config.yaml or environment variables (prefix: STREAM_):

app:
  name: streaming-service
  version: 1.0.0
  environment: production

server:
  port: 8080
  readtimeout: 30s
  writetimeout: 30s

aws:
  region: us-east-1
  s3rawbucket: streaming-raw-media
  s3processedbucket: streaming-processed-media
  dynamodbtable: video-metadata
  cloudfrontdomain: d1234.cloudfront.net

redis:
  host: redis
  port: 6379

ffmpeg:
  binarypath: ffmpeg
  segmentduration: 6
  profiles:
    - name: "1080p"
      width: 1920
      height: 1080
      videobitrate: "5000k"
      audiobitrate: "192k"

worker:
  concurrency: 4
  jobtimeout: 30m

log:
  level: info
  format: json

☸️ Kubernetes Deployment

Using Terraform

cd deployments/terraform

# Initialize Terraform
terraform init

# Review plan
terraform plan -var="environment=production"

# Apply infrastructure
terraform apply -var="environment=production"

Using kubectl

# Create namespace
kubectl create namespace streaming

# Apply manifests
kubectl apply -f deployments/kubernetes/ -n streaming

# Check deployment
kubectl get pods -n streaming

πŸ”§ Development

# Run tests
make test

# Run with coverage
make test-coverage

# Lint code
make lint

# Build binaries
make build

# Build Docker images
make docker-build

πŸ“Š Performance Targets

Metric Target
API Latency (p99) < 50ms
Transcode Time (1min video) < 60s
CDN Cache Hit Ratio > 95%
Concurrent Streams 100M+

πŸ› οΈ Technology Stack

Component Technology
Language Go 1.22+
HTTP Router Chi
Configuration Viper
Logging Zap
Media Processing FFMPEG
Storage AWS S3
Metadata AWS DynamoDB
CDN AWS CloudFront
Queue Redis
Containers Docker
Orchestration Kubernetes
IaC Terraform

πŸ“„ License

MIT License - see LICENSE for details.

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing)
  5. Open Pull Request

About

A high-performance, production-ready video/audio streaming service built in Go, designed for 100M+ RPS with HLS adaptive bitrate streaming.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages