قالب وردپرس درنا توس
Home / Tips and Tricks / What is a NoSQL database and what are they good for? – CloudSavvy IT

What is a NoSQL database and what are they good for? – CloudSavvy IT



A NoSQL database is any type of database that breaks away from traditional SQL design. NoSQL databases such as the document-based MongoDB have become increasingly popular in recent years. What is all the hype about?

The limitation of SQL: scalability

SQL has always been around – 45 years. It holds up surprisingly well, and modern implementations of SQL are very quick. However, as the web grows, so does the need for high-performance databases that can be scaled to meet demand.

The easiest way to scale a SQL database is to run it on a more powerful computer. SQL databases can be replicated to reduce regional load on a single instance, but to split a table (frequently called) shards) is much more difficult for SQL.

Document-based NoSQL databases purposely address this problem. Each document is independent from other documents in the collection, making it much easier to split the collections across multiple servers. Many document databases contain built-in tools for sharding the data on different servers.

However, the problem of scalability isn̵

7;t really a problem until you have a problem quantity of files. You can easily run an SQL database with hundreds of thousands of users and you will have no problems provided your structure is solid and your queries are fast.

Both MySQL and MongoDB will likely do the job for your application, so the choice between them will depend on which structure and syntax you prefer. Ease of development is important, and you may find that the much newer MongoDB’s document model and syntax are easier to work with than SQL.

NoSQL vs. SQL structure

Traditional SQL databases are called up frequently relational databases because of the way they are structured. In an SQL database, you have multiple tables, each with multiple rows (called) records), which themselves have several different columns, or Attributes. Each table is linked to the other by a primary key that forms a relationship.

For example, imagine you have a table with each record that represents a user’s contribution. The primary key here is the user name with which the contribution table can be linked to the user table. If you want to find the email address of the person who wrote the post, search for “Jon1996” in the user table and select the “Email” field.

However, this data structure may not work for everyone. SQL databases have a well-defined schema that can bother you if you need to make changes or simply prefer a different layout. With complex data sets, the relationships between anything can get more complicated than the data itself.

The main type of NoSQL database is a JSON document database like MongoDB. Instead of storing rows and columns, all data is stored in individual documents. These documents are stored in collections (for example, a “User” document would be stored in an “All Users” collection) and need not have the same structure as other documents in the collection.

For example, a “User” document might look something like this:

{
  "username":"Jon1996",
  "email":"jon1996@gmail.com",
  "posts": [
   {"id":1},
   {"id":2},
   {"id":3},
  ]
}

The Username and Email fields are just key-value pairs, similar to columns in SQL, but the Posts field contains an array that you will not find in SQL databases. Suppose we had a collection of mail with documents like

{
  "id":1,
  "title":"First Post",
  "content":"Hello, World!",
  "madeby":"Jon1996"
}

Now when someone visits Jon’s page, your application can pull three posts with IDs 1, 2, and 3, which is usually a quick query. Compared to SQL where you might need to get all the posts that match Jon’s userid. Still pretty fast, but the MongoDB query is more direct and makes more sense.

What are NoSQL databases good for?

NoSQL is a broad category and includes many different types of databases created with different goals. Every database is a tool, and your job may require a particular type of tool or even several different tools.

SQL databases like MySQL, Oracle and PostgreSQL existed before the Internet. They’re very stable, have a lot of support, and in general can do the job for most people. If your data is valuable to you and you want an established, consistent solution, stick with SQL.

JSON document databaseslike MongoDB and Couchbase, are popular for web applications with changing data models and for storing complex documents. For example, a site like Amazon often needs to change the data model for storing products on the site, so a document-based database may work well for them.

Document databases are meant to be the general replacement for SQL, and are probably what you think of when you hear “NoSQL”. They’re also more intuitive to learn than SQL because you don’t have to manage relationships between tables or complex queries.

RethinkDB is a JSON document database that was created for real-time applications. In a database like MongoDB, you have to check for updates every few seconds or, on top of that, implement an API to keep track of real-time updates that get very large quickly. RethinkDB solves this problem by automatically pushing updates over websocket streams that clients can connect to.

Redis is a very powerful key-value database that stores small keys and strings entirely in RAM. It’s much faster to read and write than even the fastest SSDs. It is often used in conjunction with other databases as an in-memory cache of small data that is frequently written to and read from. For example, a messaging app might want to use Redis to store the user’s messages (and even broadcast updates in real time using their pub / sub methods). Storing many small messages in this way can cause performance problems with other types of databases.

Chart databases are used to store connections between data. A common use case is social networks, where users are connected to each other and interact with other data, e.g. B. with posts created by you.

In this example, George is friends with two people, Jon and Jane. If any other type of database was to understand George’s connection to Sarah, they would have to query all of Jon’s friends and all of Jane’s friends. However, graph databases understand this relationship intuitively. The popular graphics database Neo4J is 60% faster than MySQL for querying friends of friends. For friends of friends of friends (3 levels deep) is Neo4J 180 times faster.

Wide column databases like Cassandra and Hbase, are used to store large amounts of data. They’re designed for amounts of data so large that you need multiple computers to store everything, and they’re much faster than SQL and other NoSQL databases when spread across multiple nodes.


Source link