Showing posts with label MongoDb. Show all posts
Showing posts with label MongoDb. Show all posts

Saturday, February 2, 2013

10gen's MongoDB course - it was great!


Recently, I took a free course, organized by the 10gen company(it is famous for MongoDb NoSQL data-store). It was a great course that covered many interesting aspects about MongoDb. There are was video lectures, regular homeworks, and the final exam. You need 65% grade to pass course. I, actually, got 100% and earned beautiful "M101: MongoDB for Developers" certificate:


Thank's very much to 10gen. They have not only created a great free product(MongoDb), but also help developers to learn it. 

Thursday, November 29, 2012

Hybrid CQRS implementation using MongoDb

Introduction to CQRS

Command and Query Responsibility Segregation(CQRS) is a pattern that suggests you to use different models to read and to write information.

In standard relational systems you have dilemma: use normalized database or denormalized database? In first case you get fine-designed database that is good for writing data, but has poor reading performance. In second case you get headache with your updates, but(if properly denormalized) you can get good reading performance.

So, CQRS suggests to use 2 different databases: one optimized for reading(denormalized) and another for writing(normalized). It is a very tempting way to designing systems. The only big problem with this solution is that you need somehow to sync you databases. You can create some sort of Denormalizer that would perform synchronization between your normalized and denormalized databases, after writings to your normalized database.

Is there a simpler solution?
I think there is one using NoSQL database(for example, MongoDb).

What is MongoDb?

MongoDb is a non-relational data store for JSON documents. More about MongoDb.
Big benefit of MongoDb is that it you can easily store\restore objects that you have inside your program to\from database. This help us much in our Hybrid CQRS implementation.

Hybrid CQRS implementation using MongoDb
All commands(write operations) go through Service layer where validators and other protective measures are applied. Querying(read operations) are allowed directly from Database to speed up process.

Since we use NoSQL database(MongoDb) it is not strictly necessary for us to use different databases for reading and writing. If we make proper design of our MongoDb database, it will be good for reading(due to structure of data storage) and no bad for writings(if we do not go too far with denormalization).

This CQRS implementation is applicable in cases when you want to use Domain-Driven design approach for your system Core, at the same time retaining the ability for fast data reading for your Web application.

Sunday, November 18, 2012

MongoDb for beginners


What is MongoDb?

MongoDb is a non-relational data store for JSON documents. By non-relational we mean that it does not store data in tables like relational databases does. It stores JSON documents.


What is JSON? JSON(JavaScript Object Notation) is a standard for representing data structures in a text-based human-readable form. JSON documents look like this:

{"Name" : "Bob"} 

This very simple JSON document has the key "Name" and the value "Bob". You can create more complex JSON documents with hierarchies:

{"Name" : "Bob", "Age" : 50, "Hobbies" : ["hockey", "football", "movies"], "Account" : {"Login" : "Bobby", "Password" : "12345"}}

JSON documents are stored within MongoDb collections(collections are analogous to tables in a relational database). It’s very useful when writing programs, because this type of data structures looks a lot closer to what you have inside your programs, than relational database does:
 class Person  
 {  
   public string Name;  
   public int Age;  
   public string[] Hobbies;  
   public AccountDetails Account;  
 }  
 class AccountDetails  
 {  
   public string Login;  
   public string Password;  
 }  

That’s new, because you never do that in relational table. The fact that MongoDb stores documents makes programming your domain model very convenient.

Schemaless 

Another interesting aspect about MongoDb is that it also schemaless. Schemaless means that two documents don’t need to have a same schema.

For example, you can store this documents inside the same collection:
{"a" : 1, "b" : 2}
{"a" : 1, "b" : 2, "c" : 3}

MongoDb vs Relational databases


The idea of MongoDb is to retain most of scalability and performance, giving you a lot of functionality to work with, but not quite as much as you can get in relational database management systems. 

That’s because there are few different things are missing in MongoDb:
  • Joins. MongoDb stores documents. Each document is stored in collection. But if you want to do a JOIN between two collections - you can’t do that in MongoDb. And the reason is that JOINs scale very poorly.
  • Transactions. That sound very bad, but the truth is that you don't need transactions in MongoDb in applications where you would need them in relational systems. And the reason is that documents are hierarchical in MongoDb and you can access those documents atomically. 
Choice between non-relational and relational data stores can't be easy. But if you want to create a scalable, high-performance application you should consider MongoDb as an option.

This article is based on video lectures from 10gen education course https://education.10gen.com.