NoSQL Introduction
NoSQL (NoSQL = Not Only SQL), which means "not only SQL".
On modern computing systems, a huge amount of data is generated on the network every day.
A large part of this data is processed by relational database management systems (RDBMS). In 1970, E.F.Codd's paper on the relational model, "A relational model of data for large shared data banks", made data modeling and application programming simpler.
Application practice has proven that the relational model is very suitable for client-server programming, with benefits far beyond expectations. Today it is the leading technology for structured data storage in network and business applications.
NoSQL is a brand-new revolutionary movement in databases. It was proposed early on, and by 2009 the trend was rising. NoSQL advocates promote the use of non-relational data storage. Compared with the overwhelming use of relational databases, this concept is undoubtedly an injection of new thinking.
Relational databases follow the ACID rules
A transaction in English is transaction, very similar to a transaction in the real world. It has the following four characteristics:
1. A (Atomicity) Atomicity
Atomicity is easy to understand. It means all operations in a transaction are either all completed or none are done. A transaction succeeds only if all operations in it succeed; as long as one operation fails, the whole transaction fails and needs to be rolled back.
For example, a bank transfer from account A to account B of 100 yuan involves two steps: 1) withdraw 100 yuan from account A; 2) deposit 100 yuan into account B. These two steps must either both complete or both not complete. If only the first step completes and the second fails, 100 yuan will mysteriously disappear.
2. C (Consistency) Consistency
Consistency is also easy to understand. It means the database must always be in a consistent state, and the running of a transaction does not change the original consistency constraints of the database.
For example, given the existing integrity constraint a+b=10, if a transaction changes a, then b must be changed so that a+b=10 still holds after the transaction ends; otherwise the transaction fails.
3. I (Isolation) Isolation
The so-called isolation means that concurrent transactions do not affect each other. If the data a transaction wants to access is being modified by another transaction, as long as the other transaction is not committed, the data it accesses is not affected by the uncommitted transaction.
For example, suppose there is a transaction transferring 100 yuan from account A to account B. Before this transaction is completed, if B queries its own account at this time, it cannot see the newly added 100 yuan.
4. D (Durability) Durability
Durability means that once a transaction is committed, the changes it made will be permanently saved in the database and will not be lost even if a crash occurs.
Distributed system
A distributed system consists of multiple computers and communicating software components connected through a computer network (a local network or a wide area network).
A distributed system is a software system built on top of a network. Precisely because of the characteristics of software, distributed systems have a high degree of cohesion and transparency.
Therefore, the difference between a network and a distributed system lies more in the high-level software (especially the operating system) than in the hardware.
Distributed systems can be applied on different platforms such as PC, workstations, LANs, and WANs.
Advantages of distributed computing
Reliability (fault tolerance):
An important advantage of distributed computing systems is reliability. The crash of one server does not affect the other servers.
Scalability:
In a distributed computing system, more machines can be added as needed.
Resource sharing:
Sharing data is an essential application, such as in banking and reservation systems.
Flexibility:
Since the system is very flexible, it is easy to install, implement, and debug new services.
Faster speed:
A distributed computing system can have the computing power of multiple computers, giving it a faster processing speed than other systems.
Open system:
Since it is an open system, the service can be accessed locally or remotely.
Higher performance:
Compared with centralized computer networks, clusters can provide higher performance (and better cost-effectiveness).
Disadvantages of distributed computing
Troubleshooting:
Troubleshooting and diagnosing problems.
**Software:**
Less software support is the main disadvantage of distributed computing systems.
Network:
Problems with network infrastructure, including: transmission problems, high load, information loss, etc.
**Security:**
The characteristics of open systems make distributed computing systems have issues such as data security and sharing risks.
What is NoSQL?
NoSQL refers to non-relational databases. NoSQL is sometimes also called an abbreviation of Not Only SQL, and is a general term for database management systems that differ from traditional relational databases.
NoSQL is used for the storage of very large-scale data. (For example, Google or Facebook collects trillions of bits of data from their users every day.) These types of data storage do not need a fixed schema and can scale horizontally without extra operations.
Why use NoSQL?
Today we can easily access and crawl data through third-party platforms (such as Google, Facebook, etc.). Users' personal information, social networks, geographic locations, user-generated data, and user operation logs have increased exponentially. If we want to mine these user data, SQL databases are no longer suitable for these applications, while the development of NoSQL databases can handle these large data very well.

