Maintained by Fadhila36
A high-performance, stateless, and resilient microservice for video and image compression. Built for Enterprise scale using Go, Redis, and S3.
- 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/zapwith traceablejob_id. - Security: API Key Authentication, Strict File Type Validation, and Rate Limiting.
- Graceful Shutdown: Ensures active jobs complete before server termination.
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
- Go 1.18+
- Redis (Running instance)
- FFmpeg (Installed on host)
- S3-Compatible Storage (AWS, Cloudflare R2, MinIO)
Copy .env.example to .env and configure your credentials.
cp .env.example .env# Install dependencies
go mod tidy
# Run server
go run main.godocker build -t gocompress .
docker run -p 3000:3000 --env-file .env gocompressSubmit 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"
}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.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project stands on the shoulders of giants. Special thanks to:
- Go Fiber - Web Framework
- Hibiken Asynq - Distributed Queue
- Uber Zap - Structured Logging
- AWS SDK v2 - Cloud Storage
- FFmpeg - Video Processing
Distributed under the MIT License. See LICENSE for more information.
© 2025 Fadhila36