Key Value Database FAQs
What Is Key Value Database?
A key value database or key value store is a row-based associative array with a core data model comprised of key-value pairs. The database index is called a key and data stored as values. Each key is associated with only one value.
An arbitrary string such as a hash, URI, or filename represents the key in each key-value pair. The value can be any sort of data structure, such as an image, user preference file or document. This paradigm requires no upfront schema definition or data modeling yet handily stores massive amounts of data.Key value databases can improve performance by eliminating the need to index data, but do not allow users to filter or control returns from requests. Key value stores offer a simplicity that delivers a rapid, flexible, scalable option. Using simple get, put, and delete commands rather than a query language, they are easy to use.
Key Value Database Examples
Examples of key value databases include:
- Amazon DynamoDB*
- Apache Cassandra*
- Riak KV
While Cassandra, DynamoDB, and ScyllaDB can be used as a simple key value store, they are technically known as wide column databases, which use a “key-key-value” mechanism, with the first key used for partitioning the data — a partition key — and a second key, called a clustering key or sort key, to order data rows within a partition.
Key Value Database Use Cases
Key value database applications vary. Key-value use cases often include many (though not necessarily all) of the following attributes:
- Data is denormalized: data elements can be duplicated across many rows
- Relatively simple data models: no table JOINs or foreign keys used in complex relational database (RDBMS) models
- Simple schema or schemaless: loose schema or no set schema (each row is somewhat or very different)
- High throughput: the simple data model of a key-value allows many operations per second
- Low latencies: the simple data model of a key-value lends itself to fast reads and writes
- In-memory caches: data is stored in RAM and is either not stored persistently, or only occasionally stored/persisted to disk.
Several use-cases arise that make a key value database an optimal choice.
When to use a key-value database:
Real-Time Session Management: Gaming and Finance
Key value databases are ideal when real time random data access is needed, for example in finance or gaming to generate user session attributes during large-scale session management in an online application. Many small, continuous reads and writes in an application can add volatility. Key value databases naturally offer fast reads and writes and rapid in-memory access.
Session Store: E-Commerce
Key value databases are ideal for storing basic e-commerce customer information, such as customer details, product categories, shopping-cart contents, and e-commerce product details. Personalized ads and real-time recommendations are often powered by key-value stores that follow a user moving through a site and respond by quickly accessing and presenting new ads and recommendations. Key-value databases can also handle the loss of storage nodes thanks to built-in redundancy.
A session-oriented application begins a session when a user logs in and remains active until the session times out or the user logs out. Each user session has a unique identifier, and session data may include user details, personalized data and themes, messages, targeted promotions, recommendations, and discounts.
Better Performance: All Verticals
Key-value databases can be a good choice for performance-sensitive use cases. Key-value stores are often used for in-memory data caching to accelerate application responses. This in memory key value database caching mechanism for configuration based on keys or frequently accessed data is ideal for applications that don’t need to support complex queries or require frequent updates.
What Is Key Value Database?
Key value databases deliver several important benefits related to reliability and scalability. Some common advantages include:
- Achieve outward scalability by implementing partitioning, replication, and auto recovery.
- Since they use denormalized data, key-value stores often scale with the number of nodes almost linearly.
- Key-value databases manage size well and effectively process constant read/write operations with low latency. This makes them ideal for high-scale session management, user information stores, product recommendations, personalized advertising, and caching.
- High flexibility, and ability to manage more data without traditional structures.
The disadvantages of key value databases include:
- Key-value databases are optimized only for one key and value.
- No standard query language.
- No ability to filter value fields.
- Key-value databases are not optimized for lookup which impacts performance.
- Not compatible with SQL.
- No rollback ability in the event of a key saving failure.
What Is Key Value Database?
Here are some important distinctions between key value databases and other types.
Key-value databases and the better known relational databases (RDB) are very different functionally. Relational databases have a predefined data structure with well defined data types in a series of tables and fields. The database program can optimize the various data types in various ways.
In contrast, the data in key-value systems is a single opaque collection, and each record may have a different field. This more closely follows modern programming concepts and offers considerable flexibility. And unlike most RDBs which represent optimal values with input parameters or placeholders, key-value databases can often store the same database with far less memory, facilitating major gains in performance and lower per-page overhead than relational databases.
Key-value databases are one of four primary types of NoSQL databases (alongside wide column, document, and graph).
Wide Column Databases and Key-Value Databases
The difference between key value databases and wide column databases is that the wide column database defines values in key value pairs by mapping keys to columns of related data. Each pair is essentially a row.
Key-Value Database vs Document Database
The difference between key value and document database rests in data processing methods. A document-oriented database relies on the document’s internal structure to extract metadata for further optimization. In a key-value store, the data is inherently opaque to the database.
Key-Value Store Vs Cache
A cache stores a pool of read data transparently for later, quick access to improve performance on future data requests. Because it can return a value for a specific key, a cache is sometimes compared to a key-value store.
Data stored in a cache can be a copy of data stored on disk or precomputed values. A request for data stored in the cache is called a hit, and the application serves the request rapidly by reading the cache. A request for data not stored in the cache is called a miss, and this results in a delay as the requested data is retrieved from its original source or recomputed.
There are differences between key-value stores and caches. Key-value databases function on their own, and when there is a need to increase read performance, caches might be used with a database. Yet caches cannot themselves enhance write or update performance or offer resiliency to server failure.
For more information on caches, download this whitepaper on why you shouldn’t put an external cache in front of your database.
Does ScyllaDB Offer Solutions for Key Value Databases?
The fastest key value databases are typically designed for performance of key-value stores at scale. Evaluate these solutions based on latency, availability, throughput, and scalability of storage (LATS). The best key value databases score well in each area, and ScyllaDB delivers across all of them.
Compatible with both Apache Cassandra and DynamoDB, ScyllaDB is built on a modern NoSQL database architecture designed from its inception for high availability and superior performance while offering significant advantages over other databases.
ScyllaDB supports the persistent SSTable storage format, CQL commands and drivers, high availability model, and ring architecture users demand from Cassandra. Unlike Cassandra, ScyllaDB was written in C++ using the Seastar framework, taking full advantage of low-level Linux primitives, avoiding Garbage Collection (GC) stalls, and providing highly asynchronous operations. ScyllaDB offers unique features like Workload Prioritization and Incremental Compaction that extend its capabilities beyond Cassandra.
As a key-value database, ScyllaDB runs over the same HTTP/HTTPS style connection and supports the drivers and JSON-style queries that DynamoDB does. ScyllaDB can even use maps to simulate a schemaless model. Yet ScyllaDB can run on-premises or on any cloud platform, and users are not locked-in to one cloud provider. ScyllaDB Cloud also offers a fully managed database as a service (NoSQL DBaaS) solution.
Learn more about ScyllaDB here.