1. When to use key-value databases
In this lesson, we are going to discuss when key-value databases are suitable and when not.
2. Suitable cases
Let's start with some scenarios where key-value databases are a good fit.
Websites store data of user sessions. Key-value databases can store this information
using the session identifier as the key
and all the information about the session in the value.
3. Suitable cases
Websites frequently store user profiles and user preferences, as we saw in lesson one, in the example of Datazy.
The key can be, for instance, the user identifier.
The user profile information and user preferences can be stored in the value within a single object.
4. Suitable cases
Key-value databases are also suitable for storing the data of shopping carts.
The key can be the user identifier,
and the value can be all the shopping cart information.
5. Suitable cases
Key-value databases also fit well with real-time recommendations. For example, when a person visits a commercial web page, the key-value database can present new items that the user may like.
6. Suitable cases
And finally, advertising. Key-value databases can help to show advertisements quickly while the user navigates throughout a web page.
7. Suitable cases
They all have in common that they store the information as the value in a single object.
This information could be saved just with one operation, for example, with this SET command if we used the Redis database. User, colon, 457, colon, preferences would be the key, and the rest would be the value.
Consequently, this information could also be retrieved with another operation, the GET command in this example.
This simplicity makes it very fast.
8. Unsuitable cases
By contrast, there are some situations where key-value databases are not a good option.
When there is a need to search a key based on its value, key-value databases are not typically an option. Key-value databases don't search by value, although as we saw in the previous lesson, some products support these kinds of advanced options.
9. Unsuitable cases
A typical example where we would like to retrieve a key based on a value could be when retrieving all the users who live in New York City.
Also, if your data has to be related to other data, key-value databases would not be the best fit.
10. Let's practice!
Let's practice what you have learned!