@snowcone-app/resizer
v1.0.0
Published
Image resizing service using imgproxy
Readme
Resizer Service
The Resizer service is responsible for resizing images using imgproxy. It connects to the render-queue service via Redis Streams to get resize tasks.
Architecture
The service works with two key components:
- Redis Streams for task distribution
- imgproxy for actual image resizing
Task Processing Flow
- Resize tasks are published to a Redis Stream (
resize_stream) by other services - Multiple resizer instances join a consumer group (
resize_group) to read tasks in a round-robin fashion - Each instance processes its tasks and acknowledges completion
- If a task processing fails, it remains in the "pending" state and can be claimed by other instances
Features
- Horizontal Scaling: Multiple resizer instances can work together through Redis Streams consumer groups
- Fault Tolerance: If one instance fails, tasks are automatically redistributed
- Load Balancing: Tasks are distributed evenly across all resizer instances
- Retry Mechanism: Automatically claims failed tasks after a timeout period
Configuration
The service can be configured using environment variables:
| Variable | Description | Default |
| ---------------------- | ----------------------------------------------- | ----------------------- |
| IMGPROXY_URL | URL of the imgproxy service | http://localhost:8101 |
| MAX_CONCURRENT_TASKS | Maximum number of tasks to process concurrently | 3 |
| HEALTH_PORT | Port for the health check server | 8095 |
| REDIS_ADDR | Redis server address (host:port) | localhost:6379 |
| REDIS_PASSWORD | Redis password | "" (empty) |
| CONSUMER_ID | Optional unique ID for this consumer | Auto-generated |
Installation and Setup
Local Development
Install dependencies:
npm installMake sure Redis is running and accessible at your configured
REDIS_ADDRStart the service in development mode:
npm run dev
Docker Deployment
Build the Docker image:
npm run docker:buildRun the container:
docker run -p 8095:8095 --env-file .env -d snowcone-monorepo-resizer
Health Check
The service provides a health check endpoint at:
GET http://localhost:8095/healthzTask Queuing
Tasks are added to the Redis Stream by the render-queue service. The task format is:
{
"id": "resize_12345678",
"type": "resize",
"params": {
"params": {
"assetUrl": "https://example.com/image.jpg",
"maxWidth": 800,
"tempFileUrlForResizer": "https://example.com/temp-file.jpg"
},
"callbackUrl": "https://callback.example.com/endpoint"
}
}Monitoring
You can monitor the Redis Streams and consumer groups using Redis CLI:
# View tasks in the resize stream
redis-cli XRANGE resize_stream - + COUNT 10
# View consumer group info
redis-cli XINFO GROUPS resize_stream
# View pending tasks (not acknowledged)
redis-cli XPENDING resize_stream resize_group