Redis What Why and When

redis what why and when

Redis is an open-source (BSD Licensed), in-memory data store which can be used as messaging broker, application cache, developer database and streaming engine. This high-performance engine supports many different data structures which can help cater to the requirements of a wide variety of use cases and applications. The main Data structures supported by REDIS are

WHAT

REDIS (REmote DIctionary Serve), is an in-memory data store developed by Salvatore Sanfilippo back in 2009. This was developed to scale a real-time log analysis system: LLOOGG. After the basic Redis server started working, they shared it as an open-source project.

Data types supported in Redis

  1. Strings: It can hold text up to 512 MB.
  2. Hashes: A data structure which can hold keys and values.
  3. Lists: A collection of ordered Strings.
  4. Sets: An unordered collection of unique Strings.
  5. Sorted Sets with range queries: Ordered Set by a value associated with a key.
  6. Streams: A data structure that acts like an append-only log. Can be used to record and syndicate events in real-time.
  7. Bitmaps: Data type that allows bit-level operations.
  8. Bitfields: This can be used to operate anything from unsigned 1-bit to signed 63-bit Integers
  9. HyperLogLogs: A probabilistic data structure to estimate the unique items in a data set.
  10. Geospatial Indexes: This lets you store coordinates and search for them

Features

REDIS has in-built replication and provides high availability with REDIS Sentinel and Redis Cluster. Redis Cluster supports automatic partitioning. These features make REDIS a darling for modern applications, which are distributed and have a common caching mechanism.

Redis supports Lua scripting, LRU eviction and transactions.

To achieve high performance, REDIS works with an in-memory dataset. REDIS can periodically persist data to the disk and can act like a database or if we disable “persistence” then the system will work as an in-memory cache that has eviction policies as the user deems.

When working in a distributed system with a master-replica setup, It supports asynchronous replication, with fast non-blocking synchronization and auto-reconnection with partial re-synchronization on net split.

Redis have a plethora of other features as well which are given in the subsequent sections.

As quoted from redis.io “Redis is written in ANSI C and works on most POSIX systems like Linux, *BSD, and Mac OS X, without external dependencies. Linux and OS X are the two operating systems where Redis is developed and tested the most, and we recommend using Linux for deployment. Redis may work in Solaris-derived systems like SmartOS, but support is best effort. There is no official support for Windows builds.

REDIS can be used in a lot of programming languages and the client’s details can be seen by clicking here.

GitHub and Instagram were the first to adopt this technology and in a very short time, it has been adopted and used by big companies as well as a lot of Developers.

REDIS is time tested and now it is getting used by a lot of big brands and names in the market, you can find the details listed by techstacks.io on popular sites using Redis.

WHY

Quoting from AWS “Redis delivers sub-millisecond response times, enabling millions of requests per second for real-time applications in industries like gaming, ad-tech, financial services, healthcare, and IoT. Today, Redis is one of the most popular open source engines today, named the “Most Loved” database by Stack Overflow for five consecutive years. Because of its fast performance, Redis is a popular choice for caching, session management, gaming, leaderboards, real-time analytics, geospatial, ride-hailing, chat/messaging, media streaming, and pub/sub apps.

REDIS is really powerful and for comparison, one use case is given here.

REDIS is running on *kind of* Single Thread and when running on an average Linux machine, it can deliver 1 million requests per second. Damn!!!! That’s fast.

The statement that REDIS runs on Single Thread is a little misleading as there are multiple threads in the picture from REDIS 4. Now, the other threads are limited to deleting objects in the background and using blocking commands implemented.

Why Kind of Single-Threaded REDIS make sense

When we take the wider picture, an application is comprised of multiple components like DB, Application itself, Network, user etc. All these components will take some time to process or to communicate. As this is an in-memory data store, it has the capability of serving more than 1 million requests per second even with an average Linux machine. Since there is more time involved in processing and communication, it looks like a bottleneck in the application from its standpoint of view. Also since REDIS is *kinda* single-threaded, it comes with Atomicity, ease of handling and coding.

Introducing Multi-threaded for handling main commands will make the architecture complex and the current Simplicity will be lost to some extent.

WHEN

When to use REDIS is a decision which the developer/team needs to take after their due diligence. However, here we are listing out a couple of scenarios where it can come into the picture and make an impact.

  1. As a database
  2. As a cache
  3. As a messaging queue
  4. As a session store
  5. Used for fraud detection in real time
  6. Used for smooth gaming experiences
  7. As cache for site autocomplete functions
  8. Can be used for location-based services using geospatial indexes

CONCLUSION

In conclusion, Redis is a powerful and versatile data structure store that can be used in a variety of applications. Its in-memory design, scalability, and support for multiple data structures make it an ideal choice for applications that require fast access to large amounts of data. Whether you are building a web application, a real-time analytics system or a task queue manager, Redis is a technology worth considering.

You can find documentation and more details here.