Job Creation
POST /api/v1/jobs/image/*POST /api/v1/jobs/video/*POST /api/v1/jobs/audio/*POST /api/v1/jobs/batch
Mend is a distributed media processing engine built with Go, designed for high-throughput asynchronous processing of images, videos, and audio files stored in S3-compatible storage.
┌─────────────────────────────────────────────────────────────────┐│ Client Layer ││ (HTTP Clients, Web Apps, Mobile Apps, CLI Tools) │└────────────────────────────┬────────────────────────────────────┘ │ │ HTTP/REST ▼┌─────────────────────────────────────────────────────────────────┐│ API Server (Gin) ││ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ││ │ Routes │ │ Handlers │ │ Middleware │ ││ │ /api/v1/* │ │ - Jobs │ │ - Auth │ ││ │ /health │ │ - Health │ │ - Logger │ ││ │ /metrics │ │ - Batch │ │ - CORS │ ││ └──────────────┘ └──────────────┘ └──────────────┘ │└────────────────────────────┬────────────────────────────────────┘ │ │ Enqueue Jobs ▼┌─────────────────────────────────────────────────────────────────┐│ Redis (Asynq Queue) ││ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ││ │ image queue │ │ video queue │ │ audio queue │ ││ │ Priority: 5 │ │ Priority: 3 │ │ Priority: 2 │ ││ └──────────────┘ └──────────────┘ └──────────────┘ │└────────────────────────────┬────────────────────────────────────┘ │ │ Dequeue Jobs ▼┌─────────────────────────────────────────────────────────────────┐│ Worker Pool (Asynq) ││ ┌────────────────────────────────────────────────────────────┐ ││ │ Worker 1 │ Worker 2 │ Worker 3 │ ... │ Worker N │ ││ └────────────────────────────────────────────────────────────┘ ││ ││ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ││ │ Image │ │ Video │ │ Audio │ ││ │ Processor │ │ Processor │ │ Processor │ ││ │ - Resize │ │ - Thumbnail │ │ - Convert │ ││ │ - Optimize │ │ - Extract │ │ - Compress │ ││ │ - Convert │ │ (FFmpeg) │ │ (FFmpeg) │ ││ └──────────────┘ └──────────────┘ └──────────────┘ │└────────────────────────────┬────────────────────────────────────┘ │ │ Upload/Download ▼┌─────────────────────────────────────────────────────────────────┐│ S3 Storage (AWS S3 / MinIO) ││ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ││ │ Images │ │ Videos │ │ Audio │ ││ │ Bucket │ │ Bucket │ │ Bucket │ ││ └──────────────┘ └──────────────┘ └──────────────┘ │└─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐│ Observability Layer ││ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ││ │ Prometheus │ │ Structured │ │ Health │ ││ │ Metrics │ │ Logs │ │ Checks │ ││ │ /metrics │ │ (Zap/JSON) │ │ /health │ ││ └──────────────┘ └──────────────┘ └──────────────┘ │└─────────────────────────────────────────────────────────────────┘Responsibilities:
Key Endpoints:
Job Creation
POST /api/v1/jobs/image/*POST /api/v1/jobs/video/*POST /api/v1/jobs/audio/*POST /api/v1/jobs/batchJob Management
GET /api/v1/jobs/:idGET /api/v1/jobs/:id/streamGET /api/v1/jobsMonitoring
GET /healthGET /metricsGET /api/v1/queue/statsScaling: Horizontal (multiple instances behind load balancer)
Responsibilities:
Queue Configuration:
| Queue | Priority | Use Case |
|---|---|---|
image | 5 | Image processing (highest) |
video | 3 | Video processing (medium) |
audio | 2 | Audio processing (low) |
default | 1 | Other tasks (lowest) |
Features:
Responsibilities:
Concurrency: Configurable (default: 10 workers per instance)
Processing Flow:
1. Dequeue job from Redis2. Create temporary directory3. Download source file from S34. Process file (image/video/audio)5. Upload result to S36. Update job status7. Send webhooks (if configured)8. Clean up temp filesWorker Types:
Technology: Go image libraries + ImageMagick
Operations:
Technology: FFmpeg
Operations:
Technology: FFmpeg
Operations:
Responsibilities:
Supported Providers:
Configuration:
s3: region: us-east-1 access_key_id: "${AWS_ACCESS_KEY_ID}" secret_access_key: "${AWS_SECRET_ACCESS_KEY}" # Optional: for non-AWS providers endpoint: "https://s3.example.com" use_path_style: trueBenefits:
Flow:
Client → API (202 Accepted + Job ID) ↓ Redis Queue ↓ Worker (processes job) ↓ Update status in Redis ↓ Send webhook notification1. Pending
Job is queued, waiting for a worker
Duration: Seconds to minutes
2. Processing
Worker is actively processing
Duration: Seconds to minutes
3. Completed
Job finished successfully
Result: Output file in S3
4. Failed
Job encountered an error
Retry: Up to 3 attempts
Retry Strategy:
Failure Scenarios:
Structured Logging:
{ "level": "info", "timestamp": "2025-10-18T22:00:00Z", "job_id": "550e8400", "type": "image_resize", "duration_ms": 1234, "message": "Job completed successfully"}Metrics:
Health Checks:
API Servers
Stateless design allows unlimited API instances
Workers
Independent workers process jobs in parallel
Redis
Redis clustering for high availability
| Component | Throughput | Latency | Bottleneck |
|---|---|---|---|
| API | 10k+ req/s | < 10ms | Network |
| Redis | 100k+ ops/s | < 1ms | Memory |
| Workers | Varies | 1-60s | CPU/FFmpeg |
| S3 | Unlimited | 50-200ms | Network |
Small Deployment (< 1000 jobs/day):
Medium Deployment (1k-100k jobs/day):
Large Deployment (> 100k jobs/day):
Backend
Go 1.21+
Web Framework
Gin
Queue
Asynq
Media Processing
FFmpeg
Deploy
Follow the Deployment Guide
Monitor
Set up Metrics & Monitoring
Optimize
Learn about performance tuning