A high-performance, secure, and cost-effective Go-based image resizing proxy designed to run on Google Cloud Run. It intercepts requests for resized images (e.g., image_128x128.jpg), resizes them on-the-fly from original images in Google Cloud Storage (GCS), and caches the result in-place in the same GCS bucket and via Cloud CDN.
graph TD
User([User / CDN Client]) -->|HTTP GET| CDN[Google Cloud CDN]
CDN -->|Cache Hit| User
CDN -->|Cache Miss| LB[External Application Load Balancer]
LB -->|Serverless NEG| CR[Cloud Run Service]
CR -->|Read / Write| GCS[(GCS Bucket: Original & Resized Images)]
- On-the-Fly Resizing: Automatically resizes images to supported square dimensions (
64,128,256,512). - Supported Formats: Handles
jpg,jpeg, andpngformats. - In-Place Caching: Resized images are saved back to the original GCS bucket under the requested path. Subsequent requests are served directly from GCS/CDN without invoking the resizing logic.
- Optimized for Cloud CDN: Seamlessly integrates with Google Cloud CDN to serve cached images at the edge, reducing latency and compute costs.
- Secure Distroless Container: Built using a multi-stage Docker build and runs on Google's minimal
distroless/staticimage, reducing the attack surface.
- Go 1.25+ installed locally.
- Google Cloud SDK (
gcloudCLI) installed and authenticated.
-
Authenticate your local machine to obtain Application Default Credentials (ADC):
gcloud auth application-default login
-
Run the Go application by specifying the target GCS bucket and your GCP project:
ORIGINAL_BUCKET="your-gcs-bucket-name" GOOGLE_CLOUD_PROJECT="your-gcp-project-id" go run .
-
Test it by opening your browser or using
curl:- Original image:
http://localhost:8080/image.jpg - Resized image:
http://localhost:8080/image_128x128.jpg
- Original image:
Run the unit tests to verify the parsing and resizing logic:
go test -v .A k6 load testing script is included in load-test.js to simulate realistic traffic (75% cache hits, 20% resizes, 5% 404s).
You can run it using Docker:
docker run --rm -i -e TARGET_HOST="http://<YOUR_LOAD_BALANCER_IP>" grafana/k6 run - <load-test.jsThe project includes an automated deployment script deploy.sh that:
- Enables necessary GCP APIs (Cloud Run, Cloud Build, Compute Engine, Artifact Registry).
- Creates an Artifact Registry repository.
- Builds and pushes the Docker container using Google Cloud Build.
- Provisions the GCS Bucket, Cloud Run service, Serverless NEG, Cloud CDN, and Load Balancer via Terraform.
Run the script by specifying your target GCP project ID:
GCP_PROJECT="your-gcp-project-id" ./deploy.shFor a detailed analysis of monthly costs at 100 Million requests per month (approximately $5.30 per million requests at a 95% CDN cache hit rate), see the cost_estimation.md file.