Durable Redis
What is data persistence?
When something persists, it lasts. In the context of databases, that means you intend for a piece of information that is going to be saved in some way (in memory or on disk) for some period of time, so that it can be recovered even if a computer process is killed. With data persistence, existing data from an application stays intact between sessions, preserving it for use in a following application session without suffering data loss. Data persistence is particularly essential in the event of a server restart, because data stored only in-memory is gone when the power flickers.
Data persistence options
Redis Enterprise is a fully durable database that serves all data directly from memory, using either RAM or Redis on Flash. With regards to persistent data, Redis only reads this data when both the primary and secondary shards in a high-availability database are lost.
Redis supports append-only file data persistence (AOF) as well as snapshotting. It is also possible to use both RDB and AOF together, known as “hybrid persistence” to take advantage of the strengths of both options. Lets dive into to each of the Redis data persistence options below with further explanation and more detailed information about the strengths and weaknesses of each.
Append-only file data persistence for data durability
Append-only file (AOF) is a logging mechanism that writes to a log file on disk every write operation performed on a Redis database. The log file is used to reconstruct the database in the event of a crash or failure.
AOF works by appending each database write operation to the end of the log file, hence the name append-only file. When Redis restarts, it reads the log file and re-executes the write operations preserved in the file to restore the database to its previous state.
AOF provides better data durability than the snapshot persistence option, creating only point-in-time data snapshots.
Redis uses a multi-part AOF mechanism, wherein the original AOF splits into base and incremental files. The base file represents an initial snapshot of the data present when the AOF is written. The incremental files contain changes since the last base AOF was created.
You can configure AOFs to be rewritten in the background when it gets too large, using a process called AOF fsync. The fsync configuration directive controls how often the AOF log file is synchronized to disk.
The latest AOF mechanism implementation reduces the memory consumption and the amount of I/O operations that are performed during an AOF rewrite.
Snapshot
A snapshot is a point-in-time copy of the Redis data stored in memory. Snapshots are created using the Redis DataBase (RDB) persistence option, which allows the state of the Redis database to be saved to disk at specified intervals.When an RDB snapshot is taken, Redis creates a child process to perform the snapshotting, allowing the main process to continue serving requests.
Snapshots are useful for creating backups of the Redis database, as well as for migrating data between Redis instances. They can be created manually using the ‘SAVE’ or ‘BGSAVE’ command, or automatically using the ‘save’ configuration directive in the Redis configuration file.
It is important to note that while snapshots allow the data in Redis to be persisted to disk, they do not provide the same level of data durability as the AOF persistence option. AOF writes every write operation performed on the Redis database to a log file on disk, which can be used to reconstruct the database in the event of a crash or failure.
Snapshots vs. backups
Snapshots and backup are designed for two different things. While snapshot supports data durability (i.e. to automatically recover data when there is no copy of the dataset in memory), backup supports disaster recovery (i.e. when the entire cluster needs to be rebuilt from scratch).
Data availability vs. durability
Data durability refers to the ability of data to remain stored and accessible over a period of time, even in the face of various types of failures or disasters. Data availability, on the other hand, refers to the ability of users to access and use the data when needed.
Data availability involves designing systems and processes that allow users to access and use the data when needed. This can involve desinging systems with high uptime and fast response times, as well as implementing failover and load balancing mechanisms to ensure that the data is alaways available to users, even if some of the systems fail.
For a data center, availability is an important metric as is durability. A data center will support persistence by using redundant storage systems, such as storage are networks (SANs) or network-attached storage (NAS) systems. These systems provide multiple copies of data, so that if one copy becomes unavailable, there are other copies that can be accessed.
See our blog Data Durability and Availability for more information on this topic.
Ephemeral vs. persistent storage
In cloud native deployments such as a public cloud, private cloud, or virtual private cloud, ephemeral (instance) storage cannot be used for data durability purposes.
What is ephemeral storage?
Ephemeral storage, or volatile temporary storage, disposes of data once its corresponding container reaches the end of its lifespan.
Instead, a network-attached storage (NAS) like Amazon Elastic Block Store (EBS), Microsoft Azure Disk Storage, or Google Cloud Platform Persistent Disk is required. That’s because, just as it sounds, ephemeral storage is ephemeral! When a cloud instance fails (which is relatively common), the contents of its local disk are also lost.
What is persistent storage?
Persistent storage, also known as non-volatile storage, refers to any storage device capable of keeping data intact and available when it is no longer powered on.
Persistent storage is useful for maintaining critical data and making it available for later use. A hard disk drive is a common example of a persistent storage device.
The Redis Enterprise cluster is designed to work with network-attached storage for persistent data. By default, every node in the cluster is connected to a network-attached storage resource, making the cluster immune to data-loss events such as multiple node failures with no copies of the dataset left in DRAM. This data durability-proven architecture is illustrated here: