Considerations before moving from RDBMS to MongoDB
There are a variety of reasons for moving from a relational database (RDBMS) to MongoDB. Perhaps,
like FamilySearch
, the family history division of The Church of Jesus Christ of Latter-day Saints, a company wants to improve response times from 3 seconds (RDBMS) to under 15 milliseconds (MongoDB). Or perhaps,
like Apollo Group
(PDF), the private education giant behind University of Phoenix, an enterprise is hoping to store unstructured data and scale to support anticipated growth in the number of users and volume of your content.
Whatever the reason for moving off a relational database for MongoDB, it’s important to plan appropriately.
In my role I get to work directly with MongoDB users
like Telefonica
, nearly all of which come from a relational database background. Sometimes when people are fed up with using SQL, or they see MongoDB as a way to scale, they decide to migrate an application designed for a relational database directly to MongoDB…without rethinking the data model and architecture of their application. There are
good ways to map SQL executables to MongoDB
, but this isn’t one of them.
Another error-prone migration “strategy” is driven by the blind usage of Object Document Mappers (ODM) and Object Relational Mappers (ORM) that shield a lot of the complexity of manipulating a database, but can also contribute to poor data model design.
So when considering a direct migration from RDBMS to MongoDB, it’s important to be attentive to some issues:
Too many collections (10+) - This will lead to poor performance and questions like ...How can I do a join in Mongo?“ (Answer: you can’t, but there are
ways to accomplish the same thing
in MongoDB)
Many indexes - indexing all the fields in a document is a bad approach and leads to bad insert performance. I've seen cases where, for a given database, customers end up with more space occupied by indexes then data. This is not a good practice anywhere.
The first question to ask, then, when moving from a relational database to MongoDB is, ‘How will this data be accessed?’ Other important questions include:
What is the access pattern?
What are you hoping to show to your customers/users?
How are you going to write this data?
These should be the first questions people ask themselves before migrating data from an RDBMS into MongoDB. Indeed, these should be the main questions someone should be asking before using any persistence layer. As stated, there are a lot of great reasons to use MongoDB instead of a relational database, but careful planning is required to pull off a successful migration.
Posted by Norberto Leite, Senior Solutions Architect for EMEA, 10gen.
Tagged with: rdbms, MongoDB, ORM, ODM, migration
January 15, 2013