Search code examples
nosqlravendbdocument-database

Should we denormalize data in a Document to improve performance? (Document Database)


In my system Employees log Requests and Requests are about an Equipment.

In order to avoid loading the Employee and Equipment documents each time I need to display a Request I want to denormalize the employee name and the equipment inventory number, manufacturer name and model in the Request document.

I’m I on the wrong track here? Is this an antipattern?

I realize that if I do that then I’ll have to update all affected Request documents in the very rare case that an employee’s name changes or an equipment’s inventory number changes.


PS: Links to Document Database Modeling Guidelines would be appreciated as well.


Solution

  • Sly, this really depends on your required level of speed. If you just have one database without sharding and you're ok with very fast performance, then don't denormalize and use .Include for the sake of simplicity. However, they don't work on sharded sessions, so you might want to go for denormalization then and have lightning performance.

    My very personal opinion is that you should always go with .Include unless you have a really good reason not to use it.