<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Surbhit Lamba on Medium]]></title>
        <description><![CDATA[Stories by Surbhit Lamba on Medium]]></description>
        <link>https://medium.com/@surbhit.lamba?source=rss-2138f0581d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*l--fGW8Qg8wOc9GP8-hOMA.jpeg</url>
            <title>Stories by Surbhit Lamba on Medium</title>
            <link>https://medium.com/@surbhit.lamba?source=rss-2138f0581d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 20:04:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@surbhit.lamba/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Learn To Cache With Me]]></title>
            <link>https://medium.com/@surbhit.lamba/learn-to-cache-with-me-817a9d84cddc?source=rss-2138f0581d------2</link>
            <guid isPermaLink="false">https://medium.com/p/817a9d84cddc</guid>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[caching]]></category>
            <dc:creator><![CDATA[Surbhit Lamba]]></dc:creator>
            <pubDate>Mon, 22 Jun 2020 05:59:57 GMT</pubDate>
            <atom:updated>2020-06-29T13:19:13.239Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learn To Cache With Me — Redis</h3><figure><img alt="Redis Text" src="https://cdn-images-1.medium.com/max/1024/0*LkY9vaR57ZYQ6yFG.png" /><figcaption>Redis Official Logo</figcaption></figure><p>If you’ve ever been lucky enough to be there when a web product is launched, you’ll know that generally in the beginning, the server has to handle less traffic. But what happens after the product gets popular, and the traffic increases? It leads to huge number of heavy requests on your Database. Either you’ll have to increase the resources of your infra (SPOILER : HIGH COST AND STILL HIGH RESPONSE TIME) or you could try CACHING!!</p><h4>What Is Caching?</h4><p>A cache is a high-speed data storage layer which stores a subset of data, typically transient in nature, so that future requests for that data are served up faster than is possible by accessing the data’s primary storage location. Caching allows you to efficiently reuse previously retrieved or computed data so that your database doesn&#39;t have to perform the same task again and again.</p><h4>What Are My Options?</h4><p>There are many cache stores which can be useful in multiple use cases like Redis, Memcached, Hazelcast, Couchbase etc. The main differences between them are based on many aspects like performance, supported data-structures, persistence options and many more. Here we will be talking about the most popular cache store these days.</p><p><em>…ENTER REDIS…</em></p><blockquote><strong>Redis</strong> is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.<br>It supports various data structures such as Strings, Hashes, Lists, Sets etc.</blockquote><h4>But What Does It Mean?</h4><p>Redis is a really <strong>fast</strong>, <strong>in-memory</strong>, <strong>Key-Value Store</strong> type of <strong>NoSQL</strong> Database. All Redis data resides “in-memory”, in contrast to databases that store data on disk or SSDs. By eliminating the need to access disks, in-memory data stores such as Redis avoid seek time delays and can access data in microseconds hence decreasing the RESPONSE TIME.</p><h4>What Are Some Great Use-Cases For Redis?</h4><p>As the definition says, redis can be used as a database, cache and message broker. Top use-cases for the same are:</p><ul><li><strong>Full Page Cache</strong>: Despite being capable of dynamically generating content, the majority of pages that are served on a website don’t change much on a regular basis. It is your job to stop generating the same content every time and cache it. By reducing the amount of time spent on generating static content, you can reduce the number of requests on your database and hence reduce the servers necessary to handle the same load, and can serve the site faster.</li><li><strong>Session Cache: </strong>One of the most common use-case is the session caching. A Session is an important part of web applications these days. There are multiple needs of storing different user level data as session cache for improving the overall experience. Redis offers an additional feature of OPTIONAL PERSISTENCE which is an advantage over session stores such as Memcached. Optional Persistence helps to persist data for a need basis time or even forever.</li><li><strong>Counting and Leaderboards: </strong>An amazing aspect of redis features is the increment and decrement functions along with the sets and sorted sets which make it very easy to bring up numeric stats. One can easily implement this feature for working on score ranges and putting constraints on limits etc. The possibilities are huge.</li><li><strong>Publisher/Subscriber: </strong>This is one of the least used but offers a lot. Redis has the ability to publish messages that are characterised into channels for the subscribers. Subscribers can subscribe to particular channels for the required data. Social Network triggers and chat systems can be implemented using this feature.</li><li><strong>Message Broker:</strong> Applications that deal with messaging, traffic congestion, data gathering, job management can use a Redis Queue. Redis as a message broker uses streams to communicate and maintain persistent queues between services.</li></ul><h4>What Type Of Redis Is Best Suited For Me?</h4><p>Based on the your application needs there are 4 main types of topologies that redis offers. Before choosing one of them you need to understand all the features they provide.</p><ul><li><strong>Redis Standalone: </strong>This is the most basic type and can be basically considered as one big RAM. It can be <strong>scaled vertically</strong> <strong>only</strong> i.e. you can only add more resources to the single server to make it more powerful. <strong>It doesn’t provide availability or resilience </strong>(the capacity to recover quickly in case of server failure).</li><li><strong>Redis Replicated:</strong> In this case there is a <strong>master</strong> and there are <strong>replicas</strong>. The replica nodes do not communicate between themselves. These replicas are read-only and <strong>only the master pushes data on them</strong>. Replicated Redis has a great advantage that you always have a <strong>hot snapshot</strong> of your master data. It also provides <strong>manual Resilience</strong> as one has to manually change the master node and restart the clients in case of server failure.</li><li><strong>Redis Sentinel: </strong>Redis Sentinel solves the problem of manual resilience in replicated redis. It is a <strong>monitoring system</strong> which keeps check if the master node is healthy or not, and which node will become the master if the current master fails. But what if the sentinel is lost. That’s why sentinels are always used in clusters with built in election system, which can identify the present master and the next master if the present one fails. So the sentinels are resilient as well. <strong>Overall Redis Sentinel provides all the features of a Replicated Redis with the addition of Resilience.</strong></li><li><strong>Redis Cluster: </strong>This is the most powerful type. It provides with <strong>resilience</strong> as well as with <strong>high scaling </strong>and<strong> availability </strong>. It provides a way to partition(shard) data over multiple nodes. When a value of a key ‘testKey’ is SET in redis cluster, first hash of testKey is calculated and the bucket number is generated. Then, if the current node is the master of that bucket, it accepts the operation with OK otherwise it answers MOVED with a destination master node where the SET function should be run again. <strong>So basically in a Redis Cluster the data is divided in multiple nodes which provides us better availability. In case of a node failure, other nodes will keep on serving and only a fraction of data will be in danger which can also be handled by replicas.</strong></li></ul><p>Based on scaling, availability and resilience requirements an appropriate redis model can be chosen.</p><p>So that was an introductory part on the need of redis and what all it can do.</p><blockquote>Redis has become very popular in the industry these days because of all the great features it offers and has clients and support with great documentation available for a lot of programming languages(OPEN SOURCE OF-COURSE :p). A lot of tech giants like Stack Overflow, OYO, Airbnb, Github, Uber, Twitter are using it today. <br>Overall, Redis is cool.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=817a9d84cddc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>