Skip to content

Comparison of common databases

MySQL


MySQL is a relational Database mainly used to store persistent data, and the data is stored in the hard disk, and the reading speed is slow.

MySQL is used to store data persistently to hard disk. It has powerful functions and slow speed. Based on disk, the read and write speed is not as fast as that of Redis, but it is not limited by space capacity and is cost-effective.

MySQL and redis are generally used together according to different requirements.

Using Redis where high performance is required and MySQL where high performance is not required. Stored data is synchronized between MySQL and Redis.

Disadvantages: The efficiency will be significantly slower when processing massive data.

Redis

Redis is a non-relational database. It stores data in the cache. The read speed of the cache is fast, which can greatly improve the operation efficiency, but the storage time is limited.

Redis is used to store frequently used data in the cache. It has fast reading speed and memory-based reading and writing speed. It can also be persisted, but the memory space is limited. When the amount of data exceeds the memory space, the memory needs to be expanded, but Memory is expensive.

Since Redis data is stored in memory, if persistence is not configured, all data will be lost after redis restarts. Therefore, it is necessary to enable the persistence function of redis and save the data to disk. Data recovery.

Redis provides two methods for persistence, one is RDB persistence (the principle is to periodically dump the database records of Reids in memory to RDB persistence on disk), and the other is AOF (append only file) persistence ( The principle is to append the operation log of Reids to the file).

mangoDB


mangoDB is a non-relational database, its data is stored on the hard disk, the data that needs to be read frequently will be loaded into the memory, and the data will be stored in the physical memory, so as to achieve high-speed read and write.

Advantage


1. The performance of MongoDB with an appropriate level of memory is very fast. It stores hot data in physical memory, making the reading and writing of hot data very fast.
2. MongoDB’s high availability and cluster architecture have very high scalability.
3. In the replica set, when the main database encounters a problem and cannot continue to provide services, the replica set will elect a new main database to continue to provide services.
4. The data in MongoDB’s Bson and JSon formats are very suitable for storage and query in document format.

Disadvantage


1. Transaction operations are not supported. MongoDB itself does not have its own transaction mechanism. If you need to implement a transaction mechanism in MongoDB, you need to implement the transaction logically by yourself by an additional table.
2. Less application ecosystem. Due to the short rise time of NoSQL, the application ecosystem is less than that of relational databases.
3. MongoDB takes up too much space.

PostgreSQL


MySQL is a relational database with single storage engine, and PostgreSQL is a multi-storage engine database, including InnoDB, MyISAM, etc.

PostgreSQL is very stable, and InnoDB is quite stable even in the case of a power outage.

PostgreSQL is multi-process, MySQL is multi-threaded. PostgreSQL supports triggers that fire on most command types. MySQL is asynchronous replication, and PostgreSQL supports synchronous, asynchronous, and semi-synchronous replication.

Advantage

The implementation of SQL standard is better than MySQL, and the function implementation is more rigorous;

The function support of the stored procedure is better than that of MySQL, and it has the ability to cache the execution plan locally;

The support for table joins is relatively complete, the functions of the optimizer are relatively complete, many index types are supported, and the complex query ability is strong;

The PG main table is stored in a heap table, and MySQL uses an index to organize the table, which can support a larger amount of data than MySQL.

The primary and secondary replication of PG belongs to physical replication. Compared with MySQL’s binlog-based logical replication, the data consistency is more reliable, the replication performance is higher, and the impact on the host performance is smaller.

MySQL’s storage engine plug-in mechanism has the problem that the lock mechanism is complex and affects concurrency, but PG does not exist.

ETCD

ETDC is a distributed and highly available Key/Value storage system written by CoreOS and written in Go language. It is mainly used for service discovery and configuration sharing.

etcd provides the function of mini-transaction. etcd data is stored in a B+ tree.

The classic application scenarios of ETCD are:

  1. Key/Value storage: etcd supports HTTP RESTful API, providing strong consistency (raft consistency algorithm) and high-availability data storage capabilities.
  2. Service registration and discovery: By registering the directory of a service in etcd, the service instance connects to Etcd and publishes the corresponding IP and port in the directory for the caller to use, which can effectively implement service registration and discovery.
  3. Message publishing and subscription: Through the Watcher mechanism of ETCD, subscribers can subscribe to the directories they care about. When the message publisher modifies the content of the monitored directory, the subscriber can be notified of the change in real time.
  4. Load balancing, distributed lock
  5. Distributed queue
  6. Cluster monitoring and leader election

Advantages

  1. Simple, easy to write and deploy in Go language
  2. Using HTTP as an interface is easy to use
  3. Use the Raft algorithm to ensure strong consistency and make it easy for users to understand
  4. Data persistence, etcd default data is persisted as soon as it is updated
  5. Security, etcd supports SSL client security authentication

LevelDB


LevelDB is an open source KV storage engine by Google’s legendary engineers Jeff Dean and Sanjay Ghemawat.

The data of LevelDB is stored on the disk, which is implemented by the structure of LSM-Tree. LSM-Tree converts random writes to the disk into sequential writes, which greatly improves the write speed.

Memtable for in-memory data, SST files for hierarchical data storage, Manifest and Current files for version control, and WAL (Write-Ahead Logging) before writing Memtable.

Advantages


First of all, LevelDB is a persistent storage KV system. Unlike Redis, which is an in-memory KV system, LevelDB does not take up a lot of memory like Redis, but stores most of the data on disk.

Secondly, when LevelDB stores data, it is stored in an orderly manner according to the recorded key values, that is to say, adjacent key values ​​are stored in order in the storage file, and the application can customize the key size comparison function, and LevelDB will store it according to the user. The defined comparison function stores these records sequentially.

Again, like most KV systems, the operation interface of LevelDB is very simple, and the basic operations include writing records, reading records and deleting records. Atomic batch operations for multiple operations are also supported.

In addition, LevelDB supports the data snapshot (snapshot) function, so that the read operation is not affected by the write operation, and consistent data can always be seen during the read operation.

In addition, LevelDB also supports operations such as data compression, which is directly helpful for reducing storage space and increasing IO efficiency.

Leave a Reply