I'd like to create a service to serve several hundred thousand smaller files (from 5kb to 500kb, mostly around 10-100kb). Think of it as a kind of gravatar.com which serves those little avatar pics on URLs like https://secure.gravatar.com/avatar/1545f91437e2576b910dbd1023a44756
I want to use a descriptive URL without any IDs or hashes, for example like http://www.server.com/This-is-my-file.ext, There are no duplicate file names.
What would be the most efficient way to serve and organize the files with not much overhead?
Just putting everything in one directory and let nginx serve the files will slow down after a certain amount of files depending on the file system.
One idea is to save the files in a simple directory structure based on the first characters of the filename, so the example would be served from T/h/This-is-my-file.ext with a simple rewrite rule in the nginx config. This would result in a very uneven distribution into the different directories. Using values from lets say a md5 hash of the filename would result in a good distribution but require more computing power...
I guess this sounds like a perfect use case for a key value store but isn't it possible with just the file system and nginx to keep it simple?