<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nitin Singh</title>
    <description>The latest articles on DEV Community by Nitin Singh (@imnitinsingh).</description>
    <link>https://dev.to/imnitinsingh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3409403%2F6063c031-3539-4d76-80f3-06bd707cd438.jpg</url>
      <title>DEV Community: Nitin Singh</title>
      <link>https://dev.to/imnitinsingh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imnitinsingh"/>
    <language>en</language>
    <item>
      <title>🔄 Real-Time Cache Refresh Using Azure Queue (Without Redis, Service Bus, or Pub/Sub)</title>
      <dc:creator>Nitin Singh</dc:creator>
      <pubDate>Mon, 18 Aug 2025 21:05:45 +0000</pubDate>
      <link>https://dev.to/imnitinsingh/real-time-cache-refresh-using-azure-queue-without-redis-service-bus-or-pubsub-4g5b</link>
      <guid>https://dev.to/imnitinsingh/real-time-cache-refresh-using-azure-queue-without-redis-service-bus-or-pubsub-4g5b</guid>
      <description>&lt;p&gt;🚀 A Lightweight Cache Refresh Mechanism with Azure Queue (No Redis, No Service Bus!)&lt;br&gt;
💡 The Problem&lt;/p&gt;

&lt;p&gt;In our application, data was stored in the database, but not updated frequently.&lt;br&gt;
To improve performance, we wanted this data cached across multiple app instances.&lt;/p&gt;

&lt;p&gt;The challenge:&lt;/p&gt;

&lt;p&gt;Data changes occasionally (Insert, Update, Delete in Azure DB).&lt;/p&gt;

&lt;p&gt;Whenever data changes, all app instances should refresh their cache.&lt;/p&gt;

&lt;p&gt;We wanted to avoid Redis, Pub/Sub, or Service Bus and stick with Azure Queue Storage.&lt;/p&gt;

&lt;p&gt;⚙️ The Solution&lt;/p&gt;

&lt;p&gt;Here’s the approach I designed:&lt;/p&gt;

&lt;p&gt;Cache Layer: Store the DB data in memory cache (per app instance).&lt;/p&gt;

&lt;p&gt;Trigger on Change: When a DB operation (insert/update/delete) occurs, send a message to an Azure Queue with a TTL (Time-to-Live).&lt;/p&gt;

&lt;p&gt;Background Listener: Each instance runs a lightweight listener that:&lt;/p&gt;

&lt;p&gt;Periodically checks the approximate message count in the queue.&lt;/p&gt;

&lt;p&gt;If count &amp;gt; 0 → Refreshes local cache.&lt;/p&gt;

&lt;p&gt;Message Cleanup: Since ApproximateMessagesCount is not real-time, each sender also schedules a DeleteMessageAsync after a delay, ensuring the message is eventually cleaned up.&lt;/p&gt;

&lt;p&gt;This ensures:&lt;/p&gt;

&lt;p&gt;All instances refresh cache consistently.&lt;/p&gt;

&lt;p&gt;Queue acts like a broadcast signal, not a transport layer.&lt;/p&gt;

&lt;p&gt;No dependency on Redis or Service Bus.&lt;/p&gt;

&lt;p&gt;🔄 Flow Diagram&lt;br&gt;
flowchart TD&lt;br&gt;
    A[DB Change: Insert/Update/Delete] --&amp;gt; B[Send message to Azure Queue (with TTL)]&lt;br&gt;
    B --&amp;gt; C[Background Listener reads Approximate Message Count]&lt;br&gt;
    C --&amp;gt;|Count &amp;gt; 0| D[Refresh Local Cache]&lt;br&gt;
    D --&amp;gt; E[Mark message for delayed DeleteMessageAsync]&lt;br&gt;
    E --&amp;gt; F[Cache Synchronized Across Instances]&lt;/p&gt;

&lt;p&gt;📌 Key Points&lt;/p&gt;

&lt;p&gt;Uses Azure Storage Queue only (no Service Bus, no Redis).&lt;/p&gt;

&lt;p&gt;ApproximateMessageCount drives the decision, but cleanup ensures correctness.&lt;/p&gt;

&lt;p&gt;Messages act as cache refresh signals, not data carriers.&lt;/p&gt;

&lt;p&gt;Works well in multi-instance deployments.&lt;/p&gt;

&lt;p&gt;✅ Benefits&lt;/p&gt;

&lt;p&gt;Lightweight – no extra infra needed.&lt;/p&gt;

&lt;p&gt;Cost-effective – Azure Queue is cheap.&lt;/p&gt;

&lt;p&gt;Resilient – each instance eventually refreshes even if messages are delayed.&lt;/p&gt;

&lt;p&gt;🔮 Future Improvements&lt;/p&gt;

&lt;p&gt;Use custom message metadata (e.g., message type, source host).&lt;/p&gt;

&lt;p&gt;Replace ApproximateMessageCount polling with event-based push if scale increases.&lt;/p&gt;

&lt;p&gt;Add dead-letter queue for failed refresh attempts.&lt;/p&gt;

&lt;p&gt;✍️ Final Thoughts&lt;/p&gt;

&lt;p&gt;This approach is perfect for scenarios where:&lt;/p&gt;

&lt;p&gt;Data changes are infrequent.&lt;/p&gt;

&lt;p&gt;You want shared cache consistency across multiple instances.&lt;/p&gt;

&lt;p&gt;You don’t want to introduce Redis, Pub/Sub, or costly Service Bus.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional Use Case: Configuration Management&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This approach isn’t limited to cache refresh.&lt;br&gt;
Imagine you have an application deployed across multiple environments or instances where only configuration values change from time to time.&lt;/p&gt;

&lt;p&gt;Traditionally:&lt;/p&gt;

&lt;p&gt;You’d need to redeploy apps or push configs manually.&lt;/p&gt;

&lt;p&gt;With this pattern:&lt;/p&gt;

&lt;p&gt;Store config values/keys in the database.&lt;/p&gt;

&lt;p&gt;On config update → send a message to the queue.&lt;/p&gt;

&lt;p&gt;All instances refresh their in-memory config cache automatically.&lt;/p&gt;

&lt;p&gt;👉 Result: No redeployments needed for simple config changes.&lt;/p&gt;

&lt;p&gt;👉 If you liked this idea, follow me here on Dev.to and let’s discuss how you handle cache refresh in your systems!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
