Scenario
Users can post an item and include up to 5 images with the post, each image that's uploaded needs to be resampled and resized - a total of 4 extra images are created. Meaning if the user uploads 5 images end up with 25 images total to store.
Assumptions
- The images have been properly checked and they're valid image files
- The system has to scale (let's assume 1000 posts in the first instance, so maximum 5000 images)
- Each image is renamed in relation to the auto_incremenet id of the db post entry and includes relevant suffix i.e. 12345_1_1.jpg 12345_2_1.jpg - so there's no issues with duplicates
- The images aren't of a sensitive nature, so there's no issues with having them directly accessible (although directory listing would be disabled)
Possible approaches
- Given the ids are unique we could just drop them into one folder (ineffecient after a certain point).
- Could create a folder for each post and place all the images into that, so ROOT/images/12345 (again, would end up with a multitude of folders)
- Could do an image store based on date, i.e. each day a new folder is created and the days images are stored in there.
- Could store the images based on the resized type, i.e. all the original files could be stored in one folder images/orig all the thumbnails in images/thumb (i think Gumtree uses an approach like this).
- Could allow X amount of files to be stored in one folder before creating another one.
Anyone have experience on the best practices / approaches when it comes to storing images scalably?
Note: I prememt someone will mention S3 - let's assume we want to keep the images locally for the time being.
Thanks for looking