0

I have written a PHP application with CodeIgniter. I plan to sell it as a hosted application (Software as a service).

The apps allow users to:

  • create accounts
  • create users
  • manage files
  • manage orders
  • have an address book
  • searching
  • reports and so on. It is using one database. The best example is Fresh Books. (It is not my competitor anyway.)

My question is:

What is the best configuration for a hosted application? Keep in mind that the application can grow to couple of thousands of users.

The actual configuration is:

  1. One place for the code example.com/appfolder
  2. Users will create accounts on example.com
  3. On user accounts there is a link for each user to use the app

user1.example.com

user2.example.com

.................

All subdomains point to the same example.com/appfolder

  1. example.com have a database that keep records on users and their monthly payments
  2. The application is hosted on example.com/appfolder and based on the url is selecting for each user a separate database.

All looks fine for 100, 200, 300 users but if I will have 1000 or 2000 users i will have to manage and backup 1000 or 2000 databases (3-5MB each)

I know I should have a single database for all users but this will make it very hard to manage and there is sensitive data on user databases.

And most important, users can create users that can use the same application but only on the subdomain where they were created by the admin user (which signup on exmaple.com)

Can this configuration crash a dedicated server with over 2000 admin users (which means 2000 db)?

Basic is very similar to a CMS but more specialized.

There are more practical ways to do this configuration?

Any suggestions will be greatly appreciated. Many thanks in advance.

Adrian P.
  • 5,060
  • 2
  • 46
  • 47
  • These 2000 users create users and all create other content. So, it's about million records. I know a relational DB can manage that. My question was about the configuration. The 2000 databases. Disk I/O and so on. If you ca be constructive it's OK if not just don't say it. Thanks. – Adrian P. Feb 23 '13 at 06:22
  • Are you looking for something like [subdomain rewrite](http://stackoverflow.com/questions/4193651/simple-htaccess-subdomain-rewrite)? So user1.example.com is taken to `example.com/app?user=user1`? – bobthyasian Feb 23 '13 at 06:28
  • @bobthyasian: Nope. I already did that. I'm interested in the best configuration possible for my hosted app. Thanks. – Adrian P. Feb 23 '13 at 06:32
  • How a single database is less secure than thousands of database? Moreover same datas will be repeated again and again. – itachi Feb 23 '13 at 06:47
  • @itachi I should delete the whole question? I know there is a lot to read but, please, read all info not just look at one thing and vote down! It's the easiest thing to do when you don't know the answer. I changed that phrase. Please look globally at the question. Thanks. – Adrian P. Feb 23 '13 at 06:50
  • Who voted down? I didn't even vote! – itachi Feb 23 '13 at 06:51
  • Anyway, when I put a theoretical question everybody vote down. It looks like I have to put only simple and practical questions in less than 200 words if possible. @itachi Sorry if I made a mistake. I was under impression you voted down the question. But let's discuss the question not the voting. – Adrian P. Feb 23 '13 at 06:55
  • 2
    Your question is difficult to answer due to one issue. You are creating a chain. That's ok. But we don't know how much pieces are there in the chain between the ends. E.g. A user can be active in only one sub domain and that too checked by admin. So how much payments will be made per minutes or hour? How much load it will put on the database server? You have to talk in numbers and giving the actual codes of how you implemented it because from theory, it is impossible to say. 1 advice i'l give you. Codeigniter is not suitable for this. Go with laravel for more modular structure. – itachi Feb 23 '13 at 07:06
  • 1
    One database per user certainly seems wrong. You're just shifting the "difficult to manage" piece around; as you say 2000+ separate databases aren't easy to manage either. You need to keep it all in one database with clearly related data and appropriate queries. Having said that, I have not enough insight into your app to make such assertions. – deceze Feb 23 '13 at 08:07
  • Thanks deceze. You're right. – Adrian P. Feb 23 '13 at 08:47

1 Answers1

1

A Single database or a sharded database (http://www.codefutures.com/database-sharding/ ) storing data for all your users is faster, easier to maintain, less cumbersome and all round better than 2000 databases.

Write the code you need to to manage your security or you'll be kicking yourself later when you are trying to wrestle with updating 2000 databases with a small schema change.

My suggestion would be to go with a single domain (no subdomains) and once you have 2000 users you will have the money and resources to improve.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
  • Thanks for advices. I accepted your answer. Very interesting the sharded db concept but not very cost wise. I will go with one domain and one db. Thanks a lot. – Adrian P. Feb 23 '13 at 08:42