A Comparative Study of Relational and Non-Relational Database Models in a Web-Based Application

The purpose of this paper is to present a comparative study between relational and non-relational database models in a web-based application, by executing various operations on both relational and on non-relational databases thus highlighting the results obtained during performance comparison tests. The study was based on the implementation of a web-based application for population records. For the nonrelational database, we used MongoDB and for the relational database, we used MSSQL 2014. We will also present the advantages of using a non-relational database compared to a relational database integrated in a web-based application, which needs to manipulate a big amount of data. Keywords—MongoDB; MSSQL; NoSQL; non-relational database


INTRODUCTION
As technology nowadays is tireless and evolves more and more every day, the amount of data is increasing and an application to handle a huge volume of data efficiently it is important to choose the right model of the database.Relational database model has a quite rigid schema that means that a schema must be designed in advance before data had been loaded and all attributes of the schema are uniform for all elements, in the case of missing values null values are used instead [5].It is difficult to change the schema of databases, especially when, it is a partitioned relational database that spreads across multiple servers.If our data capture and management requirements are constantly evolving, a rigid schema can quickly become an obstacle to change [6].
Generally a web application must support millions of users simultaneously and to handle a huge volume of data a relational database model is still widely in use today, even though it has serious limitations when to handle a huge volume of data.
Google, Amazon, Facebook and LinkedIn have been among the first companies that discovered those limitations of the relational database model as far as the demands of new applications.These limitations have led to the development of non-relational databases, also commonly known as NoSQL (Not Only SQL) [7].
Non-relational databases do not use the RDBMS principles (Relational Data Base Management System) and do not store data in tables, and have schema-less approach to data management.Non-relational databases do not require schema definition before inserting data nor changing the schema when data collection and management need evolve [6] [10].Instead, they use identification keys and data can be found based on the keys assigned [8].
NoSQL could be categorized in 4 types [2]: 1) Key-Value databaseswhich are the simplest NoSQL data stores to use, from an API perspective.The most popular ones are Redis, Riak, etc.
2) Document databaseswhich store and retrieve documents as XML, JSON, BSON and so on.The most popular document database is MongoDB, which provides a rich query language.
3) Column family storesthese databases store data in column families as rows that have many columns associated with a row key.One of the most popular is Cassandra.
4) Graph Databasesallows you to store entities and relationships between these entities.There are many graph databases, but between this type of database we can mention OrientDB, FlockDB.etc. [2] According to the article was written by Matt Asay, "NoSQL databases eat into the relational database market" [1] the NoSQL databases, especially MongoDB, occupy more and more space on the market, but with all these Oracle and SQL Server are still constant.In Fig 1 .we can see the popularity of MongoDB and its evolution from 2014 to 2015.In Fig. 1. we can see a growth of 3% for MongoDB from 2014 until 2015 and a decrease of 2% for Oracle and 8% for MySQL.This could mean that the companies are leaning toward NoSQL databases, so they can manipulate more data at a lower price [1].
A big advantage of non-relational databases is that they are more scalable and provide superior performance and their data model addresses several issues that the relational model is not designed to address like large volumes of structured, semistructured and unstructured data, agile sprints, quick iteration, frequent code pushes, object-oriented programming, efficiency, monolithic architecture and so on [3] [9].
In this paper, we focus on one of the non-relational databases, namely MongoDB, and we make a comparison with one of the relational databases, namely MSSQL to highlight advantages and disadvantages of the two models.The study was based on the implementation of a web-based application for population records, which needs to manipulate a big amount of data.

II. APPLICATION DEVELOPMENT USING MONGODB VS. MSSQL
We created a comparative study between relational databases, namely MSSQL, and non-relational databases, namely MongoDB.The study has based on the implementation of a website for population records, which needs to manipulate a big amount of data.To highlight the advantages of using the non-relational database MongoDB compared to the relational database MSSQL, various operations were performed on the two databases.These operations are the four basic operations that can be performed on any database, namely: SELECT, INSERT, UPDATE and DELETE.These operations were made on 1, 100, 500, 1.000, 5.000, 10.000, 25.000 and 50.000 records.The application has been developed, in ASP.NET MVC 4 with C# programming language and we implemented the same methods for both MSSQL and MongoDB databases.For non-relational databases, we used the MongoDB C# Driver that is the officially supported C# driver for MongoDB.The version of the driver is 2.0 and the version of MongoDB is 3.0.
To be able to connect to MongoDB we used a MongoClient.In code, we used two namespaces that are specific to MongoDB: MongoDB.Driver and MongoDB.Bson.Finally we added the connection string in web.config file, like this: We used this connection string through this code: IMongoCollection<BsonDocument> collection = db.GetCollection<BsonDocument>("People"); return collection; } In the method above, we call the database called "Dizertatie" and we get the collection called "People" and the results that will be returned will be a IMongoCollection of BsonDocument type which is a specific format for MongoDB.
Next, we created asynchronous methods to work with the data from MongoDB.For example, for deleting all the registered people from the collection we created a method like this: public static async Task<DeleteResult> DeleteAllConsumers() { var collection = ConnectToServer(); var filter = new BsonDocument("_id", new BsonDocument("$exists", true)); var result = await collection.DeleteManyAsync(filter); return result; } The MongoDB method that we call for deleting the registered people, DeleteManyAsync, will delete multiple documents inside the collection that we are connected to.The number of the deleted documents depends on the filter that we need to create and provide when we want to call the method.In our case, we will delete all registers from this collection.
In the following section we will mainly focus on the performance results for both databases, MongoDB and MSSSQL, that we obtained after we executed operations of SELECT, INSERT, UPDATE and DELETE.

