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

On my website, users have files so I create a folder for each user when they register.

for example


If site grows and I have thousands of users I might end up having too many user folders in one folder so i decided to split them up.

for example

/userdata/1/USERID (first thousand users)

/userdata/2/USERID (second thousand users)

My questions is how much folders should I put in one subfolder? Is 1000 in each a good idea? more? less? Just want to make sure things run smoothly.

share|improve this question

migrated from May 14 '11 at 11:49

This question came from our site for professional and enthusiast programmers.

The answer to that depends entirely on the operating system & filesystem that your web host is using. – jayp May 13 '11 at 16:17
up vote 2 down vote accepted

I always work to the rule of going for a maximum of ~1000 with ext2/ext3. I suspect that the choice of filesystem might affect your choice.

The absolute limit in ext3 is ~32k. Have a look for all of the gory details on Wikipedia:

In terms of a hashing algorithm for your directories I'd recommend using the last digit of the id. If you calculate $id % 10 and use that value it'll work a treat. That way you get an even distribution out of the box.

share|improve this answer
@James C, Can you please explain what hashing would be used for in this case? I'm not sure I understand. – user80666 May 13 '11 at 16:26
"hashing" as in which user to store in which directory. I'm recommending that it'd look like 5/1234, 5/2345, 1/102, etc – James C May 13 '11 at 16:39

It depends mostly on the file system you are using.

You'll probably find it easier to use a pattern rather then splitting on arbitrary numbers. CPAN, for instance, uses


i.e. first letter / first two letters / full username

share|improve this answer
Thanks for advice. On my site usernames can be changed, I would prefer not to have to move folders around so CPAN's approach may not be suitable for me. – user80666 May 13 '11 at 16:25
@user, I'd highly recommend using the CPAN approach, or first_letter/second_letter/[etc]/full and just accept that you'll have to move a directory now and then. – Chris S May 14 '11 at 13:43
moving folders in the same file system is just shifting the folder entry; you don't actually move any data – mpez0 May 14 '11 at 15:38

If your usernames change infrequently, the CPAN mindset might still have an advantage. It's generally better to know for 90% of users where to drill down and find their content than to have to search N file structures looking for USERID.

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.