Consider a social network in which a user photo is needed in different resolutions large/small/medium etc.
When the photo is uploaded, I do not want to make the user to wait too long for the image to be processed and the different urls for each size to be returned.
I want just to return the base url ex domain.com/images/something.jpg Then when the frontend calls for domain.com/images/something.jpg?s=large I generate the large image, cache it somwhere and always return that.
The problem that I cannot figure out with the above approach is that I cannot use s3 anymore without double transferring the data.
With the above aproach first I need to transfer the data from s3 -> backend server then from backend server -> frontend.
If I go withe the solution that I do not like, frontend waits longer for backend to generate all image sizes and return all urls, then only one transfer need to be done, from s3 to frontend.
I also thought of another possible solution that backend returns urls withhout the image being avaible, for example:
[ large: domain.com/dd.jpg?s=large small: domain.com/dd.jpg?s=small ]
Then when the frontend calls for example the small url, if it does not exist first is generated, then stored in s3 then backend returns 302 redirect to the s3 url. I think that this approach will be bad because of many 302 redirects, but offers the flexibility that I want.
I am still trying to figure out how to solve the problem. Any suggestions please ?