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
If creating dbs is so cheap, do you aim at creating task databases for some processes and delete them afterward?
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.
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.
@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?
How does this work with the REST API? Any idea how many people are using that rather than the C# client?
Shawn,
RavenDB works on Azure, yes.
Scooletz,
Yes, that one would be very easy to do, then.
You can create a database in memory, which would fit what you want
Chris,
I'll talk about this in my next post
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?
Tony,
I just fixed this bug, will be up in the new build
@Ayende
Thanks for that, does this fix also cover DeleteByIndex too?
Yes, it should
Comment preview