Skip to content

Scalable Go microservice for video/image compression. Powered by FFmpeg, Redis, and S3-compatible storage.

License

Notifications You must be signed in to change notification settings

Fadhila36/gocompress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Video Compression Microservice (Enterprise Edition)

Maintained by Fadhila36

A high-performance, stateless, and resilient microservice for video and image compression. Built for Enterprise scale using Go, Redis, and S3.

🌟 Features

  • Smart Compression: Automatically detects input bitrate using ffprobe. Skips compression if input is already optimized (< 1500k bitrate) to prevent quality loss.
  • Distributed Queue: Uses Redis (via Asynq) for reliable, persistent job queuing. Supports Dead Letter Queues and automatic Retries.
  • Stateless Architecture: Processed files are uploaded to S3 (AWS, R2, MinIO) with Private ACLs. Local storage is ephemeral and immediately cleaned up.
  • Secure Delivery: Webhooks deliver Presigned URLs (valid for 1 hour) instead of public links.
  • Observability: Production-grade structured logging using uber-go/zap with traceable job_id.
  • Security: API Key Authentication, Strict File Type Validation, and Rate Limiting.
  • Graceful Shutdown: Ensures active jobs complete before server termination.

🏗️ Architecture

graph TD
    Client[Client App] -->|POST /api/compress| API[Fiber API Gateway]
    API -->|Validation & Auth| API
    API -->|Enqueue Job| Redis[(Redis Queue)]
    
    Worker[Go Worker] -->|Pull Task| Redis
    Worker -->|Fetch File| Disk[Ephemeral Temp Storage]
    Worker -->|Run FFprobe/FFmpeg| Disk
    
    Worker -->|Upload Result| S3[(AWS S3 / R2)]
    S3 -->|Generate Presigned URL| Worker
    
    Worker -->|POST Result + URL| Webhook[Client Webhook]
    Worker -->|Cleanup| Disk
Loading

🚀 Prerequisites

  • Go 1.18+
  • Redis (Running instance)
  • FFmpeg (Installed on host)
  • S3-Compatible Storage (AWS, Cloudflare R2, MinIO)

🛠️ Setup & Run

1. Environment Configuration

Copy .env.example to .env and configure your credentials.

cp .env.example .env

2. Run Locally

# Install dependencies
go mod tidy

# Run server
go run main.go

3. Run with Docker

docker build -t gocompress .
docker run -p 3000:3000 --env-file .env gocompress

📡 API Documentation

POST /api/compress

Submit a video or image for compression.

Headers:

  • X-Secret-Key: <Your API_SECRET>

Body (multipart/form-data):

  • file: (Required) Video or Image file.
  • webhook_url: (Required) Endpoint to receive the callback.

Response (202 Accepted):

{
  "status": "queued",
  "job_id": "550e8400-e29b-41d4-a716-446655440000"
}

Webhook Payload

Sent to webhook_url upon completion.

{
  "job_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "success",
  "download_url": "https://bucket.s3.region.amazonaws.com/file.mp4?signature=...",
  "original_size": 10485760,
  "compressed_size": 4500000
}

Note: download_url is a secure Presigned URL valid for 1 hour.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📦 Open Source Libraries

This project stands on the shoulders of giants. Special thanks to:

📝 License

Distributed under the MIT License. See LICENSE for more information.


© 2025 Fadhila36

About

Scalable Go microservice for video/image compression. Powered by FFmpeg, Redis, and S3-compatible storage.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published