Most uses of Redis will focus more on latency and availability rather than consistency - that’s because at its core, Redis is essentially a cache. Generally speaking, you store things in Redis in memory and you update or read them extremely quickly. You need to make sure that the cache is always available, so in most cases you’d only choose Redis if you’re leaning towards an A class system (A for Availability) rather than a C class system (Consistency).
However, it’s important to know that a replicated instance of Redis is capable of giving you different levels of consistency up to and including read-after-write consistency - the kind of consistency that guarantees data reads from anywhere that happen after a successful response to a write will receive that write. Even if the read goes to a different replica than the write did. What Redis can’t give you is linearizability - the guarantee that any set of observers of the system will only be able to see a single copy of the system at any point in time. Redis doesn’t offer distributed transactions out-of-the-box and therefore can’t provide this along with a replicated instance. And if the instance is NOT replicated but is sharded, then linearizability can only be achieved for writes to the same machine.
The way to get read-after-write consistency with a replicated Redis distribution is to:
1.) enable WAIT, and specify all replicas - this means writes will not succeed on the client side until all replicas have received the write and responded successfully.
2.) enable AOF and set it to ‘always’ - Append Only File means that writes will be pushed to a file using a fast algorithm. Always means that every single write will hit that file on disk.
These settings trade availability almost entirely for as much consistency as Redis can offer - if any replica is down, NO writes can go through. Though reads could still succeed for some users. However, considering that you still can’t get linearizability, there’s only a narrow swath of applications that would be best served by this configuration in Redis.
Nonetheless, it’s possible, and adds another degree of flexibility to Redis.
Comments
Post a Comment