Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using amazon s3 as storage for users profile pic. I see that many websites generates large random filenames and put them into the same root directory like:

And my question is: What are the pros and cons of that approach?

If I palce them into different directories, what problems I will have in future?



share|improve this question
I'm confused as to what you are trying to do here. – mdpc Sep 4 '12 at 19:29
I want to know if there is a difference storing each user pic in its own directory, or using random unique filenames and storing all imagem in a root directory. What are the pros and cons if it has – Luccas Sep 4 '12 at 22:31

As you are using S3, the amount of files should not be an issue. However, consider what happens when you need to lookup a single file manually.. Listing some gazillion files in your browser won't be fun.

So for this case, you should have some kind of "human browseable" tree structure, which final sub directories contain a reasonable amount of files.

I'd recommend either to expand and split the id (assuming it is numeric) or prefix-split the username.

ID example:

id1 = 123
id1_expanded = 000/000/000/123

id2 = 1000002
id2_expanded = 000/001/000/002

Username example:

username1 = luccas

username2 = ukautz

In any case, most of the strategies invented for storage structure design try to tackle issues which you simply don't have in S3: amount of files per directory, sharding across storage servers .. stuff like that.

Edit: The long file names you described are often chosen for "security" reasons -> as long as you don't use an algorithm to derive it from username + id or so, any relation between the file and a specific user is concealed (given only the file name). Again: use some kind of sub-directory strategy (for the reason argued above).

share|improve this answer

It depends upon how many images you are going to use. If your application uses millions of images you better cluster them on to another server just to load balance it. You can also divide the images based upon the type of user profile. Place all the user profile based on categories. At the end of the day all you need to know is how well your server is going to load balance the requests. This is just theoretical assumption. having the specification of hardware and amount of pictures would make sense.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.