most Engineers when they hear about redis they think about cash but redis can be used as a cache a database or even a message broker redis is basically a data structure server because it supports various data structures such as strings hashes lists sets sorted sets bit maps and more and in this video we'll take a closer look at the reason that makes reddish so fast and popular so let's get started [Music] redis stands for remote dictionary server it is an open- Source inmemory data structure store now redis is commonly used as a caching layer to store frequently accessed data in memory reducing the need to fetch data from slow dis based databases and improve application performance imagine you have a web application where users frequently view their profiles fetching this data from a dis based database like my SQL every time can be slow instead you can use radius to cach the user profile data so when a user requests their profile the application first checks redus if the data is in redus it's a cash hit it has returned immediately if the data is not in redus it's a cash miss the application fetches it from the primary database stores it in redes and then returns it to the user the data in redis can have a dtl or time to live so it can automatically expire after a certain time for example say 5 minutes to ensure fresh data is there all the time redes can also function as primary database especially for use cases where speed and low latency are critical imagine you are building a gaming application where you need to maintain a realtime Leaderboard Players scores are constantly updated and you need to display the top 10 players instantly so you can use radi as sorted set data structure to store player scores each player score is added to the sorted set with their ID as the key and the score as the value this automatically sorts the scores so you can quickly retrieve the top 10 players using a single command like this redis can then process this data to disk using rdb or aof to ensure durability a message broker is a system that enables communication between different parts of an application by passing messages redis can act as a lightweight message broker using its pop or public Subscribe Feature so imagine you're building a chat application your users need to receive realtime notifications when someone sends them a message each user subscribes to a red Channel say user 1 123 when a message is sent to a user the application publishes the message to the corresponding Channel redis delivers the message to all subscribers of that channel in real time the client for example a web or mobile app listens for messages on the subscribed Channel and displays them to the user it's simple to set up compared to more complex message Brokers like Kafka or rabbit mq and so if you need fast access to Temporary data use it as a cache if you need real-time data processing and storage use radius as a database and if you need real-time messaging use it as a message broker this flexibility combined with its speed and simplicity is why red is so widely adopted across Industries in fact a single Redd server can handle up to 100,000 queries per second but what makes radius extremely fast understanding the reasons to make it extremely fast will level up your software engineering and system design skills so let's check it out first of all reddish data is all stored in memory which means that our reading and writing of data are all completed in memory in memory storage means that R stores all its data in Ram or Random Access Memory instead of an disk like traditional databases such as MySQL post SQL or mongodb Ram is much faster to read from and write to compared to desk storage here in the diagram at the top we have CPU registers and various levels of cache which are the fastest but have limited capacity Ram sits in the Middle with an access time of around 120 NS making it significantly faster than ssds or hdds which operate in the microsc to millisecond range redus leverages Ram instead of disc storage allowing it to deliver ultra low latency performance compared to traditional databases that rely more mostly on disk based storage not only that radius is also a key value in memory database it internally constructs and hash table this means that when you request a value using a specific key redis can retrieve it in 01 time complexity which is constant time regardless of the data set size and this makes radius extremely fast for lookups as it doesn't need to scan the entire data set like traditional databases that rely on dis storage reders also uses a single threaded event Loop to handle commands this means that radius uses a single thread to handle all client request and perform operations on data commands are executed only one at a time in the order they are received this avoids the complexity of managing logs or risk conditions and since radius is primarily memory bound that is data is stored in the ram the single threaded model is efficient and avoids the overhead of Contex switching now while this is single threaded for command execution it uses non-blocking IO to handle multiple client connections simultaneously non-blocking IO is a way for program to handle multiple tasks without getting stuck waiting for one task to finish since redis uses a single thread to handle all client requests This Thread runs an event Loop which continuously checks for new events for example incoming request or data to send back to clients this allows it to serve many clients concurrently without being being bottlenecked by iio operations this achieves concurrency but it is not parallelism now I have previously made a full video to explain concurrency versus parallelism in detail here please do check it out if you have any doubts the single threaded model used by RIS can however become a limitation in scenarios where the workload is CPU intensive for example complex computations or heavy data processing or if the data set is very large and the single thread model cannot keep up with a volume of request in such cases radius can be scaled horizontally using radius cluster which partitions data across multiple radius instances or by using radius modules to offload specific tasks radius also operates on simple well optimized data structures such as strings bit maps hashes and hyperlock locks since all operations and radies are executed directly in memory they require minimal CPU resources resulting in exceptionally fast performance I'll be diving deep into some of the most important radi data types exploring the use cases and performance characteristics in my upcoming videos so do stay tuned all right the last one redis is written in C which is a low-level language that provides fine grein control over memory and CPU usage it means that redis can manage system resources like memory and CPU very efficiently and precisely for example in C developers can manually allocate and deallocate memory using in functions like Malo and free this allows radius to optimize memory usage radius can allocate exactly the amount of memory it needs and free it when it is no longer needed reducing any waste AG it also avoids overhead because higher level languages like Java often uses garbage collection which can introduce delays and unpredictability C avoids this by letting radies manage memory directly C also allows developers to write code that runs very close to the hardware with minimal overhead this means faster execution because C code is compiled directly into machine code which the CPU can execute without additional layer of interpretation unlike languages like python or Ruby R is can also Implement algorithms in a way that takes full advantage of the CPO capabilities such as using bitwise operations or optimizing for cache locality the combination of find G control over memory and CPU usage along with c's lowlevel nature makes radies extremely fast and efficient as you design and optimize your systems understanding how redes achiev such speed can help you make better architectural decisions if you found this explanation helpful and want to dive deeper into redis its architecture and how you can leverage it in your projects do check out my YouTube video on distributor locking here where I break it down in an easy to understand way in upcoming videos I'll be diving deeper into some of the Redd's most important data types and the real world applications and if you found this video useful please make sure to like subscribe and turn on on notifications to stay updated see you in the next one [Music]