Example
Social networks:
Each record: UserID1, UserID2
Separate records: UserID, first_name,last_name, age, gender,...
Task: Find all friends of friends of friends of ... friends of a given user.
Wikipedia page :
Large collection of documents
Combination of structured and unstructured data
Task: Retrieve all pages regarding athletics of Summer Olympic before 1950.
RDBMS vs NoSQL
**RDBMS **
- Highly organized structured data
- Structured Query Language (SQL) (SQL)
- Data and relationships are stored in separate tables.
- Data manipulation language, data definition language
- Strict consistency
- Basic transactions
**NoSQL **
- Represents not only SQL
- No declarative query language
- No predefined schema
- Key-value pair storage, column storage, document storage, graph database - Eventual consistency, rather than ACID properties
- Unstructured and unpredictable data
- CAP theorem
- High performance, high availability, and scalability

A Brief History of NoSQL
The term NoSQL first appeared in 1998. It was a lightweight, open-source relational database without SQL functionality developed by Carlo Strozzi.
In 2009, Johan Oskarsson of Last.fm initiated a discussion about distributed open-source databases [2]. Eric Evans from Rackspace re-proposed the concept of NoSQL. At this time, NoSQL mainly referred to non-relational, distributed database design patterns that do not provide ACID.
The "no:sql(east)" conference held in Atlanta in 2009 was a milestone, with the slogan "select fun, profit from real_world where relational=false;". Therefore, the most common interpretation of NoSQL is "non-relational", emphasizing the advantages of Key-Value Stores and document databases rather than simply opposing RDBMS.
CAP theorem (CAP theorem)
In computer science, the CAP theorem (CAP theorem), also known as Brewer's theorem (Brewer's theorem), states that it is impossible for a distributed computing system to satisfy all three of the following points at the same time:
- Consistency (Consistency) (all nodes have the same data at the same time)
- Availability (Availability) (guarantee that every request has a response, whether successful or failed)
- Partition tolerance (Partition tolerance) (the loss or failure of any information in the system does not affect the continued operation of the system)
The core of the CAP theorem is: a distributed system cannot satisfy all three requirements of consistency, availability, and partition tolerance well at the same time, and can only satisfy two of them well at most.
Therefore, according to the CAP principle, NoSQL databases are divided into three major categories: those satisfying the CA principle, those satisfying the CP principle, and those satisfying the AP principle:
- CA - a single-point cluster, a system satisfying consistency and availability, usually not very strong in scalability.
- CP - a system satisfying consistency and partition tolerance, usually not particularly high in performance.
- AP - a system satisfying availability and partition tolerance, usually with lower requirements for consistency.

Advantages/Disadvantages of NoSQL
Advantages:
-
- High scalability
-
- Distributed computing
-
- Low cost
-
- Architectural flexibility, semi-structured data
-
- No complex relationships
Disadvantages:
-
- No standardization
-
- Limited query functionality (so far)
-
- Eventual consistency is not intuitive to program
BASE
BASE: Basically Available, Soft-state, Eventually Consistent. Defined by Eric Brewer.
The core of the CAP theorem is: a distributed system cannot satisfy all three requirements of consistency, availability, and partition tolerance well at the same time, and can only satisfy two of them well at most.
BASE is the principle of weak requirements for availability and consistency that NoSQL databases usually have:
- Basically Available -- basically available
- Soft-state -- soft state / flexible transaction. "Soft state" can be understood as "connectionless", while "Hard state" is "connection-oriented"
- Eventually Consistency -- eventual consistency, which is also the ultimate goal of ACID.
ACID vs BASE
| ACID | BASE |
|---|---|
| Atomicity(Atomicity) | Basically Available(Basically Available) |
| Consistency(Consistency) | Soft state / flexible transaction(Soft state) |
| Isolation(Isolation) | Eventual consistency (Eventual consistency) |
| Durability (Durable) |
NoSQL Database Classification
| Type | Some representatives | Feature |
|---|---|---|
| Column storage |
Hbase Cassandra Hypertable |
As the name suggests, it stores data by columns. The biggest feature is that it facilitates the storage of structured and semi-structured data, facilitates data compression, and has a great I/O advantage for queries targeting a certain column or columns. |
|
Document storage |
MongoDB CouchDB |
Document storage generally uses a json-like format for storage, and the stored content is document-type. This also gives the opportunity to build indexes on certain fields to achieve some functions of relational databases. |
|
key-value storage |
Tokyo Cabinet / Tyrant Berkeley DB MemcacheDB Redis |
You can quickly query its value through a key. Generally speaking, storage does not care about the format of the value and accepts it all. (Redis includes other functions.) |
|
Graph storage |
Neo4J FlockDB |
The best storage for graph relationships. Using traditional relational databases to solve this is inefficient, and the design and use are inconvenient. |
|
Object storage |
db4o Versant |
Operate the database through syntax similar to an object-oriented language, and access data in the form of objects. |
|
xml database |
Berkeley DB XML BaseX |
Efficiently store XML data and support XML's internal query syntax, such as XQuery, Xpath. |
Who is using it
Now many companies use NoSQL:
- Mozilla
- Adobe
- Foursquare
- Digg
- McGraw-Hill Education
- Vermont Public Radio