Reader small image

You're reading from  Redis Stack for Application Modernization

Product typeBook
Published inDec 2023
PublisherPackt
ISBN-139781837638185
Edition1st Edition
Right arrow
Authors (2):
Luigi Fugaro
Luigi Fugaro
author image
Luigi Fugaro

Luigi Fugaro's first encounter with computers was in the early 80s when he was a kid. He started with a Commodore Vic-20, passing through a Sinclair, a Commodore 64, and an Atari ST 1040, where he spent days and nights giving breath mints to Otis. In 1998, he started his career as a webmaster doing HTML, JavaScript, Applets, and some graphics with Paint Shop Pro. He then switched to Delphi, Visual Basic, and then started working on Java projects. He has been developing all kinds of web applications, dealing with backend and frontend frameworks. In 2012, he started working for Red Hat and is now an architect in the EMEA Middleware team. He has authored WildFly Cookbook and Mastering JBoss Enterprise Application Platform 7 by Packt Publishing.
Read more about Luigi Fugaro

Mirko Ortensi
Mirko Ortensi
author image
Mirko Ortensi

Mirko Ortensi earned a degree in Electronic Engineering and a Master's degree in Software Engineering. Mirko's career has spanned several roles from Software Engineering to Customer Support, particularly centered around distributed database systems. As a Senior Technical Enablement Architect at Redis, Mirko shares technical knowledge about Redis's products and services.
Read more about Mirko Ortensi

View More author details
Right arrow

Using Redis Stack as a Primary Database

In the previous chapters, we have covered most of the topics that concern software architects and engineers at the time of mapping the business logic of an application to the concrete physical data model using Redis. As a professional used to working with relational databases or document stores, you have learned to make the most of Redis using the core data structures and discovered the features delivered in Redis Stack, such as enhanced searches and queries, and working with JSON documents. Modeling entities and relationships with the traditional Hashes or the standard JSON format together with the ability to create indexes on different fields of documents stored in such formats shifts Redis from the realm of caches to that of database management systems (DBMSs).

Redis has long been used as a cache, and the original design encouraged such use, offering real-time performance and a predictable footprint, with efficient expiration and eviction...

Technical requirements

To follow along with the examples in the chapter, you will need to install Redis Stack Server 7.2 or a later version on your development environment. Alternatively, you can create a free Redis Cloud subscription to achieve a free plan and use a managed Redis Stack database.

What is a primary database?

There is no formal definition of what a primary database is and what requirements it should have; the interpretation of what features a primary database should support largely depends on the use case the data store fulfills. However, by looking at how traditional DBMSs are used as primary and often unique solutions in the data layer, we can sketch a few traits:

  • A database can be considered primary when it is the authoritative source of data and stores the most recent copy of data. Secondary databases instead serve read-only workloads, either using the same technology as the primary database (using proprietary master-replica protocols) or as in-memory caches (using methods such as change data capture).
  • A primary database serves mixed online transactional processing (OLTP) workloads, such as searches or scans and lookups, and may have analytical processing capabilities.
  • A primary database is reliable and can stand single software or hardware...

Redis as a primary database

When Redis is deployed in a replicated topology with Sentinel agents or as a Redis cluster, it fulfills the typical requirements of a DBMS in terms of availability and scalability. Redis supports backups and recovery to a consistent state in case of major issues. In terms of hardening, Redis provides user permission management via access-control lists (ACLs), traffic encryption, and additional security features. Tools for benchmarking, monitoring, and auditing a Redis or Redis Stack database are available as well, and together with a rich set of client libraries, the Redis ecosystem integrates with all kinds of software architectures. We’ll discuss the manageability of Redis in scalable and available scenarios in the next chapter and compare the different flavors: open source, Enterprise, and Cloud. In this section, we’ll focus on the discussion around using Redis as an authoritative source of data.

Redis is commonly adopted as a cache to...

The BASE and ACID properties

Grouping the properties of Redis is immediate and serves the purpose of understanding where it fits between the ACID and BASE models. While relational databases usually follow the ACID consistency model, Redis, as a NoSQL real-time in-memory data store with support for replication and scalability, and used as a key-value, data structure, document, and vector store, fulfills the BASE properties. The BASE model does not stand necessarily as a replacement for the ACID model, but suggests the idea that databases may privilege some properties rather than others or blend them in order to excel in specific use cases. Let’s introduce the BASE and ACID properties and discover how Redis fulfills them.

The BASE properties

Let’s examine what the BASE properties are and see why Redis complies with them, as most of the NoSQL databases do. The idea of the BASE properties for distributed systems was presented in 1999 by the computer scientist Eric Brewer...

Configuring Redis for durability, consistency, and availability

For those scenarios where reliability matters besides availability, you can consider the following configurations.

Configuring snapshots

Snapshots (also called Redis database snapshots, or RDBs) provide a consistent binary dump of the data stored in the keyspace and are used to perform data recovery to a specific point in time. You should set the following in the configuration file:

save 900 1000
dbfilename "dump.rdb"

These settings enable snapshots every 900 seconds if at least 1,000 keys have changed. This kind of persistence is good for point-in-time restores and is also considered a backup. So, from time to time, you should copy the RDB snapshot file to an external storage device on a different, possibly remote host (invoking a script with cron, as an example) to discard major incidents affecting the local storage device. This method cannot be considered valid to achieve a good recovery point objective...

Summary

Redis not only can be adopted safely as a primary database in many use cases, but it is also the best option in many terms. Secondary indexing of Hash and JSON documents together with the ability to perform complex and hybrid multi-field queries and with basic analytical processing capabilities makes Redis, Redis Stack, and the commercial Enterprise and Cloud versions full-fledged data management systems with full support for scalability and availability. While NoSQL databases don’t generally fulfill the ACID properties but privilege availability over consistency, we have gone through the assumptions that help maximize the consistency of Redis databases against crashes, either in the standalone or replicated deployments.

Compromising on data integrity, consistency, and durability may not be an option, and in this chapter, you have learned to achieve the most durable configuration in Redis with the safest (but much less performing) AOF persistence policy. You have...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Redis Stack for Application Modernization
Published in: Dec 2023Publisher: PacktISBN-13: 9781837638185
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Luigi Fugaro

Luigi Fugaro's first encounter with computers was in the early 80s when he was a kid. He started with a Commodore Vic-20, passing through a Sinclair, a Commodore 64, and an Atari ST 1040, where he spent days and nights giving breath mints to Otis. In 1998, he started his career as a webmaster doing HTML, JavaScript, Applets, and some graphics with Paint Shop Pro. He then switched to Delphi, Visual Basic, and then started working on Java projects. He has been developing all kinds of web applications, dealing with backend and frontend frameworks. In 2012, he started working for Red Hat and is now an architect in the EMEA Middleware team. He has authored WildFly Cookbook and Mastering JBoss Enterprise Application Platform 7 by Packt Publishing.
Read more about Luigi Fugaro

author image
Mirko Ortensi

Mirko Ortensi earned a degree in Electronic Engineering and a Master's degree in Software Engineering. Mirko's career has spanned several roles from Software Engineering to Customer Support, particularly centered around distributed database systems. As a Senior Technical Enablement Architect at Redis, Mirko shares technical knowledge about Redis's products and services.
Read more about Mirko Ortensi