We're developing an ASP.NET MVC 3 website to be deployed on AppHarbor. The site will have at least 10,000 products on it. The user can search for products based on a tagging system (eg search for "color=blue" plus "size=10" plus "category=whatever"). So this system will be heavy on th开发者_开发知识库e db reads and light on the writes, and one of our main concerns is to keep the search feature blisteringly fast. To this end we'd also like to incorporate some caching of results.
Are we right or wrong in thinking this a good use case for using a NoSQL database (we've been looking at MongoDB, to be hosted on https://mongohq.com)?
If we do use MongoDB, what caching strategies should we look into?
Cheers!
MongoDB is great for tagging because of it's multikeys functionality
e.g. suppose you create your product documents like this
{
_id : 1,
name : "Widget",
tags: [
{color : "blue"},
{size : 10},
{foo : "bar"}
]
}
You can then create an index on the tags array and each item will be indexed. So, to find all products that are blue, you could query like this:
db.Products.find({tags : {color : "blue"}});
The great thing about this is every item can have a completely different set of tag "attributes" and queries will be able to use the index - some might have color and size, others might have weight and height.
With regard to caching, in MongoDB it's important to have enough RAM to be able to keep your working set in memory (enough for all the accessed data and indexes to be held). This way, data will remain in memory making queries very quick. So you may not need a caching technology on the top.
While MongoDB will do what you are looking for, I would seriously consider looking into Lucene or Solr which are inherently better at doing searching. There are very powerful searching features that they provide, like faceted searching and "Did you mean ..." type of functionality, that MongoDB doesnt do and likely never will.
You may not need that kind of functionality today, but take a minute to think about whether or not that is something you may need in the future.
精彩评论