Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

http://xxx.us-east-1.amazonaws.com/aHR0cHM6Ly9mYmNkbi1wcm9maWxlLWEuYWthbWFpaGQubmV0L2hwcm9maWxlLWFrLWFzaDIvMjczMzkxXzEwMDAwMDMxMjAxMzg5OV81NTk3MjM4Mzdfbi5qcGc.jpg

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?

http://xxx.us-east-1.amazonaws.com/users/id/username.jpg

or

http://xxx.us-east-1.amazonaws.com/users/id/random_number.jpg

Thanks!

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
add comment

2 Answers

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
http://xxx.us-east-1.amazonaws.com/users/000/000/000/123/username.jpg

id2 = 1000002
id2_expanded = 000/001/000/002
http://xxx.us-east-1.amazonaws.com/users/000/001/000/002/username.jpg

Username example:

username1 = luccas
http://xxx.us-east-1.amazonaws.com/users/l/lu/luc/luccas/random_number.jpg

username2 = ukautz
http://xxx.us-east-1.amazonaws.com/users/u/uk/uka/ukautz/random_number.jpg

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
add comment

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
add comment

Your Answer

 
discard

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.