One of the most important decisions a developer makes is which database to use. Over the years, options have been limited to various relational database options that support structured query language (SQL). These include MS SQL Server, Oracle, MySQL, PostgreSQL, DB2, and many others.
Over the past 15 years, many new databases have appeared on the market as part of the No-SQL approach. These include key-value stores, such as Redis and Amazon DynamoDB, wide column databases, such as Cassandra and HBase, document stores, such as MongoDB and Couchbase, as well as graph databases and search engines, such as Elasticsearch and Solr.
In this article we will try to understand SQL and NoSQL, without getting into their functionality.
In addition, we will have some fun in the process.
Explain Granny SQL
Grandma, imagine that I am not your only grandson. Instead, mom and dad loved each other like rabbits, they had 100 children, then they adopted another 50.
So, you love us all and do not want to forget any of our names, birthdays, tastes of our favorite ice cream, clothing sizes, hobbies, names of spouses, names of offspring and other super important facts. But let's face it. You are 85 years old, and the good old memory is simply not able to cope.
Fortunately, I, being the smartest of your grandchildren, can help. So I come to your home, take out a few sheets of paper and ask you to bake cookies before we start.
On one sheet of paper we make a list called "
Grandchildren ." Each
grandson is recorded with some essential information about him, including a unique number, which will now indicate what kind of
grandson he is. In addition, for the sake of organization, we write out named attributes at the top of the list so that we always know what information this list contains.
Grandchildren list
After a while, you understand everything and we are almost done with the list! However, you turn to me and say: “We forgot to add a place for spouses, hobbies, grandchildren!” But no, we did not forget! This goes further and requires a new sheet of paper.
So I pull out another piece of paper, and on it we call the list of
Spouses . We again add the attributes that are important to us at the top of the list and start adding in the lines.
List of spouses
At this stage, I explain to my grandmother that if she wants to know who is married to whom, she only needs to match the
id in the list of
grandchildren with
grandchild_id in the list of spouses.
After a couple dozen cookies, I need to take a nap. “Can you continue, granny?” I'm leaving to take a nap.
I’m coming back in a few hours. And you are cool, granny! Everything looks great except for the
hobby list. There are about 1000 hobbies on the list. Most of them are repeated; what happened?
Sorry, I completely forgot to say! Using one list, you can track only
hobbies . Then in another list we need to track the
grandchildren who are engaged in this
hobby . We are going to call it the
“General List .
” Seeing that you do not like it, I start to worry and return to list mode.
Hobby List
As soon as we have our list of hobbies, we create our second list and call it “
Grandchildren ’s
Hobbies ”.
General list of grandchildren hobbies
After all this work, my grandmother now has a cool memorization system for tracking her entire surprisingly large family. And then - in order to detain me longer - she asks the magic question: “Where did you learn to do all this?”
Relational databases
A relational database is a set of formally described tables (in our example, these are sheets) from which you can access
data or collect them in various ways without having to reorganize the
database tables. There are many different types of relational databases, but unfortunately the list on a piece of paper is not one of them.
A distinctive feature of the most popular relational databases is the SQL query language (Structured Query Language). Thanks to him, if grandmother transfers her memorization system to a computer, she will be able to quickly get answers to questions such as: “Who did not visit me last year, is married and has no hobbies?”
One of the most popular SQL database management systems is open source MySQL. It is implemented primarily as a relational database management system (RDBMS) for web-based software applications.
Some key features of MySQL:
- It is quite famous, widely used and thoroughly tested.
- There are many qualified developers with experience working with SQL and relational databases.
- Data is stored in various tables, which makes it easy to establish communication using primary and foreign keys (identifiers).
- It is easy to use and efficient, making it ideal for large and small enterprises.
- Source code is subject to the GNU General Public License.
Now forget
ALL .
Explain Grandma NoSQL
Grandma, we have a huge family. She has 150 grandchildren! Many of them are married, have children, are fond of something, and so on. At your age, it is impossible to remember everything about all of us. What you need is a memorization system!
Fortunately, I,
not wanting you to forget my birthday and my favorite taste of ice cream, can help. Therefore, I run to the nearest store, take a notebook and return to your home.
The first step I take is to write “Grandchildren” in big bold letters on the cover of a notebook. Then I turn to the first page and start writing everything that you should remember about me. After a few minutes, the page looks something like this.
{ "_id":"dkdigiye82gd87gd99dg87gd", "name":"Cody", "birthday":"09-12-2006", "last_visit":"09-02-2019", "clothing_size":"XL", "favorite_ice_cream":"Fudge caramel", "adopted":false, "hobbies":[ "video games", "computers", "cooking" ], "spouse":null, "kids":[ ], "favorite_picture":"file://scrapbook-103/christmas-2010.jpg", "misc_notes":"Prefers ice-cream cake on birthday instead of chocolate cake!" }
Me : “Everything seems ready!”
Grandmother : “Wait, what about the other grandchildren?”
Me : “Yes, exactly. Then select a page for each. ”
Grandmother : “And I will need to record all the same information for everyone, as I did for you?”
Me : “No, only if you want. Let me show."
Taking my pen from my grandmother, I turn over the page and quickly write down information about my most unloved cousin.
{ "_id":"dh97dhs9b39397ss001", "name":"Tanner", "birthday":"09-12-2008", "clothing_size":"S", "friend_count":0, "favorite_picture":null, "remember":"Born on same day as Cody but not as important" }
Whenever a grandmother needs to remember something about one of her grandchildren, she only needs to go to the right page in her grandchildren's notebook. All information about them will be stored right there on their page, which it can quickly change and update.
When everything is already done, she asks the magic question: “Where did you learn to do all this?”
NoSQL Databases
There are many
NoSQL databases (“not just SQL”). In our examples, we showed
a database of documents . NoSQL databases model data in ways that exclude tabular relationships used in relational databases. These databases became popular in the early 2000s among companies that needed a cloud-based clustering of databases due to their explicit scalability requirements (e.g. Facebook). In such applications, data consistency was much less important than performance and scalability.
At the beginning, NoSQL databases were often used for niche data management tasks. Basically, when it came to web and cloud applications, NoSQL databases processed and distributed significant amounts of data. Engineers working with NoSQL also liked the flexible data scheme (or its complete absence), so that quick changes in updated applications were possible.
Key features of NoSQL:
- Very flexible way to store data.
- Scale to Clusters
- Possible Consistency / Distribution Sequence
- Documents that are identified using unique keys
Detailed comparison
MySQL requires a specific and structured framework.
NoSQL allows you to save any data in a "document".
MySQL supports a huge community.
NoSQL has a small and rapidly growing community.
NoSQL is easy to scale.
MySQL needs more manageability.
MySQL uses SQL, which is used in many types of databases.
NoSQL is a design-based database with popular implementations.
MySQL uses standard query language (SQL).
NoSQL does not use the standard query language.
MySQL has many great reporting tools.
NoSQL has several reporting tools that are difficult to standardize.
MySQL may issue performance issues for big data.
NoSQL provides great performance on big data.
Thoughts 8base
At
8base , where I work, we provide the workspace of each project with the Aurora MySQL relational database hosted on AWS. Although NoSQL is a logical choice when the requirements of your application require high performance and scalability, we believe that the strict data consistency provided by the DBMS is necessary when creating SaaS applications and other business software.
For startups and developers creating such business applications that need reporting, transaction integrity and well-defined data models, investing in relational databases is, in our opinion, the right choice.
Learn more about developing with Aurora, Serverless, and GraphQL with 8base.com
here .