RDB (Real-time Data Base) Persistence Model
RDB is a point-in-time snapshot of the Redis dataset stored as a binary file. The RDB file contains a representation of the dataset at a particular point in time and can be used to restore the dataset in case of a server crash or restart. RDB is very efficient in terms of disk space usage and performance, as it uses a binary format to store the data.
RDB can be configured to save the data periodically or based on certain conditions, such as a minimum number of write operations. However, the downside of RDB is that it can lead to data loss if the server crashes before the scheduled RDB snapshot is taken.
Snapshotting in RDB
Snapshotting is a process in Redis persistence that creates a point-in-time snapshot of the entire dataset in memory and saves it to disk in a binary format. This snapshot can be used to restore the dataset in case of a server crash or restart. Redis supports snapshotting through its RDB persistence mechanism.
The snapshotting process works as follows:
- Redis forks a child process from the parent process.
- The child process creates a copy of the current state of the dataset in memory.
- The child process writes the copy of the dataset to a temporary RDB file.
- The child process renames the temporary file to the final RDB file name, overwriting any existing RDB file.
- The child process terminates, and Redis continues serving requests.
Redis can be configured to perform snapshotting automatically at regular intervals or based on certain conditions, such as a minimum number of write operations or a minimum amount of time elapsed since the last snapshot. If we are doing heavy work and changing lots of keys, then a snapshot per minute will be generated for us, in case changes are relatively less, then a snapshot per 5 minutes, and if it’s further less, then every 15 minutes a snapshot will be taken.
Advantages of RDB(Real-time database)
- RDB files are perfect for backups, as it is a very compact single-file point-in-time representation of the redis data. It allows us to easily restore different versions of the data set in case of disasters.
- It is very good for disaster recovery, being a single compact file that can be transferred to far data centers.
Disadvantages of RDB(Real-time database)
Let us now take a comparative look at the Disadvantages of Redis DB:
- RDB is not optimal.
- If we need to minimize the chance of data loss in case Redis stops working.
- We can configure different save points where an RDB is produced. However, we will usually create an RDB snapshot every five minutes or more, so in case of Redis stops working without a correct shutdown for any reason, we should be prepared to lose the latest minutes of data.
Redis and its role in System Design
Redis is an open-source, in-memory data structure store used as a database, cache, and message broker. It is widely used for its fast performance, flexibility, and ease of use.
|