Growing businesses face a range of challenges and opportunities which demand some future proof planning. What worked a year ago might not be the best approach today. Similarly, when you're building a new .NET enterprise application, you have to think through and pick the right tool for the right job. If you choose wrong, it will hurt your complete business in the long run.
Picking the right database technology is one of those decisions that will drive how you architect your application. Since there is no technology that fits all, this article will help you understand why and when should you choose a NoSQL database.
To make a choice, you first need to ask a few questions about the needs of your application. For example;
Answering these questions helps you identify the needs of your application and highlights areas where a NoSQL database truly shines in contrast to a relational database.
Relational databases have been dominating the database industry for the past many years, but this way of storing data is challenged with new business requirements. With ever increasing user growth and the huge amounts of data being generated, relational databases cannot provide on demand scalability. It is because they are primarily engineered to run in a single server machine, thus scaling-up has been the only option.
Scaling up means upgrading your servers by adding more processors, RAM and hard-disks to your machine to handle more load and increase capacity. Which means that whenever your business has grown enough to max out server capacity, you have to replace and upgrade your database server machines to accommodate more throughput (reads and writes). This results in downtime. Also, in "less-than-peak-load" conditions, you are under-utilizing your server machines and incurring unnecessary initial costs.
To tackle the problem of lack of scaling out, architects often deploy an In-Memory distributed cache, like NCache, with SQL servers. This brings linear scalability to your relational database layer and improves performance. In-Memory distributed caches help control costs, but there are other options to scale your apps, based on other considerations that make a NoSQL database attractive.
Note: You can always put a distributed cache on top of a NoSQL database to get the maximum performance available today.
As you know, a relational database stores data in a fixed and pre-defined structure. This leads to a rigid data model where each schema change comes at a cost. This is because before your begin your development, you have to define your data schema in terms of tables and columns. Any change in the data model requires a change in the schema which leads to creating new columns, defining new relations, reflecting the changes in your application, discussing with your database administrators etc. While possible, this process is against everything agile, where new business requirements need a fast implementation.
So what are the advantages an enterprise application can leverage from a NoSQL database? A NoSQL database provides extreme data flexibility, scales out as your application scales out and assures 100% database uptime. These advantages can be addressed under three headings:
All businesses have a knack for adding new demands and features to their applications after deployment. Such requirement changes are not just feature requests but entire changes in business process as well. Innovation in any industry is not just a buzzword anymore, it's a necessity, and competition demands rapid adaptability to new requirements.
NoSQL is built to support exactly such fast moving requirements whereas a relational database is inherently slow to such changes due to its rigid data structure. NoSQL databases fully support agile development.
A NoSQL database stores data in Key Value pairs where the "key" is just a unique identifier and the "value" is a JSON document. The closest similar entity in a relational database is a row. A row in an RDBMS is just a flat data structure where the data is divided into columns. The JSON format however, is much, much richer than just a flat data structure. For comparison reasons, the following diagram speaks volumes.
The diagram shows a single row of a user data converted to a JSON document. In it, the column names are converted to keys inside a JSON document and the values are retained as is.
For example, if we are to add new information to the user data, it requires a hit on the whole database (i.e. all the rows of a table) which hurts performance on production servers thereby hurting every other application depending on the servers as well.
NoSQL on the other hand is completely flexible. Instead of defining all the column names before inserting data, a NoSQL database has no data schema restrictions. If your business demands a change or addition in the data from here-forth, no problem. Just add new entities inside new JSON documents.
With the help of a NoSQL database, your data schema is flexible and that supports the speed that agile development demands. Your application will accept new changes as required by the business without advanced definition.
Storing data in the JSON format not only provides schema flexibility, it is also a more natural way to store data than in rows and columns. For example, a relational database stores data in pieces. Suppose you need to store a USER object which has multiple Hobbies
and also has a few Shipping Addresses
. The relational way to store such information would be as follows.
This data is naturally meant to be stored together since the values are accessed, used and created together. So it's safe to say that storing information in rows and columns is highly structured and therefore unnatural. The natural way would have been to store this information as one and group them together. This would allow your applications to access this information without any complex queries and JOINS.
Such flexibility with fluid data models allows you to mold your data according to your application needs and also helps you adapt to new changes per requirements of the business.
While you need to learn a few tricks about storing data in a way which bests suits your needs, why should you need to learn new tricks to retrieve it? NosDB supports data querying and data definition through SQL. This cuts down the learning curve for data retrieval by a huge margin. For example:
You could also query on the objects embedded inside the base JSON object.
Some of the supported keywords are GroupBy
, Exists
, IsNOTNULL
, Contains
e.t.c
For more information you could check out the SQL cheat sheet or check out the documentation for detailed information on SQL.
Such a non-relational data model helps you to develop faster and more agile applications and also helps the NoSQL database to distribute data among multiple server machines.
NoSQL databases break the traditional mindset of storing data at a single location. Instead, NoSQL distributes and stores data over a set of multiple servers. This distribution of data helps the NoSQL database server to distribute the load
on the database tier. This distributed data approach also means the system can scale out rather than just scale up.
One of the main advantages of a NoSQL database over a relational database is the ability to scale out. Scaling out means adding more servers to your system to distribute the load. That is, when your current server machines (application or database) reach their maximum capacity, you do not stop operations to upgrade your server machines; instead you add more nodes. Such scalability also saves money by using less-costly commodity hardware rather than expensive multi-core heavy duty machines.
As seen from the above figure, adding servers only when required helps to keep the operating cost low. NosDB can scale out to an infinitely large cluster and it provides linear scalability. Which means that as you increase your NoSQL database servers, your transaction capacity increases equally. This helps you to handle huge amounts of data beyond the limits of a single machine.
Other than providing scalability, NoSQL databases also provide high availability out of the box. NoSQL architecture supports data replication that happens near real time. If a primary server goes down, the replica server automatically takes over and your client applications work seamlessly. There is practically no limit to the number of replicas a node can have.
Furthermore, NoSQL databases allow you to configure your database to span multiple data centers. This way, if any data center completely crashes, other replica machines can take over. These replica machines can be configured to serve read requests from client applications. Typically, the closest replica is automatically selected by the client application based on a "nearest-path" algorithm.
The other way to ensure 100% uptime is to distribute your database cluster to diverse geographic locations. This way while your application has access to all of the database servers, you can control the data distribution to get the maximum performance.
For more information on how NoSQL database are architectured, please see the documentation
To gain a competitive edge, businesses need to innovate and adopt agile methodologies. NoSQL is the perfect fit for such needs in the database sphere. They allow you to store data in a flexible and fluid data model, provide scaling up capabilities to your database tier, and provide 100% uptime through replication.
To top it off, NosDB is a NoSQL Document Database written 100% in .NET. and it comes with algorithms like MapReduce baked right into the database. To assist in migration from an RDBMS, NosDB provides an official ADO.NET wrapper. So if you're a .NET developer and want to try a .NET native NoSQL database, give NosDB a try.
With a NoSQL database offering so much, the question "Why NoSQL?" should be "Why not NoSQL?"
NosDB is 100% native .NET NoSQL Database (released under Apache 2.0 license) with flexible JSON schema which allows your .NET applications to handle extreme transaction loads (XTP).