{"id":53,"date":"2013-04-10T05:51:06","date_gmt":"2013-04-10T05:51:06","guid":{"rendered":"http:\/\/ajaykumar.co.in\/?p=53"},"modified":"2013-04-16T03:21:12","modified_gmt":"2013-04-16T03:21:12","slug":"nosql-the-buzz","status":"publish","type":"post","link":"https:\/\/ajaykumar.co.in\/?p=53","title":{"rendered":"NoSQL &#8211; The Buzz"},"content":{"rendered":"<p>NoSQL what is it? The word is really catchy you would start thinking about something which is not SQL. Means we are talking about something which doesn\u2019t have Structured Query Language. But hold on, the name is really confusing. NoSQL means No Relational. Why people came up this name I need to find out. NoSQL is termed for persistence technologies where Relational Database is not used. So when you are not using Relational Database means you are using NoSQL technology.<\/p>\n<p>Before diving deep in what is NoSQL(Non Relational) database, we need to understand what is relational database. Relational Databases are driven by Relations. By the definitions on Wiki<\/p>\n<ul type=\"disc\">\n<li>A relation is a data structure which consists of a heading and an unordered set of tuples which share the same type.<\/li>\n<li>A relation is a set of tuples (d1, d2, &#8230;, dj), where each element dn is a member of Dn, a data domain.<\/li>\n<\/ul>\n<p><span style=\"font-size: 16px; line-height: 1;\">So the key characteristic of Relation is Tuple which shares the same type across multiple records. So if you look at below image, there are attributes and tuple. So same set of attributes are shared across multiple Tuples.<\/span><\/p>\n<p><span style=\"font-size: 16px; line-height: 1;\">\u00a0<a href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-55\" alt=\"NoSQL_Image1\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image1-300x133.png\" width=\"300\" height=\"133\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image1-300x133.png 300w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image1.png 590w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/span><\/p>\n<p>Let&#8217;s take one scenario where we are supposed to store the information related to employees of the company owned by you. So below would be the structure of Relation. This would be kind of table we will have considering we need to store Id, Name, Salary and DOJ.<\/p>\n<p><a href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-56\" alt=\"NoSQL_Image2\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image2-300x128.png\" width=\"300\" height=\"128\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image2-300x128.png 300w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image2.png 463w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>As this company is run by developers like us, so we are playing as much as we earn and you can see we are kind organization who pays well. Just kidding. So we have these many employees. All the employees in this company share the same set of information(Id, Name, Salary and DOJ). So story is very happy till here and we are pretty much in control of solution. Now requirement has little bit of change as you decided to support some open source projects also. So you are asking programming community to support you in development of that open source. Since it is kind of open source and you are not expected to pay salary to some of you employees. So you don&#8217;t have salary attribute to some of these employees. Like\u00a0 this you have different set of attributes for every employee is different. So you need to store information like this.<\/p>\n<p><a href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-57\" alt=\"NoSQL_Image3\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image3-300x227.png\" width=\"300\" height=\"227\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image3-300x227.png 300w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image3.png 623w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><span style=\"font-size: 16px; line-height: 1;\">So now we have to persist information. There are couple of ways to solve this problem using Relational Database. Either use a superset of all these tables and create table with all these attributes. So table structure would look like this.<\/span><\/p>\n<p><a href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-58\" alt=\"NoSQL_Image4\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image4.png\" width=\"461\" height=\"132\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image4.png 823w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image4-300x86.png 300w\" sizes=\"auto, (max-width: 461px) 100vw, 461px\" \/><\/a><\/p>\n<p><span style=\"font-size: 16px; line-height: 1;\">Second option is to two table to store above information. One table with common set of fields and other with Property\/Value combination. So the second table would hold three fields. One EmployeeId foreign field which will map to first table. So after this redesign you table design is going to look like below.<\/span><\/p>\n<p><a href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-59\" alt=\"NoSQL_Image5\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image5-300x231.png\" width=\"300\" height=\"231\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image5-300x231.png 300w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image5.png 531w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><span style=\"font-size: 16px; line-height: 1;\">You might argue that what would be problem with above approach to store different types of data using relational database. I would say it is perfectly fine and you can live with this as long as you are able solve your problem with Relational Database. But the point which I am trying to make here is different. It is not about having one extra field or creating a parent child relationship. It is about persisting data where every tuple has different set of attributes. So we have data which is non-relational in nature and trying to store in RDBMS(Relational Database Management System) but RDBMS are not inherently designed to store Non Relational data.<\/span><\/p>\n<p>NoSQL term is used for broad set of technologies which are schema free, Non Relational, BASE(Not ACID), horizontally scalable and support &#8220;Web Scale&#8221;. Let us understand these features in detail.<\/p>\n<ul type=\"disc\">\n<li><strong><span style=\"font-size: 16px;\">Schema Free<\/span><\/strong> &#8211; We have seen what we mean by pre-defined\/kind of pre-defined schema. So NoSQL database don\u2019t have predefined schemas. So each tuple can have different attribute.<\/li>\n<li><strong>Non-Relational<\/strong> &#8211; NoSQL databases are not relational in nature. Generally we use foreign key relationship to map one table to another table. But in case of NoSQL databases, every tuple is responsible for holding the parent\/child tuple child relation and keeping one foreign key concept doesn\u2019t play in case of NoSQL database.<\/li>\n<li><strong>BASE(Not ACID)<\/strong> &#8211;\u00a0 We know RDBMS has ACID property. ACID stands for Atomicity, Consistency, Isolation and Durability. BASE stands for Basic Availability, Soft state and eventual consistency. So BASE doesn&#8217;t talk about always consistency. It talks about eventual consistency but important is availability. Just to provide detail of what we are talking here. Imagine you started a new merchandise website and deployed on a server. So you started getting hit on\u00a0 this website.<\/li>\n<\/ul>\n<p><a style=\"font-size: 16px; line-height: 1;\" href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-60\" alt=\"NoSQL_Image6\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image6-300x140.png\" width=\"300\" height=\"140\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image6-300x140.png 300w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image6.png 531w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now your site becomes famous overnight and you started getting lot of hits. So scenario would be something like this.<\/p>\n<p><a href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-61\" alt=\"NoSQL_Image7\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image7-300x213.png\" width=\"300\" height=\"213\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image7-300x213.png 300w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image7.png 543w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Since it was a great site, the number of hits increased and one server was not able to handle the entire load. So you created a load balancing architecture where you have server farm to handle all this load.\u00a0 So the scenario would something like below.<\/p>\n<p><a href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-62\" alt=\"NoSQL_Image8\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image8-300x198.png\" width=\"300\" height=\"198\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image8-300x198.png 300w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image8.png 808w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Imagine a basic architecture where have entire app server connecting to one database. So although web server load is balanced but database server is single. So you also need to load balance at database server level. So eventual architecture would be something like below.<\/p>\n<p><span style=\"font-size: 16px; line-height: 1;\"><a href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-63\" alt=\"NoSQL_Image9\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image9-300x181.png\" width=\"300\" height=\"181\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image9-300x181.png 300w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image9.png 886w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/span><\/p>\n<p>So now you have multiple copies of database to handle the load at database level. So either you would be using sharding, partitioning, denormalizing or distributed caching techniques. But after doing all these, you have to make sure the database is always in consistent state as per ACID. To make database consistent your availability would be compromised when there is new addition or update or delete of information. This model works fine till you need a web-scale level of application which I just explained above.<\/p>\n<p>So the time you go for distributed system according to\u00a0<a href=\"http:\/\/www.julianbrowne.com\/article\/viewer\/brewers-cap-theorem\">Eric Brewer\u2019s CAP theorem<\/a>\u00a0if you want consistency, availability, and partition tolerance, you have to settle for two out of three. So in case of ACID, we settle for Consistency and Partition tolerant. But some cases Availability is more important than consistency. Imagine a scenario where it is okay to roll out new product(adding new merchandise in database) different database copies eventually and not in consistent way. So it would be added in one copy of database and then eventually propagated to other copies. This pattern is called BASE.<\/p>\n<p>&nbsp;<\/p>\n<ul type=\"disc\">\n<li>Web-Scale &#8211; I just explained web-scale term in BASE section. Web-Scale is kind of application which is\u00a0 Highly Available, Reliable, Transparent, High Performance, Scalable, Accessible, Secure, Usable, and Inexpensive.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Below are some of the options available as part of NoSQL. Please refer <a href=\"http:\/\/nosql-database.org\/\">http:\/\/nosql-database.org\/<\/a>.<\/p>\n<p><a href=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image10.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-64\" alt=\"NoSQL_Image10\" src=\"http:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image10.png\" width=\"616\" height=\"342\" srcset=\"https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image10.png 880w, https:\/\/ajaykumar.co.in\/wp-content\/uploads\/2013\/04\/NoSQL_Image10-300x166.png 300w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/a><\/p>\n<p>It is not that all these features of NoSQL cann&#8217;t be done using RDBMS. But RDBMS are not inherently designed to support these features. So RDBMS technology is a forced fit for modern interactive software systems. And I am not advocating NoSQL as silver bullet which will solve all your current problems. But it is just additional option which you should have in your arsenal. When you are deciding for database to be used in your application then you can choose NoSQL based on your requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>NoSQL what is it? The word is really catchy you would start thinking about something which is not SQL. Means [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=53"}],"version-history":[{"count":11,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":79,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=\/wp\/v2\/posts\/53\/revisions\/79"}],"wp:attachment":[{"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ajaykumar.co.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}