Fastness of Redis

Question:- What is Redis ?

Answer → Redis is a very popular In-Memory database and most loved database amongst developer community because of following reasons :-

  • It’s rock-solid.

Question:- Why is Redis so fast ?

Answer → Here are the reasons of Redis being so fast :-

Reason #1.) The first reason Redis is fast is because : It is an In-Memory database.

Reason #2.) Memory-Access of RAM is several orders of magnitude faster than random disk I/O.

Reason #3.) Redis is primarily Single-Threaded.

Question:- Why are the benefits of Pure-Memory access ?

Answer → Pure memory access provides :-

  • High Read & Write Throughput.

The trade-off is that, the dataset can’t be larger than the RAM memory.

Question:- From the coding prospective, accessing which option is better ?

Answer → Code-wise, In-memory data-structures are much easier to implement than On-Disk counterparts.

This keeps the code simple and it contributes to Redis’s rock solid stability.

Question:- Why would a Single-Threaded design would lead to high performance ? Would not it be faster, if it uses threads to leverage all the CPU-Cores ?

Answer → There are following reasons that Multi-threaded is not so fast :-

  • Multi-threaded applications require Locks Or Other Synchronisation mechanisms. They are notoriously hard to reason about.

Question:- How does a single threaded codebase handle many thousand of incoming requests and outgoing responses at the same time ? Would not a thread gets blocked, waiting for the completion of each request individually ?

Answer → This is where, I/O multiplexing comes into the picture.

  • With I/O Multiplexing, the Operating-System allows a single thread to wait on many socket-connections simultaneously.

Question:- On LINUX Operating-System, how does this I/O Multiplexing happens ?

Answer → On Linux-System, epoll is the performant variant of I/O Multiplexing that supports many thousand of connections in constant time.

Question:- Are there any drawbacks of the Single-Threaded Design ?

Answer → It doesn’t leverage all the CPU cores available in modern hardware and therefore, For some workloads, it is quite common to have several Redis Instances running on a single server to utilise more CPU Cores.

Question:- Are there other Redis Compatible Servers ?

Answer → Yes, this is true :-

  • There are attempts at implementing new Redis Compatible servers to squeeze more performance out of a single-server.

That’s all in this document. If you liked reading it, then do clap on this page. We shall see you in the next document.

--

--

Software Engineer for Big Data distributed systems

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store