SQL and NoSQL Data structures
Published: 2021-03-01 05:34:30


For every benefit of a data structure, there will be some tradeoff. Consider cooking: say you want to prepare a meal that is cheap, fast, and delicious. You realize that you’ll only ever be able to achieve two of these qualities. So, then, it’s about ordering your priorities. And your priorities for a weeknight meal will differ from meal planning on the weekend. The same give and take is true of databases. Any application will have unique data storage priorities. These priorities are largely outlined by the CAP theorem:

C: Consistency
A: Availability
P: Partition Tolerance

Imagine these qualities as a triangle, and a given database resides on one of the triangle’s vectors. 

SQL would reside on the vector between consistency and availability. NoSQL would reside between Availability and Partition Tolerance. Choosing which data storage type is right for an application means choosing the greatest priority, and understanding it will come at the expense of a lower priority.



##SQL


SQL has been in practice for over two decades, and takes advantage of a relational format that increases durability and safeguards data. Data in one table can reference data from another table using keys. For deeply structured data (think anything that can cleanly be represented on an Excel spreadsheet), MySQL creates a powerful interconnected web of data that is ideal for advanced analytics. Structured Query Language is also programmer friendly. The highly structured format makes easy work of iterating through a table, filtering data, or joining data into a single collection.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ru5d2ah1ey11r2wi1i3j.jpg)

For large data systems, the table-based architecture exemplified here simply scales upwards.


##NoSQL


As storage needs have tilted due to the sheer volume of data collected and utilized in applications, availability and accessibility of storage have become a priority. This is where MongoDB and other NoSQL database systems thrive. By using an unstructured format, any type of data, and importantly, varying volumes of data, can easily be stored. Unstructured storage is also the optimum format for data that might not currently have much utility in a program, but could be useful in the future.

MongoDB stores data in the JSON format. JSON, or Javascript Object Notation, utilizes a key value system that is less rigid than the table system used by SQL databases. JSON’s ubiquity makes the process of formatting data for storage in MongoDB fairly straightforward.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6atqvbesrrk8lqmhb8t.jpg)

It's important to note that there are a variety of options for adding advanced analytics functionality to MongoDB. While these methods won't be native to MongoDB as they are to MySQL, they offer programmers the opportunity to capture some of the functionality of structured databases. 

##Summary

To summarize, structured data storage like SQL is ideal for applications where advanced analytics are required. On the other hand, NoSQL databases like MongoDB allow programmers greater flexibility for data that is difficult to structure. MongoDB also utilizes the popular JSON format.