Image Resizing Architecture at

The Problem

Plus Storage cost of 100TB data in S3 (More than the salary of a good software developer in India :))

Lazy Load

Ever Heard of Aws Lambda?. I feel Aws Lambda is the uber of computation industry. No maintenance of servers, no memory leak issues. It just feels like magic. Amazon took it a step further, they introduced LambdaEdge in November last year. Aws LambdaEdge is basically Aws lambda replicated in every edge location (which can be triggered on cloud front request).


The Solution

Webp checker — This lambda is responsible for determining whether the browser (Only google chrome accepts webp images) is accepting WEBP images from request headers
2. One-time Image Resizer — When an image is uploaded to s3 we convert this image to a standard 1500*1500 image and move the originally uploaded image to amazon glacier
3. Run-Time Image Resizer — When the request misses CloudFront cache, this lambda converts the standard image present on s3 to requested image and stores it in the CloudFront cache.

The Glacier (this one is not melting)

Request flow
We store all the configurations(height, width, watermark, crop, white space shrinking etc.) of an image in the database and keep one copy of it in s3 document, after every creation or updating of configuration we update the s3 file.
The request first comes to webp checker it appends .webp extension on the basis of request headers. If CloudFront has an image with this URL it returns the image otherwise request goes to Run-Time Image Resizer it fetches the standard image from s3 and configuration from s3 document, by looking at the extension of URL (webp images will have URL like .jpg.webp) it converts the image and stores it in the CloudFront cache

Useful links:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shubham Kukreja

Rails Developer, Traveller, Dev ops enthusiast, like to swim and read once in a while