Alex -


NoSQL database types explained: Key-value store

Learn about the benefits and detriments of utilizing a key-value store -- a simply designed NoSQL database that can potentially improve data processing speeds and scalability.

Modern society collects data to learn, earn, create systems and simplify lives. The technology is at a level where data can be collected simply, and it is improving each day. To facilitate and use the data collected, we store it in databases.

Up until recently, technical constraints made relational (SQL) databases everyone's first choice. With an increasing variety of data types and cheap storing options, we started stepping away from them and looking into nonrelational (NoSQL) databases.

They have been around for a while, but it was only recently that we started utilizing their potential.

NoSQL databases

There are many types of NoSQL databases. They can be divided into four major groups: key-value store, column-oriented, document-based and graph databases. Each of the types suit specific requirements and data types. This article focuses on the key-value store.

What is a key-value store?

This specific type of NoSQL database uses the key-value method and represents a collection of numerous Key-value pairs. The keys are unique identifiers for the values. The values can be any type of object -- a number or a string, or even another key-value pair in which case the structure of the database grows more complex.

Unlike relational databases, key-value databases do not have a specified structure. Relational databases store data in tables where each column has an assigned data type. Key-value databases are a collection of key-value pairs that are stored as individual records and do not have a predefined data structure. The key can be anything, but seeing that it is the only way of retrieving the value associated with it, naming the keys should be done strategically.

Key names can range from as simple as numbering to specific descriptions of the value that is about to follow. A key-value database can be thought of as a dictionary or a directory. Dictionaries have words as keys and their meanings as values.

Phonebooks have names of people as keys and their phone numbers as values. Just like key-value stores, unless you know the name of the person whose number you need, you will not be able to find the right number.

All in the NoSQL family

The features of key-value database

The key-value store is one of the least complex types of NoSQL databases. This is precisely what makes this model so attractive. It uses very simple functions to store, get and remove data.

Apart from those main functions, key-value store databases do not have querying language. The data is of no type and is determined by the requirements of the application used to process the data.

A very useful feature is built-in redundancy improving the reliability of this database type.

Use cases of key-value databases

The choice of which database an organization should apply depends purely on its users and their needs. However, some of the most common use cases of key-value databases are to record sessions in applications that require logins.

In this case, the data about each session -- period from login to logoff -- is recorded in a key-value store. Sessions are marked with identifiers and all data recorded about each session -- themes, profiles, targeted offers, etc. -- is sorted under the appropriate identifier.

With an increasing variety of data types and cheap storing options, we started stepping away from them and looking into nonrelational (NoSQL) databases.

Another more specific use case yet similar to the previous one is a shopping cart where e-commerce websites can record data pertaining to individual shopping sessions. Relational databases are better to use with payment transaction records; however, session records prior to payment are probably better off in a key-value store. We know that more people fill their shopping carts and subsequently change their mind about buying the selected items than those who proceed to payment. Why fill a relational database with all this data when there is a more efficient and more reliable solution?

A key-value store will be quick to record and get data simultaneously. Also, with its built-in redundancy, it ensures that no item from a cart gets lost. The scalability of key-value stores comes in handy in peak seasons around holidays or during sales and special promotions because there is usually a sharp increase in sales and an even greater increase in traffic on the website. The scalability of the key-value store will make sure that the increased load on the database does not result in performance issues.

Advantages of key-value databases

It is worth pointing out that different database types exist to serve different purposes. This sometimes makes the choice of the right type of database to use obvious. While key-value databases may be limited in what they can do, they are often the right choice for the following reasons:

  • Simplicity. As mentioned above, key value databases are quite simple to use. The straightforward commands and the absence of data types make work easier for programmers. With this feature data can assume any type, or even multiple types, when needed.
  • Speed. This simplicity makes key value databases quick to respond, provided that the rest of the environment around it is well-built and optimized.
  • Scalability. This is a beloved advantage of NoSQL databases over relational databases in general, and key-value stores in particular. Unlike relational databases, which are only scalable vertically, key-value stores are also infinitely scalable horizontally.
  • Easy to move. The absence of a query language means that the database can be easily moved between different systems without having to change the architecture.
  • Reliability. Built-in redundancy comes in handy to cover for a lost storage node where duplicated data comes in place of what's been lost.

Disadvantages of key-value databases

Not all key-value databases are the same, but some of the general drawbacks include the following:

  • Simplicity. The list of advantages and disadvantages demonstrates that everything is relative, and that what generally comes as an advantage can also be a disadvantage. This further proves that you have to consider your needs and options carefully before choosing a database to use. The fact that key-value stores are not complex also means that they are not refined. There is no language nor straightforward means that would allow you to query the database with anything else other than the key.
  • No query language. Without a unified query language to use, queries from one database may not be transportable into a different key-value database.
  • Values can't be filtered. The database sees values as blobs so it cannot make much sense of what they contain. When there is a request placed, whole values are returned -- rather than a specific piece of information -- and when they get updated, the whole value needs to be updated.

Popular key-value databases

If you want to rely on recommendations and follow in the footsteps of your peers, you likely won't make a mistake by choosing one of the following key-value databases:

  • Amazon DynamoDB. DynamoDB is a database trusted by many large-scale users and users in general. It is fully managed and reliable, with built-in backup and security options. It is able to endure high loads and handle trillions of requests daily. These are just some of the many features supporting the reputation of DynamoDB, apart from its famous name.
  • Aerospike. This is a real-time platform facilitating billions of transactions. It reduces the server footprint by 80% and enables high performance of real-time applications.
  • Redis. Redis is an open source key-value database. With keys containing lists, hashes, strings and sets, Redis is known as a data structure server.

The list goes on, and includes many strong competitors Key-value databases serve a specific purpose, and they have features that can add value to some but impose limitations on others. For this reason, you should always carefully assess your requirements and the purpose of your data before you settle for a database. Once that is done, you can start looking into your options and ensure that your database allows you to collect and make the most of your data without compromising performance.

Dig Deeper on Database management

Business Analytics
Content Management