<?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 Jay Limbasiya on Medium]]></title>
        <description><![CDATA[Stories by Jay Limbasiya on Medium]]></description>
        <link>https://medium.com/@jaylimbasiya.work?source=rss-ea0deceda76e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GdnYjOY76GVKQu1J</url>
            <title>Stories by Jay Limbasiya on Medium</title>
            <link>https://medium.com/@jaylimbasiya.work?source=rss-ea0deceda76e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:18:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jaylimbasiya.work/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[Redis Beyond Caching: Data Structures and Their Real-World Use Cases]]></title>
            <link>https://medium.com/@jaylimbasiya.work/redis-beyond-caching-data-structures-and-their-real-world-use-cases-c27c0624091a?source=rss-ea0deceda76e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c27c0624091a</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[Jay Limbasiya]]></dc:creator>
            <pubDate>Mon, 17 Aug 2026 05:24:56 GMT</pubDate>
            <atom:updated>2026-08-17T05:24:56.221Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Part 2 of Redis in Real Applications: a simple guide to choosing strings, hashes, lists, sets, sorted sets, streams, and more.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irNKfkjkjB6kZMxphYBMxA.png" /></figure><p>When people first learn Redis, they usually hear one sentence:</p><blockquote><em>Redis is a fast in-memory cache.</em></blockquote><p>That is true, but it is incomplete.</p><p>Redis is also a data structure server. Instead of giving us only key-value strings, it provides structures that match common application problems. We can store a counter, represent a user session, find mutual friends, build a leaderboard, schedule delayed work, process events, search nearby locations, or estimate unique visitors.</p><p>The important skill is not memorizing every Redis command. It is learning how to translate an application requirement into the right data structure.</p><p>This article provides that map.</p><h3>Start with the access pattern</h3><p>Before choosing a Redis structure, ask what the application needs to do with the data.</p><ul><li>Do I need one value or an atomic counter?</li><li>Do I need multiple fields inside one object?</li><li>Is order important?</li><li>Must every member be unique?</li><li>Does each member need a score?</li><li>Do events need acknowledgement and replay?</li><li>Is an approximate answer acceptable?</li></ul><p>The answers usually point toward the right structure.</p><h3>1. Strings: values, counters, and temporary state</h3><p>A Redis string is the simplest structure. It can store text, serialized data, bytes, or a number.</p><pre>product:42        -&gt; serialized product data<br>page:home:views   -&gt; 15482<br>otp:challenge:91  -&gt; hashed OTP</pre><p>Strings are useful for:</p><ul><li>Cached values</li><li>Atomic counters</li><li>Rate limiting</li><li>OTPs and temporary tokens</li><li>Idempotency keys</li><li>Feature flags</li></ul><p>Commands such as INCR and INCRBY update numeric strings atomically. That makes a string useful for shared counters across many application servers.</p><p>For example, a fixed-window rate limiter may use:</p><pre>Key: rate-limit:{userId}:{endpoint}:{window}<br>Value: request count<br>TTL: window duration</pre><p>Redis does not have a special data type called a rate limiter. The application builds one from a string counter, atomic increment, and expiration.</p><p>Use a string when the value is naturally treated as one unit. If the application often reads or updates individual fields, a hash may be a better choice.</p><h3>2. Hashes: objects with fields</h3><p>A Redis hash stores field-value pairs inside one Redis key. It feels similar to a Java HashMap or a Python dictionary.</p><pre>Key: session:abc123</pre><pre>userId     -&gt; 42<br>role       -&gt; admin<br>locale     -&gt; en-IN<br>lastPage   -&gt; checkout</pre><p>Hashes are useful for:</p><ul><li>User sessions</li><li>Shopping carts</li><li>User preferences</li><li>Small objects</li><li>Frequently updated object fields</li></ul><p>The application can read or update one field without replacing the complete object.</p><p>A hash works well for a flat object. For deeply nested documents, arrays, and richer JSON operations, Redis JSON may fit better.</p><h3>3. Lists: ordered sequences and simple queues</h3><p>A Redis list stores strings in insertion order. Applications can add or remove items from either end.</p><pre>jobs:email</pre><pre>[job-105, job-104, job-103]</pre><p>Lists are useful for:</p><ul><li>Simple background job queues</li><li>Recent activity</li><li>Small ordered histories</li><li>Producer and worker patterns</li></ul><p>A producer can push a job to one end. A worker can block until an item is available and remove it from the other end.</p><p>The word simple matters. If a worker removes a job and crashes before completing it, recovery requires extra design. When the system needs acknowledgements, pending-message tracking, retries, or multiple consumer groups, Redis Streams are a better match.</p><h3>4. Sets: uniqueness and membership</h3><p>A Redis set stores unique, unordered strings.</p><pre>friends:alice -&gt; {bob, carol, david}<br>friends:john  -&gt; {carol, david, emma}</pre><p>Sets are useful for:</p><ul><li>Unique tags or participants</li><li>Roles and permissions</li><li>Group membership</li><li>Items a user has already seen</li><li>Mutual friends</li></ul><p>Redis can calculate intersections, unions, and differences between sets. The intersection of Alice’s and John’s friend sets gives:</p><pre>{carol, david}</pre><p>Use a set when every member must be unique and order does not matter. If members need an order or priority, use a sorted set.</p><h3>5. Sorted sets: rankings, priority, and time</h3><p>A sorted set stores unique members. Each member also has a numeric score that controls its order.</p><pre>Key: game:7:leaderboard</pre><pre>player-9  -&gt; 2450<br>player-2  -&gt; 2210<br>player-5  -&gt; 1980</pre><p>Sorted sets are useful for:</p><ul><li>Leaderboards</li><li>Rankings</li><li>Priority queues</li><li>Trending content</li><li>Delayed jobs</li><li>Time-based scheduling</li></ul><p>For a leaderboard, the score is the player’s score. Redis can return the top players, a score range, or one player’s rank.</p><p>For delayed work, the score can be a Unix timestamp:</p><pre>Member: order:981<br>Score: cancellation time</pre><p>A worker reads entries whose scores are earlier than the current time. Before performing an important action, it should confirm the latest state in the primary database.</p><p>Sorted sets are one of the most versatile Redis structures because a score can represent rank, priority, time, distance, or another numeric property.</p><h3>6. Streams: events that need reliable processing</h3><p>A Redis Stream behaves like an append-only log. Each entry receives an ID and can contain multiple fields.</p><pre>Key: order-events</pre><pre>eventId: 173...<br>orderId: 981<br>type: PAYMENT_CONFIRMED</pre><p>Streams are useful for:</p><ul><li>Event processing</li><li>Notifications with history</li><li>Audit-like activity feeds</li><li>Sensor readings</li><li>Background work that needs acknowledgement</li></ul><p>Streams support consumer groups. Workers in one group share the work, acknowledge completed messages, and track messages that are still pending. Different consumer groups can independently process the same stream.</p><p>This makes Streams more reliable than a basic list or Pub/Sub for work that must be tracked.</p><p>Redis Streams are still not automatically a replacement for Kafka. Kafka is usually a stronger fit when the system needs very long retention, large-scale replay, extensive ecosystem integration, or a durable company-wide event backbone.</p><h3>7. Geospatial indexes: nearby locations</h3><p>Redis geospatial commands store members with longitude and latitude.</p><pre>Key: active-drivers:bengaluru<br>Member: driver:572<br>Location: longitude, latitude</pre><p>They are useful for:</p><ul><li>Nearby drivers</li><li>Nearby stores</li><li>Delivery agents within a radius</li><li>Location-based discovery</li></ul><p>The application can find members near a point and order the results by distance.</p><p>Redis geospatial search is useful for fast proximity queries. It is not a complete geographic information system. Complex polygons, map analysis, and advanced spatial relationships may need a specialized database.</p><h3>8. HyperLogLog: approximate unique counts</h3><p>Suppose a website needs the number of unique visitors, but it does not need the exact list of visitors.</p><p>A normal set can provide an exact answer, but its memory usage grows with every unique user. HyperLogLog keeps an approximate count using a small, fixed amount of memory.</p><pre>Key: visitors:2026-08-17<br>Members added: user IDs<br>Result: estimated unique count</pre><p>HyperLogLog is useful for:</p><ul><li>Unique daily visitors</li><li>Approximate active users</li><li>Unique search queries</li><li>Large-scale cardinality estimates</li></ul><p>It cannot return the original members or answer whether one specific user was seen. Use it only when an approximate count is enough.</p><h3>9. Bloom filters: probably seen or definitely not seen</h3><p>A Bloom filter is a probabilistic membership structure. It answers a specific question:</p><blockquote><em>Have we probably seen this item before?</em></blockquote><p>It can say that an item is definitely not present. A positive answer means the item is probably present, because false positives are possible.</p><p>Bloom filters are useful for:</p><ul><li>Avoiding database lookups for nonexistent IDs</li><li>Checking whether a username is probably taken</li><li>Reducing repeated content recommendations</li><li>Screening items before an expensive operation</li></ul><p>Use a Bloom filter when memory efficiency matters and occasional false positives are acceptable. Use a normal set when exact membership is required.</p><h3>A simple decision guide</h3><p>Choose based on the operation your application needs most:</p><pre>One value or counter              -&gt; String<br>Flat object with fields           -&gt; Hash<br>Ordered sequence                  -&gt; List<br>Unique membership                 -&gt; Set<br>Unique members with scores        -&gt; Sorted set<br>Stored events with acknowledgements -&gt; Stream<br>Nearby-location search            -&gt; Geospatial index<br>Approximate unique count          -&gt; HyperLogLog<br>Probable membership check         -&gt; Bloom filter</pre><p>This mapping is a starting point, not a rule that replaces design work. The same requirement can sometimes be solved in multiple ways. The best choice depends on consistency, memory, scale, failure handling, and the operations that must remain fast.</p><h3>Redis is a tool, not the source of truth for everything</h3><p>Redis is excellent for fast shared state and for problems that match its native structures. It should not automatically become the primary database.</p><p>Keep durable and critical records in a system designed for their requirements. Financial balances, authoritative inventory, long audit histories, complex relational queries, and large durable event pipelines often belong elsewhere.</p><p>The most useful Redis question is not:</p><blockquote><em>Can Redis store this?</em></blockquote><p>It is:</p><blockquote><em>Does a Redis data structure directly match the operations this feature needs?</em></blockquote><p>If the answer is yes, Redis can turn a complicated application problem into a small and efficient design.</p><p>In the next part of this series, we can choose one of these patterns and build it step by step, including its failure cases and production trade-offs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c27c0624091a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redis Caching in Production: Beyond GET and SET]]></title>
            <link>https://medium.com/@jaylimbasiya.work/redis-caching-in-production-beyond-get-and-set-b150f35e3bcd?source=rss-ea0deceda76e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b150f35e3bcd</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[caching]]></category>
            <dc:creator><![CDATA[Jay Limbasiya]]></dc:creator>
            <pubDate>Wed, 12 Aug 2026 16:43:35 GMT</pubDate>
            <atom:updated>2026-08-12T16:51:46.458Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nQU8gsALHCYh2BcIyofDog.png" /></figure><p>Part 1 of Redis in Real Applications: cache-aside, TTLs, invalidation, stampedes, and graceful failure through one product API.</p><p>Imagine a product-details API during a flash sale. Thousands of users request the same product, but its information changes only occasionally.</p><p>Sending every request to the primary database works — until latency rises, connections fill up, and the database spends most of its time returning the same record.</p><p>Redis can protect that read path. But adding a cache is the easy part. The real engineering decisions are what to cache, how long to keep it, how to invalidate it, and what to do when Redis is unavailable.</p><h3>Start with one rule: the database owns the truth</h3><p>The primary database should remain the authoritative store for our product. Redis holds a temporary copy under a predictable key:</p><pre>Key: product:{productId}<br>Value: serialized product details<br>TTL: acceptable freshness window</pre><p>If that key expires, is evicted, or becomes unavailable, the application can rebuild it from the database. Redis accelerates access to the data; it does not become the durable source of truth.</p><h3>Cache-aside: load only what users request</h3><p>With the cache-aside pattern, the application controls the cache:</p><pre>1. Check Redis for product:{id}<br>2. On a hit, return the cached value<br>3. On a miss, read from the database<br>4. Store the result in Redis with a TTL<br>5. Return the result</pre><p>In pseudocode:</p><pre>function getProduct(id):<br>    key = &quot;product:&quot; + id<br>    cached = redis.get(key)</pre><pre>    if cached exists:<br>        return cached</pre><pre>    product = database.findProduct(id)<br>    redis.set(key, product, ttl)<br>    return product</pre><p>The first request still reaches the database. Later requests avoid that cost until the entry expires or is invalidated. This works especially well when a small part of the catalogue receives most of the traffic.</p><h3>TTL is a business decision</h3><p>A time to live limits both the life of a cache entry and the period for which stale data might survive if invalidation fails.</p><p>There is no universal value:</p><ul><li>A mostly static description can use a longer TTL.</li><li>Price or availability usually needs a shorter TTL.</li><li>An OTP may live for only a few minutes.</li><li>Online presence may expire within seconds.</li></ul><p>Short TTLs improve freshness but cause more database reads. Long TTLs improve the hit rate but can serve old information longer. Choose the longest stale-data window the product can safely tolerate.</p><p>Adding a small random variation — often called TTL jitter — also prevents many related keys from expiring at exactly the same moment.</p><h3>Update the database, then invalidate Redis</h3><p>When a product changes, a simple write path is:</p><pre>1. Update the primary database<br>2. Delete product:{id} from Redis<br>3. Let the next read rebuild the cache</pre><p>Deleting the cache entry is often safer than trying to update two systems with the same value.</p><p>The order matters. If the application deletes Redis first and the database update fails, another request can reload the old database value into the cache. Updating the database before invalidation reduces that risk.</p><p>It still does not guarantee perfect consistency. If the database commit succeeds but cache deletion fails, stale data can remain until the TTL expires. For stricter requirements, teams may add retries, versioned keys, or event-driven invalidation.</p><h3>Prevent a cache miss from becoming an incident</h3><p>Imagine a popular product key expiring while thousands of requests arrive. Every request observes the miss, queries the database, and tries to refill Redis. This is a cache stampede.</p><p>One common defense is request coalescing:</p><pre>One request acquires a short-lived lock,<br>loads the database value, and fills Redis.</pre><pre>Other requests wait briefly,<br>then read the refreshed value.</pre><p>The lock needs an expiry and a unique owner token. Other options include refreshing hot keys before expiry, serving a slightly stale value while one worker refreshes it, and using TTL jitter.</p><p>There is a related problem: repeated requests for IDs that do not exist. Because Redis never contains those products, every request reaches the database. Cache a “not found” result for a short period, validate inputs, and apply rate limiting. At very large scale, a Bloom filter can add another layer of protection.</p><h3>TTL and eviction are not the same</h3><ul><li>TTL removes data because it is no longer valid.</li><li>Eviction removes data because Redis has reached its configured memory limit.</li></ul><p>For a reloadable product cache, an LRU- or LFU-style eviction policy may be appropriate. Data that must never disappear should not share an aggressively evicting cache without clear isolation and operational safeguards.</p><h3>Design the failure path too</h3><p>If Redis is unavailable, the application may fall back to the database. But allowing every request to fall back at once can overwhelm the system Redis was meant to protect.</p><p>A safer plan combines short Redis timeouts, bounded retries, circuit breaking, database concurrency limits, and request shedding for nonessential traffic. Monitor cache hit rate, latency, evictions, errors, and database load.</p><p>“Fall back to the database” is not a complete strategy. Fall back within a controlled capacity limit.</p><h3>A practical checklist</h3><p>Before shipping a Redis cache, answer these questions:</p><ol><li>Which system remains the source of truth?</li><li>How stale may a response safely be?</li><li>What invalidates the cache after a write?</li><li>How are popular-key expirations protected from stampedes?</li><li>Should missing values be cached?</li><li>Which memory limit and eviction policy fit the workload?</li><li>What happens when Redis is slow or unavailable?</li><li>Which metrics will show whether the cache is actually helping?</li></ol><h3>The takeaway</h3><p>Redis caching is not simply about making GET faster. It is about maintaining a controlled, temporary copy of data with explicit freshness, memory, and failure boundaries.</p><blockquote><em>The database owns the truth. Redis accelerates access to it. TTL limits staleness. Invalidation manages change. Protection mechanisms keep cache misses from becoming incidents.</em></blockquote><p>In the next part, I’ll use Redis atomic operations to implement API rate limiting and compare fixed-window, sliding-window, and token-bucket designs.</p><p><strong>Further reading:</strong> <a href="https://redis.io/docs/latest/develop/use-cases/cache-aside/">Redis cache-aside</a> and <a href="https://redis.io/docs/latest/develop/reference/eviction/">Redis key eviction</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b150f35e3bcd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>