views:

86

answers:

2

Hi everyone!
I'm planing to create an accounting application in asp.net mvc.
Each user will pay monthly subscription, I'll provide daily backups, etc.

I don't know which strategy to choose:

  1. To use SQL CE4 and run application in separate virtual directory for each user.
  2. To put everything in a single SQL Server database

What are cons and pros of these two options?
If I choose option 2, I'll have to write more logic inside code. I must prevent users from seeing things they should not see (more trips to database).

The two most important things are:

  1. General performance of the system
  2. Ability to easily create backups for separate users.

I expect between 20 and 30 users.

Any suggestion will be appreciated.

+3  A: 

I'd go for option 2 as always. I come from an intense financial integration background so option 2 (to me at least) is best.

There are no con's when considering the use of data. There are no more round trips than there would be with option 1.

Performance of the system is generally left up to the programmer. If you write shitty code you can expect terrible performance. Option 2 provides the easiest backup option as you only have to worry about 1 database. There's no need to consider that for separate users at all if you go with 1 database.

RE: the round trip's for users (or more "logic" in your code to handle that), how hard is it to add "Where userID = x" ?

You should be separating your .net code with stored procedures anyway so writing from the ground up shouldn't have anymore (or even less) round trips/file access issues than you would have with option 1.

AcidRaZor
+1 Yes, with an extra 'Where userID = X' in each query I'll reduce round trips. Thank you.
šljaker
@šljaker In order to enforce this and avoid accidentally leaving the tenant ID off in some queries, you can wrap your base tables with inline table valued functions which require a tenant ID to be supplied every time. Overhead of an ITVF is similar to a view (i.e. minimal) and the optimizer can work with them very easily.
Cade Roux
@Cade Roux, can you show me any sample? Tnx
šljaker
@šljaker Wrap every table with a TVF: CREATE FUNCTION fTABLENAME (@TenantID int) RETURNS TABLE AS RETUEN (SELECT * FROM TABLENAME WHERE TenantID = @TenantID). Then only use the functions: SELECT * FROM fCust(@TentantID) AS c INNER JOIN Accounts(@TenantID) AS a ON a.CustID = c.CustID
Cade Roux
I'd recommend against this as the overhead of a "view" would get huge if designed improperly. The idea is to get FEWER round trips, yet in this case you're creating MORE. If you want to have your application grow without the need to upgrade hardware or re-do programming, just do it "right" from the start by adding userID= where its needed. I'm currently doing an application that has both users and companies (user linked to company) and because I designed it right from the start to handle more than 1 company and their users, I can just add new companies without wondering if my code will hold up
AcidRaZor
A: 

You are probably not going to realistically be able to use SQL Server's backup feature if you go for a multi-tenant design in a single database, because the unit of backup is not going to be fine enough to back up each user's data individually. You can use partitions and filegroups and backup only filegroups, but the partition feature is not exactly easy to administer, and would probably not be good for this purpose.

If you are expecting to use SQL Server's backup and restore capability independently for users (which it sounds like from your comment), you probably need to have them in separate databases.

Having said that, I would re-think that requirement (think about implementing selective export/import), because a multi-tenant architecture is a lot easier to deal with overall.

Cade Roux
Backup is one of my main problems :(
šljaker
@šljaker It depends what your backup scenarios are - if it's for restoring data due to hardware failure as a service provider (you), it's probably fine, but if you want users to be able to backup restore on their own or be able to take that backup and restore it locally, SQL Server backup is probably not going to work for that.
Cade Roux