Key-Value Store vs Storage Engine
Tags: kvs, speedb, storageengine, rocksdb
Published: 2023-12-19 09:55:06

As data management and storage solutions evolve, it's imperative to understand the different technologies available. In the domain of data storage, key-value stores and storage engines are both major players. While these terms might sound similar to some, there can often be confusion surrounding their definitions and functionalities.

So what are the differences between a key-value store and a storage engine? 

‍

### Key-value store‍

A key-value store is a simple and flexible data storage paradigm that organizes data in a straightforward manner. It revolves around a key-value pair, where data is stored and accessed based on a unique key. Key-value stores offer excellent scalability, fast read/write operations, and flexible schema-less data modeling. They are widely used for caching, session management, user preferences, and other scenarios that require efficient data retrieval based on unique keys. Key-value stores include popular solutions like Redis and Memcached. 

Key value stores usually support basic operations such as put, get, set, and delete. 

Example:

![key-value](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7um9y3uaw8a4n45vistr.png)



### Storage engine: 

A storage engine, also known as a data engine, is a software component that interacts with the underlying hardware or file system to provide efficient and reliable data storage and retrieval capabilities.  A storage engine is an extension of the key-value store. It also organizes data in key-value format but supports an extended set of operations and formats. 

Storage engines handle the low-level details of data organization, indexing, and I/O operations, providing efficient storage and retrieval mechanisms. It can be tailored to different data models, such as document-oriented, columnar, or graph databases, and is often integrated with higher-level database systems. The main capabilities that differentiate storage engines from key-value stores are transaction support, snapshots, and the fact that the elements are ordered. 

For example, S3 (Simple Service Storage) by Amazon, is a cloud storage service that implements a key-value store scheme. It can provide an object per a given key but it doesn’t support range queries. In other words, for a given key it can return the object but it can’t return the next object since the elements are not ordered. 

A very common usage of a storage engine is in a database management system and it is used to create, read, update, and delete data from a database (CRUD).

A storage engine serves as the underlying engine that interacts with the DBMS, translating high-level commands into low-level data operations. It determines how data is structured, indexed, and organized, ultimately impacting the performance, reliability, and functionality of the database system.

![storage-engine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1c27x99a4sovfirzcmsv.png)

Storage engines can be implemented using different data structures such as B-tree and LSM.
Some popular storage engine examples are InnoDB, MyISAM, Speedb, RocksDB, and WiredTiger.

Different storage engines have different characteristics that make them more or less suitable for different use cases. For example, RocksDB uses an LSM tree since it’s optimized for write-intensive workloads. InnoDB on the other hand, is based on B-tree to better support read-intensive workload and range queries. 

Key value store and storage engine can both be used as embedded components. 


### Embedded or standalone?
‍
Since a storage engine and key-value store can be used for different purposes they can, and sometimes should be embedded in the application’s software stack. When it’s embedded it becomes a part of the application that can be replaced when you find a substitute that is more suitable for your needs. Look at this as outsourcing specific operations at your office. You don’t need to use your employees for IT services, you can use external companies to do it. Another popular example of using embedded KVS is Apache Flink. It uses RocksDB for storing states in a key-value format. RocksDB can be replaced with any other compliant storage engine in order to support heavy write workload/reduce write amplification or solve any other issue it might have. 


While storage engines can only be embedded, there are some key-value store databases that are used as standalone applications, such as Redis. A storage engine needs an application to reside in it, and the application interacts with the storage engine. 

## So What are the differences between a Storage Engine and a Key Value Store?
‍
**Stand-alone vs embedded:**
While a key-value store can refer to a stand-alone application, a storage engine must be embedded in another application. 


**Functionality:**
A key-value store is mostly used for simple operations such as get and set while a storage engine has more data management capabilities such as transactions, snapshots, and iterators:


**Transactions:**
Transactions are very important to ensure consistency of the data when multiple operations are being performed at the same time. Also, it allows recovery from a situation where there is inconsistency in the data.


**Snapshots: **point-in-time view of the data, allowing users to access and query the data as it existed at the time the snapshot was taken, regardless of subsequent modifications. Snapshots are useful for various purposes, such as creating consistent backups, facilitating data versioning, and enabling point-in-time analysis. Most of the key-value stores do not support snapshots, since the main focus is on simplicity, performance, or specific use cases where snapshot functionality may not be a primary requirement,

Storage engines on the other hand, commonly support snapshots as a fundamental feature. A snapshot in the context of storage engines refers to a point-in-time copy of the data, providing a consistent view of the database or file system as it existed at the time the snapshot was taken.


**Organized data:**

The data in the storage engine is organized in a way that we can not only find an object but also the next object since the data is structured and organized. This cannot be said for every key-value store. 

‍
Here is a table that summarizes the major differences between KVS and storage engine: 

![kvs-vs-storage-engine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rr2bvb5kaj9x3yoc4pqu.png)

### Thus, what is Speedb?
‍
Speedb is an embedded key-value storage engine that writes the data in a key-value format. It can be used as an embedded key-value store in any application as well as a storage engine, since it supports all the unique capabilities storage engines support, such as transactions, snapshots, and the elements are in order, supporting range query operations. 

Since Speedb is fully compatible with RocksDB and LevelDB, it can be replaced easily. What are the benefits of it? Well, this is for another blog post. In the meantime, you can read more about Speedb innovation [here](https://www.speedb.io/blog-posts/boosting-your-application-with-speedb) 


### To summarize: 
A storage engine is an extended implementation of a key-value store. It is used as an embedded component, the same as KVS, and can manage data and metadata efficiently. 

Key-value store primarily addresses the question of "how" data is stored and the format of its structure, while the storage engine pertains to the question of "what" can be accomplished with the data. In other words, the storage engine handles the diverse data operations, while the key-value store serves as a specific means of organizing and storing the data.

Storage engines implement key-value data structure but sometimes this model is extended to serve other applications needs.