I’m starting to develop a new application. Can’t say what it is, but it perfectly fits MongoDB Document Oriented Database approach. Everything is great. except of small detail – I don’t want to store everything in one database. Of course I could use collections and embedded documents to organize whole nested structures and keep users stuff separated, although it would make source code much more complicated than it should be. Instead I’ve decided to use one MongoDB database per user. That way I can separate users data and I don’t need to worry about scoping it out. There will be a gateway, that will authorize incoming requests to a proper database.

Gateway

Schema is pretty straightforward and the only thing that was bothering me was the multi-db switching performance. I’ve decided to make a simple benchmark that would test if there’s a difference when using one or many databases. Results are promising. It seems, that there’s only around 5% (5.3% exactly) performance loss when using many databases instead of one. 5% is a difference level that I can easily accept. To be honest I think, I will gain much more especially when I will have a lot of data. Lets say I have 100 customers with 100 000 000 records. With one database I would have to query all of it. With separate databases, I will have to query only 1% of it.

Below you can see performance difference when querying one vs many MongoDB databases.

Dbs I will definitely go with that approach and I will try to keep you posted.

Note: This is not a full-pro-extremely accurate long-time test – more like a proof of concept. Keep that in mind ;)