Redis
Redis
Architecture of Redis
The Redis architecture comprises two primary components: the Redis client
and the Redis server. You can install both the Redis server and client either
on a single machine or on separate devices. Multiple clients can concurrently
connect to a shared server, facilitating the handling of various requests.
Servers bear the responsibility of housing data within memory, subsequently
overseeing all control aspects crucial to the architecture. As such, the Redis
server constitutes a highly significant facet of this structure.
Conversely, a Redis client essentially serves as a Redis console integrated
with a programming language tailored for the Redis API. In this setup, Redis
retains all data within primary memory. However, it's essential to note that
Redis's primary memory is impermanent; hence, restarting the server can
lead to data loss.
Redis provides compatibility with the subsequent storage platforms:
The subsequent illustration delineates two segments: the client side and the
server side.
1. AOF - primarily, enables data preservation by recording all write
operations received from the server.
2. Save the command – Significantly, the "SAVE" command compels the
Redis server to generate RDB snapshots on demand.
3. RDB - entails duplicating all data from memory and storing it in
persistent storage at predefined intervals.
4. Replication is additionally provided to enhance fault tolerance and
ensure data availability. Furthermore, you have the option to augment
storage capacity by grouping two or more servers within a designated
cluster.
The Redis architecture encompasses the following deployments:
1. Single Redis Instance
This represents the simplest way to deploy Redis. It requires users to
configure and operate small instances that facilitate the expansion and
acceleration of their services.'
Nevertheless, it comes with a disadvantage: if this active instance were to
crash or become inaccessible, any requests directed towards Redis would be
unsuccessful. As a result, there would be a decline in the overall system
performance and speed.
2. Redis High Availability (HA)
An alternative widely used arrangement involves a primary deployment
alongside a secondary deployment that consistently mirrors the replication
process.
These secondary instances encompass one or multiple units within our
deployment, facilitating the expansion of read capabilities from Redis.
Furthermore, they offer a failover mechanism in scenarios where the
primary instance becomes inaccessible.
High availability (HA) ensures consistent performance and uptime beyond
the ordinary. Such systems avoid single points of failure, allowing smooth
transitions between primary and secondary components without data loss,
and feature automated failure detection and recovery.
In this topology, various novel factors come into play as we step into a
distributed system realm laden with multiple fallacies that demand
attention. What was once simple now gains intricacy.
Redis Replication
In Redis, each main instance possesses a replication ID and an offset, crucial
for pinpointing a replication instance's progress and enabling sync decisions.
The offset increments with main instance actions.
When a replica is slightly behind the main instance, it catches up by
replaying commands, achieving sync. Mismatched IDs or unknown offsets
prompt full synchronization, where the main instance sends a snapshot to
the replica. Replication resumes once the sync is complete.
Matching ID and offset mean identical data. A replication ID helps infer past
primaries for partial sync after a restart or promotion. Similar IDs and
slightly differing offsets indicate matching datasets. Dissimilar IDs require
full sync unless common ancestry helps perform partial sync based on
previous replication ID knowledge.
3. Redis Sentinel
Sentinel represents a distributed system configuration. It's structured to
encompass a cluster of sentinel processes collaborating to coordinate the
system's state, ensuring uninterrupted accessibility of the Redis system. In
addition to caching, Redis Sentinel offers several other functionalities.