9

I have looked and played around with RavenDb for a while and have started to look at MultiTenancy. Ayendes sample for multitenancy looks like this:

using(var store = new DocumentStore
{
    Url = "http://localhost:8080"
}.Initialize())
{
    store.DatabaseCommands.EnsureDatabaseExists("Brisbane");

    store.DatabaseCommands.EnsureDatabaseExists("Melbroune");
    store.DatabaseCommands.EnsureDatabaseExists("Sidney");

    using (var documentSession = store.OpenSession("Brisbane"))
    {
        documentSession.Store(new { Name = "Ayende"});
        documentSession.SaveChanges();
    }
}

I don't know how each database is stored and hence the question: Will that work for large applications with a lot of tenants?

jgauffin
  • 99,844
  • 45
  • 235
  • 372
  • 3
    FYI - the 'EnsureDatabaseExists' will not work without a using directive for 'Raven.Client.Extensions'. I had a very hard time finding this information. – Jim Reineri Nov 09 '11 at 14:16

2 Answers2

11

See the first and last paragraphs from the docs (v2.5 | v3.0).

RavenDB's databases were designed with multi tenancy in mind, and are meant to support large number of databases on a single server. In order to do that, RavenDB will only keep the active databases open. If you access a database for the first time, that database will be opened and started, so the next request to that database wouldn't have to pay the cost of opening the database. But if a database hasn't been accessed for a while, RavenDB will cleanup all resources associated with the database and close it.

That allows RavenDB to manage large numbers of databases, because at any given time, only the active databases are actually taking resources.

So yes it will support it and each database will be stored in a separate folder on disk.

Community
  • 1
  • 1
Matt Warren
  • 10,279
  • 7
  • 48
  • 63
  • 1
    To expand on that, by default we store the tenants in the Tenants\TenantName folder, adjacent to the main database Data folder. – Ayende Rahien Sep 09 '11 at 17:41
1

There are 3 basic options of implementing multi-tenancy (plus hybrid combinations): enter image description here

All are good to go in RavenDB (the original question was about option #2). Of course, option #1 with fully isolated tenants is more secure but others are likely to become cheaper in the long run with option #3 being the most affordable out of the three (in the long run).

Check out these resources:

Alex Klaus
  • 8,168
  • 8
  • 71
  • 87