Serving static images - sokanu/frame GitHub Wiki
We have a couple of options
- Serve on-demand
We could store the original copy in the destination folder. When users demand a version, we download the image and serve it from the frame instance. If the image needs to be modified, it is done during that request and the output is served. A caching layer will store the result of the image and serve it instantly if the image is re-requested
This has a lot of issues: cache will balloon really quickly, the initial request will require downloading the image onto the server and then serving it again. If you serve a ton of different files and they only get requested once or twice, this will probably be the quickest though.
- Redirect to stored version
When a user requests an image, we look up the globally accessible location and redirect the browser to it. If an image requires modification, things get more complicated: we download the image, make the changes, upload the changed version, store the location and variation in the database, and redirect the user to the changed version. The cache stores the request type and redirect url, so any subsequent requests will no longer require any work. This will use a lot more space and will make the initial variation requests slower. It will allow the cache to store way more redirection information, so there will be fewer hits on the server. It will offset the work of serving the images to the content server (S3 or some local server). We could add a functionality to generate a few common user-defined variations on images as they are uploaded and pre-cache those results in the cache server, so with the right cache size we could minimize the server's work to nearly zero. I think this is the approach that I will try to take.