Advantages and limitations of key-value databases

1. Advantages and limitations of key-value databases

Welcome back! Now that we're up to speed with the terminology, it is time to deepen our knowledge by studying the advantages and limitations of key-value databases.

2. Advantages - very simple

Let's start with the advantages. Key-value databases are very simple. As we learned in lesson one, we just need a key and a value to form a key-value tuple. There is no need to define a schema, and there is no need to determine the types of keys and values. There are three basic operations to work with a key-value database; Put, Get, and Delete. Put inserts a new key-value tuple or updates a value if the key already exists. Get returns the value by a given key. And finally, Delete removes a key and its value if the key exists. This simplicity leads to fast operations.

3. Advantages - flexible

Key-value databases are very flexible. They allow data types to be changed. Let's suppose that we first assigned this number to this key, and we later decide to change the value to this string. Key-value databases won't typically complain about type changes, as opposed to relational databases. In the same way, we can also add additional information to a given key. In this example, we only have the language as the value, but then, we can add the color and the timezone.

4. Advantages - information stored in memory

Many key-value databases store the information in memory, so reads and writes will be faster than writing to a disk. However, we can lose the data, for example, if the machine suddenly shuts off. That is why some key-value databases combine data persistence on disk and memory, so they take advantage of both types of persistence.

5. Advantages - scalability

In terms of scalability, key-value databases can scale horizontally by using sharding. This technique is outside the scope of this course, but basically, sharding distributes

6. Advantages - scalability

different parts

7. Advantages - scalability

of the data

8. Advantages - scalability

across multiple servers.

9. Limitations

Key-value databases have some limitations. We can only search a value by its key, so we will have a problem if we don't know the key we want to find. Some key-value databases have added extended functionalities to avoid this problem. They can search by value and create secondary indexes to specific value attributes. Some key-value databases can even search by multiple keys simultaneously. However, these queries will not be as complex as we can find when using a relational database. For instance, relational databases allow us to join multiple tables, which enables us to connect data.

10. Let's practice!

Great job! Let's take some exercises before studying the scenarios where key-value databases are suitable.