Skip to content

P4ST4S/go-image-optimizer

Repository files navigation

Go Image Optimizer Microservice 🚀

A high-performance microservice for image processing, designed to be resilient and lightweight. This project demonstrates Go's efficiency for CPU-bound tasks compared to Node.js.

Go Docker Size Build and Push GitHub release

⚡ Key Features

  • Native Image Processing: Decoding, resizing (Lanczos), and optimized JPEG encoding without heavy system dependencies.
  • Memory Protection (Semaphore Pattern): Uses buffered Go Channels to limit concurrency and prevent OOM (Out Of Memory) kills under heavy load.
  • Fail-Fast Architecture: Immediate rejection of excess requests (Status 503) to maintain low latency for active users.
  • Graceful Shutdown: OS signal handling (SIGTERM/SIGINT) to complete in-flight requests before container shutdown (Zero data loss).
  • Docker Multi-Stage Build: Static production binary weighing less than 20 MB.

🛠️ Installation & Setup

Via Docker (Recommended)

# Build the lightweight image
docker build -t go-optimizer .

# Run the container (Port 8080)
docker run -p 8080:8080 --name optimizer go-optimizer

Local Development

go mod download
go run .

🧪 Benchmark & Performance

Test performed with k6 (50 VUs, 2MB image uploads, 30s):

Metric Result
Throughput ~50 req/sec (CPU-bound)
Max Memory Stable at ~250MB (thanks to semaphore)
p95 Latency < 1.5s
Docker Image 21 MB

📐 Code Architecture

  • main.go: Entry point, server configuration and Graceful Shutdown handling.
  • handle_upload.go: Business logic and concurrency management (Semaphore).
  • Goroutines: Each request is handled in its own lightweight thread.

🔗 Author

Antoine Rospars - Portfolio - GitHub

About

A high-performance microservice for image processing, designed to be resilient and lightweight.

Topics

Resources

Stars

Watchers

Forks