<?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 Dipak Das on Medium]]></title>
        <description><![CDATA[Stories by Dipak Das on Medium]]></description>
        <link>https://medium.com/@dipak434das?source=rss-4a803651cc5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mm7I-JJ3vRn3kNeB</url>
            <title>Stories by Dipak Das on Medium</title>
            <link>https://medium.com/@dipak434das?source=rss-4a803651cc5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:41:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dipak434das/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[Handling Downstream Failures in Kafka Using DLQ: A Practical System Design Approach]]></title>
            <link>https://medium.com/@dipak434das/handling-downstream-failures-in-kafka-using-dlq-a-practical-system-design-approach-4add495eca1e?source=rss-4a803651cc5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4add495eca1e</guid>
            <dc:creator><![CDATA[Dipak Das]]></dc:creator>
            <pubDate>Sat, 19 Sep 2026 09:34:16 GMT</pubDate>
            <atom:updated>2026-09-19T09:38:15.004Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A practical system-design approach for resilient Kafka consumers, including a real-world CDC use case and Spring Kafka implementation.</em></p><h3>1. The Problem</h3><p>In a distributed system, a Kafka consumer rarely works in isolation.</p><p>A common flow looks like:</p><p><strong>Kafka → Consumer → Downstream Service → Database / External System</strong></p><p>Now imagine the consumer successfully receives a message, but the downstream service is temporarily unavailable.</p><p>For example:</p><ul><li>Downstream service is down</li><li>Network timeout occurs</li><li>External API is unavailable</li><li>Database connection fails</li><li>Downstream service returns 5xx</li></ul><p>What should happen to the Kafka message?</p><p>Simply failing the consumer isn’t always a good solution.</p><p>Repeatedly retrying the same message can block processing, increase latency and potentially create backpressure.</p><p>This is where a <strong>Dead Letter Queue (DLQ)</strong> can help.</p><h3>2. What is a DLQ?</h3><p>A Dead Letter Queue is a separate Kafka topic where messages that cannot be successfully processed are sent for later investigation or replay.</p><p>Instead of:</p><pre>Kafka Topic<br>     ↓<br>  Consumer<br>     ↓<br>Downstream ❌<br>     ↓<br>Message Lost</pre><p>we create:</p><pre>Kafka Topic<br>     ↓<br>  Consumer<br>     ↓<br>Downstream Service<br>     ↓<br>   Failure<br>     ↓<br>    DLQ</pre><p>The failed message is preserved rather than simply disappearing from the processing flow.</p><h3>3. Basic Architecture</h3><h3>Normal Flow</h3><pre>┌───────────────┐<br>│ Kafka Topic   │<br>│  main-topic   │<br>└───────┬───────┘<br>        │<br>        ▼<br>┌───────────────┐<br>│   Consumer    │<br>└───────┬───────┘<br>        │<br>        ▼<br>┌───────────────┐<br>│  Downstream   │<br>│    Service    │<br>└───────┬───────┘<br>        │<br>        ▼<br>    Processing</pre><h3>Failure Flow</h3><pre>┌───────────────┐<br>│ Kafka Topic   │<br>└───────┬───────┘<br>        │<br>        ▼<br>┌───────────────┐<br>│   Consumer    │<br>└───────┬───────┘<br>        │<br>        ▼<br>┌───────────────┐<br>│  Downstream   │<br>│      ❌       │<br>└───────┬───────┘<br>        │<br>        ▼<br>┌────────────────┐<br>│      DLQ       │<br>│ failed-events  │<br>└────────────────┘</pre><h3>4. Recovery Flow</h3><p>A DLQ is useful only if we have a proper recovery strategy.</p><p>When the downstream service becomes healthy again, we can start processing the failed messages.</p><pre>             ┌─────────────┐<br>             │     DLQ     │<br>             └──────┬──────┘<br>                    │<br>                    ▼<br>             ┌─────────────┐<br>             │   Consumer  │<br>             └──────┬──────┘<br>                    │<br>                    ▼<br>             ┌─────────────┐<br>             │ Downstream  │<br>             │   Service   │<br>             └──────┬──────┘<br>                    │<br>                    ▼<br>                 Success<br>                    │<br>                    ▼<br>               DLQ becomes<br>                  empty<br>                    │<br>                    ▼<br>               Resume main<br>                  topic</pre><p>The important point is that <strong>recovery should be an explicit processing strategy</strong>.</p><p>A production implementation may use a dedicated replay consumer/job rather than simply switching a consumer back and forth between topics.</p><h3>5. Spring Kafka — Simplified Example</h3><p>A consumer can catch processing failures and publish the failed event to a DLQ.</p><pre>@KafkaListener(<br>        topics = &quot;main-topic&quot;,<br>        groupId = &quot;order-consumer&quot;<br>)<br>public void consume(ConsumerRecord&lt;String, String&gt; record) {<br><br>  try {<br>        processDownstream(record.value());<br>    } catch (Exception ex) {<br>        log.error(<br>            &quot;Downstream processing failed. Sending message to DLQ&quot;,<br>            ex<br>        );<br>        sendToDlq(record);<br>    }<br>}</pre><p>A simplified DLQ publisher:</p><pre>private void sendToDlq(<br>        ConsumerRecord&lt;String, String&gt; record) {<br>  ProducerRecord&lt;String, String&gt; dlqRecord =<br>            new ProducerRecord&lt;&gt;(<br>                    &quot;main-topic-dlq&quot;,<br>                    record.key(),<br>                    record.value()<br>            );<br>    dlqRecord.headers().add(<br>            &quot;original-topic&quot;,<br>            record.topic().getBytes()<br>    );<br>    dlqRecord.headers().add(<br>            &quot;original-partition&quot;,<br>            String.valueOf(record.partition())<br>                    .getBytes()<br>    );<br>    dlqRecord.headers().add(<br>            &quot;original-offset&quot;,<br>            String.valueOf(record.offset())<br>                    .getBytes()<br>    );<br>    kafkaTemplate.send(dlqRecord);<br>}</pre><p>The actual implementation can be more sophisticated using Spring Kafka’s error-handling and dead-letter publishing mechanisms.</p><p>The important concept is preserving enough metadata to understand <strong>where the message originally came from</strong>.</p><h3>6. Why Metadata Matters</h3><p>Suppose we have:</p><pre>main-topic<br>partition = 3<br>offset = 10245</pre><p>and the message goes to:</p><pre>main-topic-dlq</pre><p>During replay, we should ideally know:</p><pre>Original Topic<br>Original Partition<br>Original Offset<br>Exception<br>Failure Timestamp<br>Retry Count<br>Consumer/Application Information</pre><p>This makes debugging and replay much easier.</p><h3>7. DLQ in CDC Architecture</h3><p>This pattern becomes particularly interesting with <strong>Change Data Capture (CDC)</strong>.</p><p>Consider:</p><pre>┌──────────────┐<br>│   Database   │<br>└──────┬───────┘<br>       │<br>       │ CDC<br>       ▼<br>┌──────────────┐<br>│ Debezium /   │<br>│ CDC Platform │<br>└──────┬───────┘<br>       │<br>       ▼<br>┌──────────────┐<br>│    Kafka     │<br>└──────┬───────┘<br>       │<br>       ▼<br>┌──────────────┐<br>│   Consumer   │<br>└──────┬───────┘<br>       │<br>       ▼<br>┌──────────────┐<br>│ Downstream   │<br>│   Service    │<br>└──────────────┘</pre><p>Imagine an employee record is updated:</p><pre>Employee salary:<br>₹80,000 → ₹90,000</pre><p>CDC captures the change and publishes an event:</p><pre>{<br>  &quot;operation&quot;: &quot;UPDATE&quot;,<br>  &quot;employeeId&quot;: &quot;E123&quot;,<br>  &quot;salary&quot;: 90000<br>}</pre><p>Kafka receives the event.</p><p>But now suppose the downstream employee service is unavailable.</p><p>We don’t want to lose this change.</p><p>Instead:</p><pre>CDC Event<br>   ↓<br>Kafka<br>   ↓<br>Consumer<br>   ↓<br>Downstream ❌<br>   ↓<br>DLQ</pre><p>Once the downstream service is healthy:</p><pre>DLQ<br> ↓<br>Replay<br> ↓<br>Downstream<br> ↓<br>Success</pre><p>This is particularly useful when the CDC event represents an important state change that must eventually be processed.</p><h3>8. One Important System Design Consideration</h3><p>A DLQ doesn’t automatically solve <strong>duplicate processing</strong>.</p><p>Consider this scenario:</p><pre>Consumer<br>   ↓<br>Downstream successfully processes<br>   ↓<br>Consumer crashes BEFORE offset commit<br>   ↓<br>Kafka redelivers message</pre><p>Now the downstream service may process the same event twice.</p><p>Therefore, a production-grade Kafka consumer should consider <strong>idempotency</strong>.</p><p>For example, use a unique event ID:</p><pre>{<br>  &quot;eventId&quot;: &quot;evt-12345&quot;,<br>  &quot;operation&quot;: &quot;UPDATE&quot;,<br>  &quot;employeeId&quot;: &quot;E123&quot;<br>}</pre><p>The downstream service can maintain a record of processed event IDs.</p><pre>eventId = evt-12345<br>       ↓<br>Already processed?<br>       ↓<br>      YES<br>       ↓<br>Ignore duplicate</pre><p>This is an important part of designing reliable event-driven systems.</p><h3>9. DLQ vs Retry</h3><p>DLQ and retry solve slightly different problems.</p><h3>Retry</h3><p>Useful when the failure is likely to be temporary.</p><pre>Message<br>   ↓<br>Attempt 1 ❌<br>   ↓<br>Retry<br>   ↓<br>Attempt 2 ❌<br>   ↓<br>Retry<br>   ↓<br>Attempt 3 ✅</pre><h3>DLQ</h3><p>Useful when normal processing cannot continue and the message needs to be isolated for later processing.</p><pre>Message<br>   ↓<br>Processing ❌<br>   ↓<br>DLQ<br>   ↓<br>Later Replay</pre><p>A common production architecture can combine both:</p><pre>Kafka<br>  ↓<br>Consumer<br>  ↓<br>Retry 1<br>  ↓<br>Retry 2<br>  ↓<br>Retry 3<br>  ↓<br>DLQ</pre><h3>10. Production Considerations</h3><p>When implementing DLQ, there are several things worth considering.</p><h3>1. Idempotency</h3><p>Make downstream operations safe against duplicate events.</p><h3>2. DLQ Monitoring</h3><p>Monitor:</p><ul><li>DLQ message count</li><li>Oldest message age</li><li>Failure rate</li><li>Replay rate</li></ul><p>A growing DLQ can be an early indication of a downstream problem.</p><h3>3. Message Retention</h3><p>DLQ retention should be aligned with your recovery requirements.</p><h3>4. Replay Strategy</h3><p>Define how messages will be replayed.</p><p>For example:</p><pre>DLQ → Replay Service → Downstream</pre><p>rather than manually publishing messages.</p><h3>5. Poison Messages</h3><p>Some messages may fail repeatedly because the data itself is invalid.</p><p>These should not necessarily be replayed forever.</p><pre>Retry<br>  ↓<br>Retry<br>  ↓<br>Retry<br>  ↓<br>Still failing<br>  ↓<br>Permanent failure / Investigation</pre><h3>6. Observability</h3><p>Include useful metadata such as:</p><pre>eventId<br>topic<br>partition<br>offset<br>timestamp<br>exception<br>service<br>retryCount</pre><p>This makes troubleshooting significantly easier.</p><h3>11. The Bigger Picture</h3><p>The main idea behind the DLQ pattern is not simply:</p><blockquote><em>“Put failed Kafka messages into another topic.”</em></blockquote><p>The bigger system-design goal is:</p><p><strong>Failure should be isolated, observable and recoverable.</strong></p><p>For CDC-based architectures, this becomes even more important because a temporary downstream outage should not necessarily prevent the system from eventually processing an important database change.</p><p>A resilient architecture therefore looks something like:</p><pre>              DATABASE<br>                 │<br>                 ▼<br>                CDC<br>                 │<br>                 ▼<br>        ┌────────────────┐<br>        │ Kafka Main     │<br>        │ Topic          │<br>        └───────┬────────┘<br>                │<br>                ▼<br>            Consumer<br>                │<br>                ▼<br>        Downstream Service<br>           │          │<br>        Success      Failure<br>           │          │<br>           ▼          ▼<br>       Commit        DLQ<br>                      │<br>                      ▼<br>                Replay Process<br>                      │<br>                      ▼<br>                Downstream</pre><p><strong>Reliable event-driven systems aren’t designed assuming failures won’t happen. They’re designed to recover when failures do happen.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4add495eca1e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Most RAG Applications Fail in Production (and How to Fix Them)]]></title>
            <link>https://medium.com/@dipak434das/why-most-rag-applications-fail-in-production-and-how-to-fix-them-f637b7edef92?source=rss-4a803651cc5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f637b7edef92</guid>
            <dc:creator><![CDATA[Dipak Das]]></dc:creator>
            <pubDate>Sat, 11 Jul 2026 10:14:06 GMT</pubDate>
            <atom:updated>2026-07-11T10:14:06.130Z</atom:updated>
            <content:encoded><![CDATA[<p>Most tutorials make Retrieval-Augmented Generation (RAG) look deceptively simple.</p><p>The architecture usually looks like this:</p><pre>                 Documents<br>                     │<br>              Generate Embeddings<br>                     │<br>              Vector Database<br>                     │<br>              Retrieve Top-K<br>                     │<br>                    LLM<br>                     │<br>                 Final Answer</pre><p>This pipeline works well for prototypes and demos.</p><p>However, once you deploy a RAG system in an enterprise environment, the challenges become much more complex.</p><h3>The Production Reality</h3><p>Imagine your organization contains:</p><ul><li>500,000+ documents</li><li>API documentation</li><li>Engineering wikis</li><li>PDF manuals</li><li>Jira tickets</li><li>Runbooks</li><li>Design documents</li></ul><p>Now a developer asks:</p><blockquote><strong>“How do we deploy microservices to production in our organization?”</strong></blockquote><p>The vector database retrieves five semantically similar chunks.</p><p>Unfortunately, they contain:</p><ul><li>Outdated deployment instructions</li><li>Documentation belonging to another team</li><li>Duplicate information</li><li>Partial code snippets</li><li>Chunks with missing context</li></ul><p>The LLM faithfully answers using the retrieved information.</p><p>If the retrieved context is poor, the answer will also be poor.</p><p>The model isn’t the problem.</p><p>The retrieval pipeline is.</p><h3>What a Production RAG Pipeline Looks Like</h3><p>A production-ready architecture typically includes several additional layers.</p><pre>                  Documents<br>                      │<br>               Document Parsing<br>                      │<br>              Metadata Extraction<br>                      │<br>                 Smart Chunking<br>                      │<br>             Embedding Generation<br>                      │<br>               Vector Database<br>                      │<br>              Metadata Filtering<br>                      │<br>         Hybrid Search (BM25 + Vector)<br>                      │<br>               Retrieve Top 50<br>                      │<br>           Cross-Encoder Reranker<br>                      │<br>                  Best Top 5<br>                      │<br>              Prompt Construction<br>                      │<br>                     LLM<br>                      │<br>                Final Response</pre><p>Each stage improves the quality of retrieved context before it reaches the language model.</p><h3>1. Smart Chunking</h3><p>Many systems split documents every 500 characters.</p><p>This often separates headings from their content, breaks code blocks, and loses important context.</p><p>A better strategy is to chunk using the document structure:</p><ul><li>Headings</li><li>Paragraphs</li><li>Bullet lists</li><li>Tables</li><li>Code blocks</li></ul><p>Typical recommendations:</p><ul><li>Chunk Size: 400–700 tokens</li><li>Overlap: 50–100 tokens</li><li>Preserve document hierarchy</li><li>Attach metadata (team, version, page, document type)</li></ul><h3>2. Metadata Filtering</h3><p>Searching every document is unnecessary.</p><p>Before vector search, filter documents using metadata such as:</p><ul><li>Team</li><li>Repository</li><li>Product</li><li>Environment</li><li>Version</li><li>Owner</li></ul><p>This significantly reduces irrelevant search results.</p><h3>3. Hybrid Search</h3><p>Vector search captures semantic meaning.</p><p>BM25 excels at exact keyword matching.</p><p>Neither is sufficient on its own.</p><p>A stronger approach combines both.</p><pre>                User Query<br>                     │<br>         ┌───────────┴───────────┐<br>         │                       │<br>      BM25 Search          Vector Search<br>         │                       │<br>         └───────────┬───────────┘<br>                     │<br>               Merge Results<br>                     │<br>                 Reranking</pre><p>Hybrid search consistently improves retrieval quality, especially for technical documentation.</p><h3>4. Reranking</h3><p>The first retrieval stage prioritizes recall.</p><p>The reranker prioritizes precision.</p><p>Instead of sending every retrieved chunk to the LLM:</p><pre> Retrieve Top 50<br>        │<br>  Cross-Encoder<br>        │<br>   Select Best 5<br>        │<br>       LLM</pre><p>This often improves answer quality without changing the language model.</p><h3>5. Version-Aware Indexing</h3><p>Many enterprise documents become obsolete.</p><p>Rather than deleting them entirely:</p><ul><li>Track document versions</li><li>Mark deprecated content</li><li>Prefer the latest documentation</li><li>Apply freshness scoring during retrieval</li></ul><p>This prevents outdated instructions from reaching users.</p><h3>6. Caching</h3><p>Latency matters.</p><p>Production systems commonly cache:</p><ul><li>Embeddings</li><li>Retrieval results</li><li>Prompt templates</li><li>Frequently asked LLM responses</li></ul><p>This reduces cost while improving response times.</p><h3>Key Takeaways</h3><p>The biggest lesson I’ve learned while working with RAG systems is simple:</p><blockquote><strong><em>Better retrieval beats a bigger language model.</em></strong></blockquote><p>A production-grade RAG system isn’t just about embeddings and vector databases.</p><p>It requires:</p><ul><li>Intelligent chunking</li><li>Metadata-aware filtering</li><li>Hybrid search</li><li>Reranking</li><li>Version-aware indexing</li><li>Effective caching</li></ul><p>When these components work together, the LLM receives richer, more relevant context, resulting in more accurate, grounded, and reliable responses.</p><p>As enterprise AI adoption continues to grow, <strong>retrieval engineering</strong> will become one of the most valuable skills for software and AI engineers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f637b7edef92" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>