Different options for hosting RavenDB

Wednesday 05 December 2012

In the previous blog posts about RavenDB I used the Raven.Server.exe to create a database server. Just running raven.Server.exe and connecting to it is fine for development but certainly not our only option.


Running RavenDB as a Windows Service

Once you have the RavenDB.Server NuGet package you can install it as a Windows Service. This means it is always available and running whenever you need it. Certainly a nice and simple way of using RavenDB if you do so more often.


Installing is easy, just run Raven.Server.exe /install and it installs.



Running as an IIS application

Another option for hosting RavenDB is creating an IIS application and letting IIS take care of things. There is a little bit more work to it and I consider it more of a deployment option but its a great way of hosting RavenDB in production.


Running RavenDB in embedded mode

Yet one more option is running RavenDB in embedded mode. This is a great option if you don’t want to, or can’t, deploy an extra IIS application. A number of my websites run on a budget hosting infrastructure that make it harder to deploy extra IIS applications. Deploying to Azure Web Sites is another of those places where embedded mode is really useful.

As the client also contains the server the setup and capabilities are a little different. The most obvious difference is using the RavenDB.Embedded NuGet package and the EmbeddableDocumentStore class. The initialization code in the Global.asax now looks like this:

   1: public static DocumentStore DocumentStore { get; private set; }
   3: private void CreateRavenDB()
   4: {
   5:     DocumentStore = new EmbeddableDocumentStore()
   6:     {
   7:         ConnectionStringName = "ravenDB"
   8:     };
   9:     DocumentStore.Initialize();
  10: }


And in the web.config we need the following configuration:

   1: <connectionStrings>
   2:   <add name="ravenDB"
   3:        connectionString="DataDir = ~\App_Data\RavenDB"/>
   4: </connectionStrings>

In this case the RavenDB folder inside the special App_Data folder is where all data is stored.

One thing to keep in mind is that this package uses the original 4.0.8 version of Newtonsoft.Json making it difficult to use with some of the newer releases of the ASP.NET team that ship with Newtonsoft.Json version 4.5.6. The upcoming RavenDB 2.0 should take care of that.



There are quite a few options when it comes to hosting RavenDB. Just choose whatever works best for your situation. In most business application I would opt for hosting as an IIS application if possible and otherwise as a Windows Service. When running on budget web hosting environment or other special cases the embedded option is really nice.