Ayende @ Rahien

It's a girl

RavenDB Multi Tenancy

Originally posted at 11/27/2010

One of the features that people asked for RavenDB is the notion of multi tenancy. The idea is that I can (easily) create a new database (there is the RavenDB Server, and the server contains Databases, which contain indexes and documents) for each tenant. As you can imagine from the feature name, while it is actually an implementation of several databases on the same server, the usage goal is to have this for different tenants. As such, the RavenDB implementation is aimed to handle that exact scenario.

As such, it is expected that some users will have hundreds / thousands of databases on a single instance (think shared hosting or hosted raven). In order to support this, we need to have a good handle on our resources.

RavenDB handles this scenario by loading databases on demand, and unloading them again when they aren’t used for a long enough period. Using this approach, the only databases that consume resources are the ones actually being used.

In order to use the multi tenancy features, all you need to do is call:

documentStore.DatabaseCommands.EnsureDatabaseExists("Northwind");

var northwindSession = documentStore.OpenSession("Northwind");

You can now work in a separate database from all other databases, with no potential for data to leak from one tenant to another. Creating a database on the fly s a very cheap operation, as well, so you can create as many of them as you want.

Comments

Scooletz
11/29/2010 12:28 PM by
Scooletz

If creating dbs is so cheap, do you aim at creating task databases for some processes and delete them afterward?

Ayende Rahien
11/29/2010 12:30 PM by
Ayende Rahien

Scooletz,

Can you give me a good idea about what you want exactly?

Please note that there is no facility to delete a database. You can make it inaccessible, but not delete it.

Shawn
11/29/2010 01:42 PM by
Shawn

I looked but couldn't find any mention elsewhere -- I realize that this competes to an extent with Table Storage, but do you have any plans for this to be hostable as an Azure Worker Role? You might be able to use a CloudDrive for your persistent storage, but I'm not sure about performance.

Scooletz
11/29/2010 04:04 PM by
Scooletz

@Ayende,

what I meant was using so-called temporary Raven db as a source for running Map/Reduces after filling it with data. With temporary, in-memory indexes feature in mind, it seems to allow you to easy work with that kind of task, doesn't? Am I missing sth?

Chris Wright
11/29/2010 04:28 PM by
Chris Wright

How does this work with the REST API? Any idea how many people are using that rather than the C# client?

Ayende Rahien
11/29/2010 05:20 PM by
Ayende Rahien

Shawn,

RavenDB works on Azure, yes.

Ayende Rahien
11/29/2010 05:21 PM by
Ayende Rahien

Scooletz,

Yes, that one would be very easy to do, then.

You can create a database in memory, which would fit what you want

Ayende Rahien
11/29/2010 05:21 PM by
Ayende Rahien

Chris,

I'll talk about this in my next post

Tony
12/15/2010 02:48 PM by
Tony

Is it possible to create indexes in only one database? At the moment i use the following code to create indexes:

IndexCreation.CreateIndexes(typeof(My_Index).Assembly, container.Resolve <idocumentstore());

is this method of creating indexes obsolete/bad practice?

Ayende Rahien
12/15/2010 02:50 PM by
Ayende Rahien

Tony,

I just fixed this bug, will be up in the new build

Tony
12/15/2010 08:51 PM by
Tony

@Ayende

Thanks for that, does this fix also cover DeleteByIndex too?

Comments have been closed on this topic.