III. COMPARATIVE STUDY: MONGODB VS MSSQL
Generally, depending on the scope of the application that we want to develop, when the project is in the planning stage, each company will establish the resources and the limits for the project.We also need to choose the database for the application that will be developed.Here, we should consider the amount of data that will be manipulated, the rapidity that the project needs and the budget.
Considering these factors, for an application that will need to store a large amount of data, if the application have to handle a huge volume of data, then we should think how we could achieve this in an efficient way or how many resources should be allocated for this scope.For example, in the application that we created, we took in consideration the fact that we need a huge space for storing the data and the queries that will be made every day like adding new data, deleting, updating and so on.All these queries are expensive and we should also, think about the rapidity at which they are processed.Another important fact that we need to consider is the number of users that will access the application, like the employees from all the country, plus the usual users that will need different information.www.ijacsa.thesai.orgConsidering all these facts, it is important to analyse the performance of the application in terms of insertion, update, deletion and selection operations.
The performance of the database that we have chosen can be a very important fact because of the storage space, all the hardware and other components that we need.
We began testing with the creation of databases both MongoDB and MSSQL after that we executed operations of INSERT, UPDATE, DELETE and SELECT on both databases.All these operations have been made on 1, 100, 500, 1.000, 5.000, 10.000, 25.000 and 50.000 records.
In MongoDB, for inserting a list of people into the database we write the following code: After we executed these operations, we obtained the following results that are shown in Table 1.
The graphical representation of the results from Table 1 is shown in Figure 2. We notice that until 1.000 records, we obtained a maximum difference of 200 milliseconds, but we can see that the difference is more significant after 1.000 records and for 50.000 records we obtained a difference of 7 seconds and half.
To update the records in MongoDB we write the following code: var collection = ConnectToServer(); var filter = new BsonDocument("_id", new BsonDocument("$exists", true)); var update = Builders<BsonDocument>.Update .Set("Nume", "Updated") .Set("Adresa", "Updated"); var result = await collection.UpdateManyAsync(filter, update); The methods that we created for MSSQL to insert a new record or a list of records will be used for UPDATE operation too, but the parameter @isInsert will be equal with false in that case.The results of the update operation are shown in Table 3.The graphical representation of the results from Table 3 is shown in Figure 4.For the update operations we can see a bigger difference from 5.000 records, which is approximatively 2 seconds and until 50.000records it grows up to 29 seconds and gives MongoDB an advantage.We notice that MongoDB spends less time than MSSQL, for performing update operation as shown in figure Fig. 4.
To delete the records in MongoDB we write the following code: The results of the delete operation are shown in Table 4.

IV. CONCLUSIONS
In this paper, we showed the results of different operations that had been applied for MongoDB and MSSQL databases.MongoDB provided lower execution times than MSSQL in INSERT, UPDATE and DELETE operations, which is essential when an application should provide support to thousands of users simultaneously.The only time when the MSSQL obtained an advantage was with the SELECT operations, the other ones gave advantages to MongoDB.
We can also notice that the difference between the results of each database was not noticeable until around 1.000 records.Thus, we can say that relational databases, namely MSSQL is suitable for small and medium applications.Relational databases are widely used in most of the applications and they have good performance when they handle a limited amount of data.
We need to be carefull when we want to choose a model of the database for the application that we will want to create.We should take into consideration main factors as the amount of data, the flexibility of schema, the budget, the amount of transactions that would be made and how frequent they are called.These days, companies, depending on the application that they want to develop, have the possibility to choose the most suitable database from a wide range of databases.Generally, for smaller and medium applications, a relational database would be chosen and for big applications, that use and manipulate large quantities of data, a non-relational database will be chosen.Of course, these are not the only criteria for choosing a database, but it depends on each company and the purpose of the application that would need to be developed.
Considering that, in our days, the request for storing a big volume of data at a low price is bigger every day, we tend to choose a non-relational database.Also, MSSQL being commercial at a pretty big price and MongoDB being an open source solution, it is a big disadvantage for MSSQL.
In the end, for choosing the correct database that can satisfy all the needs that an application demands in order to have been developed, all the things presented above should be taken into consideration before the start of development of the project.Depending on what each application needs, we can choose the most suitable database, a non-relational or a relational database.

TABLE I .
THE RESULTS OF THE INSERT OPERATIONAfter we executed these operations for select we obtained the following results that are shown in Table2: