<?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 Vojtech Pastyrik on Medium]]></title>
        <description><![CDATA[Stories by Vojtech Pastyrik on Medium]]></description>
        <link>https://medium.com/@vojtech.pastyrik?source=rss-c30bee04c80f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kujt3daYdGHst-TALFoixg.jpeg</url>
            <title>Stories by Vojtech Pastyrik on Medium</title>
            <link>https://medium.com/@vojtech.pastyrik?source=rss-c30bee04c80f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 09:02:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vojtech.pastyrik/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[NATS JetStream vs RabbitMQ: Choosing the Right Message Broker for Your Event-Driven Architecture]]></title>
            <link>https://medium.com/@vojtech.pastyrik/nats-jetstream-vs-rabbitmq-choosing-the-right-message-broker-for-your-event-driven-architecture-5b7bc739f540?source=rss-c30bee04c80f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b7bc739f540</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[integration]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[nats-jetstream]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <dc:creator><![CDATA[Vojtech Pastyrik]]></dc:creator>
            <pubDate>Fri, 14 Nov 2025 09:22:22 GMT</pubDate>
            <atom:updated>2025-11-14T09:22:22.686Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*klr7p15eRmR886VLIyhe0A.png" /></figure><p>I got a call from a friend who works as an accounting system vendor. He had a client facing a critical challenge: they needed to migrate from their old accounting system to a new one, and simultaneously prepare for international expansion beyond the Czech Republic. He asked if I could build them an integration platform to handle this complex migration.</p><p>This wasn’t a small project. The company had years of data trapped in their legacy system and ambitious plans to operate across several European countries. They needed a solution that could:</p><ul><li>Handle data migration from the old accounting system to the new one</li><li>Integrate the new accounting system with their existing operations</li><li>Support multi-country operations with different regulations and tax systems</li><li>Scale as they expanded internationally</li><li>Be maintainable long-term</li></ul><p>The wrong architectural choice could doom the project — performance bottlenecks, operational nightmares, or expensive rewrites. The right choice would enable smooth migration and support their growth for years.</p><p><strong>RabbitMQ seemed like the obvious choice.</strong> It’s the industry standard, battle-tested, and everyone recommends it for enterprise integrations. But something made me pause — RabbitMQ is powerful, but also heavy. Complex configuration, Erlang runtime, memory management tuning. Did a client with just 2 IT people really need all that complexity?</p><p>I decided to spend a few nights researching and testing alternatives. I wanted something newer, lighter, more cloud-native. That’s when I discovered<strong> NATS JetStream</strong>.</p><p>After several late nights of building proof-of-concepts and running real migration scenarios through both platforms, I made my decision — and it surprised me.</p><p>This is the story of what I discovered, why I ultimately chose what I did, and the lessons I learned. If you’re building an event-driven integration platform and wondering whether to go with the proven standard or explore newer alternatives, this might help.</p><h3>Understanding Event-Driven Architecture: The Foundation</h3><p>Before we dive into specific tools, let’s establish what we mean by Event-Driven Architecture.</p><h3>What is EDA?</h3><p>Event-Driven Architecture is a design pattern where services communicate through events — significant changes in state or notifications that something has happened. Instead of services calling each other directly (request-response), they emit events that other services can consume asynchronously.</p><p><strong>Core Concepts:</strong></p><ul><li><strong>Events</strong>: Immutable facts about what happened (e.g., “OrderPlaced”, “PaymentProcessed”)</li><li><strong>Producers</strong>: Services that emit events</li><li><strong>Consumers</strong>: Services that react to events</li><li><strong>Message Broker</strong>: The middleware that routes events from producers to consumers</li></ul><h3>Why EDA Matters</h3><p>Traditional synchronous architectures create tight coupling between services. When Service A calls Service B directly, they must both be available, creating a brittle system where one failure cascades to others.</p><p>EDA provides:</p><ol><li><strong>Loose Coupling</strong>: Services don’t need to know about each other</li><li><strong>Scalability</strong>: Process events at your own pace</li><li><strong>Resilience</strong>: Failures in one service don’t break others</li><li><strong>Real-time Processing</strong>: React to events as they happen</li><li><strong>Audit Trail</strong>: Events create a natural log of what happened</li></ol><h3>Common Use Cases</h3><ul><li><strong>Microservices communication</strong>: Decoupling service dependencies</li><li><strong>Real-time analytics</strong>: Processing streams of data as they arrive</li><li><strong>IoT data processing</strong>: Handling millions of sensor events</li><li><strong>CQRS patterns</strong>: Separating reads and writes with event sourcing</li><li><strong>Notification systems</strong>: Triggering alerts and updates across platforms</li></ul><p>Now that we understand the “why,” let’s explore the “how” with our two messaging platforms.</p><h3>What I Actually Needed</h3><p>Understanding EDA principles is one thing, but every project has specific requirements. For this accounting migration and international expansion, I needed more than just pub-sub messaging. Let me be specific about what drove my technology choice.</p><p><strong>The Critical Requirement: Intelligent Error Handling</strong></p><p>During data migration, failures aren’t edge cases — they’re guaranteed to happen:</p><ul><li>The new accounting system API goes down for maintenance</li><li>Data validation fails on edge cases in x years of legacy data</li><li>Network timeouts, rate limits, temporary database locks</li><li>Currency conversion APIs hit rate limits</li></ul><p>I needed a message broker that would handle this elegantly with:</p><ol><li><strong>Dynamic redelivery mechanism</strong> with exponential backoff (not fixed delays)</li><li><strong>Automatic DLQ (Dead Letter Queue) routing</strong> after exhausting retries</li><li><strong>Message persistence</strong> — messages must survive broker restarts (critical for accounting data)</li><li><strong>Spring Boot integration</strong></li></ol><p>This wasn’t about processing millions of messages per second. It was about processing thousands of messages <strong>reliably</strong>, with intelligent handling when things go wrong.</p><h3>Candidate #1: RabbitMQ — The Spring Boot Favorite</h3><p>RabbitMQ was my natural first choice for one compelling reason: <strong>official Spring Boot integration</strong>.</p><p>Spring AMQP provides ready-made annotations, auto-configuration, and template classes. For a Spring Boot project, this seemed like the path of least resistance:</p><pre>@RabbitListener(queues = &quot;invoice.migration&quot;)<br>public void processInvoice(InvoiceEvent invoice) {<br>    accountingService.migrateInvoice(invoice);<br>}</pre><p>Simple, clean, familiar. Perfect, right?</p><p>The Reality Check As I started implementing the actual retry logic I needed, things got complicated fast.</p><h4>Problem #1: No Built-in Exponential Backoff</h4><p>RabbitMQ doesn’t natively support dynamic redelivery delays. To get exponential backoff, I found several unsatisfying options:</p><p><strong>Option A: Multiple TTL Queues</strong> - Create a chain of queues with different TTLs. When a message fails, route it through queues with increasing delays. Horrifically complex for maintenance:</p><pre>invoice.retry.1s -&gt; (fails) -&gt; invoice.retry.3s -&gt; (fails) -&gt; <br>invoice.retry.9s -&gt; (fails) -&gt; invoice.retry.27s -&gt; (fails) -&gt; invoice.dlq</pre><p>That’s 5+ queues just for retry logic!</p><p><strong>Option B: Delayed Message Plugin</strong> — For delayed messages, I’d need the rabbitmq-delayed-message-exchange plugin. But this plugin <strong>isn&#39;t included</strong> in the standard RabbitMQ distribution.</p><p>It’s not just</p><pre>rabbitmq-plugins enable rabbitmq_delayed_message_exchange</pre><p>You need to:</p><ul><li>Download the correct plugin version for your RabbitMQ version</li><li>Manually copy it to the plugins directory</li><li>Enable it</li><li>Restart RabbitMQ</li><li>Repeat on every cluster node</li><li>Build custom Docker images for Kubernetes deployments</li><li>Track compatibility across RabbitMQ upgrades</li></ul><p>For the client’s IT team, this meant:</p><ul><li>❌ Custom Docker image maintenance</li><li>❌ Plugin version tracking</li><li>❌ Additional documentation</li><li>❌ One more thing that can break during upgrades</li></ul><p><strong>Option C: Application-Level Retries</strong> Implement retry logic in my Spring Boot code. But then, what’s the message broker doing for me?</p><p><strong>Problem #2: Configuration Was Ugly</strong></p><p>Lots of boilerplate. Multiple beans. And crucially: <strong>I still had to write custom code for exponential backoff retry logic anyway.</strong></p><p><strong>Problem #3: The Realization</strong></p><p>After a few days fighting with this, I had a moment of clarity:</p><p><strong>RabbitMQ isn’t actually solving my core problem. I’d have to write custom retry logic regardless.</strong></p><p>If I’m writing custom code anyway, why deal with:</p><ul><li>❌ Manual plugin installation and maintenance</li><li>❌ Complex multi-queue configuration</li><li>❌ Erlang runtime tuning (vm_memory_high_watermark, etc.)</li><li>❌ Higher infrastructure costs (RabbitMQ needs more memory)</li><li>❌ Operational complexity for the client’s 2-person IT team</li></ul><p>The Spring Boot annotations were nice syntactic sugar, but they weren’t worth all this complexity for what should be a straightforward integration platform.</p><p>I decided to give NATS JetStream a serious look.</p><h3>Candidate #2: NATS JetStream — Building It My Way</h3><p>When I discovered NATS JetStream, my first reaction was: “Great, no Spring Boot starter. I’ll have to build everything myself.”</p><p>But then I thought: <strong>I’m building custom logic anyway with RabbitMQ. Why not build it exactly how I want it?</strong></p><h3>What I Built</h3><p>I created my own annotation-based system that does exactly what I need:</p><pre>@NatsListener(<br>            subject = CREATE_SALES_ORDER_ITEMS,<br>            dlq = &quot;sales-order.create-items-dlq&quot;,<br>            initialBackoffMs = 60000,<br>            maxBackoffMs = 300000,<br>            maxAttempts = 5,<br>            backoffMultiplier = 2.0,<br>            autoAck = true<br>    )<br>    public void createSalesOrderItems(SalesOrder order) {<br>   <br>    }</pre><p><strong>One annotation. Everything configured. Exactly the behavior I wanted.</strong></p><p>No plugins. No multiple queues. No complex configuration files. Just:</p><ul><li>✅ Automatic redelivery with exponential backoff</li><li>✅ Configurable retry limits</li><li>✅ Automatic DLQ routing after max retries</li><li>✅ Metrics and observability built in</li><li>✅ Type-safe message handling</li></ul><h3>Real-World Usage</h3><p>Here’s how clean my actual business code looks:</p><pre> @NatsListener(<br>            subject = CREATE_SALES_ORDER_HEADER,<br>            dlq = &quot;sales-order.create-header-dlq&quot;<br>    )<br>    public void create(SalesOrder order) {<br>        try {<br>            log.info(&quot;START: Creating sales order header for contract: {}&quot;, order.getOrderId().value());<br><br>            bcGateway.createDimension(&quot;ORDER&quot;, order.getOrderId().value());<br>            bcGateway.createDimension(&quot;RESORT&quot;, order.getCenterId());<br><br>            bcGateway.createSalesOrderHeader(order);<br><br>            log.info(&quot;SUCCESS: Sales order header created in BC, orderId: {}&quot;, order.getBcOrderId());<br>            publishForNextStep(order, LINK_DIMENSION);<br><br>        } catch (Exception e) {<br>            log.error(&quot;FAILED: Failed to create sales order header for contract: {}&quot;,<br>                    order.getOrderId().value(), e);<br>            handleOrderError(order.getOrderId().value(), e);<br>        }<br>    }<br><br>    @NatsListener(<br>            subject = LINK_DIMENSION,<br>            dlq = &quot;sales-order.link-dimension-dlq&quot;<br>    )<br>    public void linkDimensions(SalesOrder order) {<br>        try {<br>            log.info(&quot;START: Linking dimensions for contract: {}&quot;, order.getOrderId().value());<br><br>            bcGateway.linkSalesOrderDimension(&quot;ORDER&quot;, order.getOrderId().value(), order.getBcOrderId());<br>            bcGateway.linkSalesOrderDimension(&quot;RESORT&quot;, order.getCenterId(), order.getBcOrderId());<br>            bcGateway.linkSalesOrderDimension(&quot;ACTIVITY&quot;, order.getOperationType().name(), order.getBcOrderId());<br><br>            log.info(&quot;SUCCESS: Dimensions linked for contract: {}&quot;, order.getOrderId().value());<br>            publishForNextStep(order, CREATE_SALES_ORDER_ITEMS);<br><br>        } catch (Exception e) {<br>            log.error(&quot;FAILED: Failed to link dimensions for contract: {}&quot;,<br>                    order.getOrderId().value(), e);<br>            handleOrderError(order.getOrderId().value(), e);<br>        }<br>    }<br><br>    @NatsListener(<br>            subject = CREATE_SALES_ORDER_ITEMS,<br>            dlq = &quot;sales-order.create-items-dlq&quot;<br>    )<br>    public void createSalesOrderItems(SalesOrder order) {<br>        try {<br>            log.info(&quot;START: Creating sales order items for contract: {}&quot;, order.getOrderId().value());<br><br>            bcGateway.createSalesOrderItems(order.getBcOrderId(), order.getItems());<br><br>            log.info(&quot;SUCCESS: Sales order items created for contract: {}&quot;, order.getOrderId().value());<br>            publishForNextStep(order, ADDITIONAL_DATA);<br><br>        } catch (Exception e) {<br>            log.error(&quot;FAILED: Failed to create sales order items for contract: {}&quot;,<br>                    order.getOrderId().value(), e);<br>            handleOrderError(order.getOrderId().value(), e);<br>        }<br>    }</pre><p>No configuration files. No bean definitions. Just clean, declarative code that expresses business intent.</p><h3>Deployment: Helm Chart Simplicity</h3><p>This was another pleasant surprise.</p><p><strong>Deploying RabbitMQ on Kubernetes:</strong></p><p>RabbitMQ doesn’t have an official Helm chart optimized for GitOps workflows. You have several options, none ideal:</p><ul><li><strong>Community Helm charts</strong>: Previously maintained by Bitnami (now deprecated), various forks exist but no clear “official” option</li><li><strong>RabbitMQ Cluster Operator</strong>: Adds another layer of complexity, doesn’t really simplify deployment</li><li><strong>Build your own manifests</strong>: Full control, but you’re maintaining everything yourself</li></ul><p><strong>Deploying NATS JetStream:</strong></p><pre>helm repo add nats https://nats-io.github.io/k8s/helm/charts/<br>helm install nats nats/nats</pre><p>Where values.yaml contains:</p><pre>config:<br>  cluster:<br>    enabled: true<br>    replicas: 2<br>  jetstream:<br>    enabled: true<br>    fileStore:<br>      pvc:<br>        size: 2Gi<br><br>promExporter:<br>  enabled: true</pre><p>Done. Two commands. Official Helm chart from the NATS team. GitOps-ready. Production-tested. Small value file.</p><p>For the client’s IT team, this difference was massive. One simple Helm chart vs. building and maintaining their own deployment infrastructure.</p><h3>Monitoring</h3><p><strong>The Missing UI</strong></p><p>I’ll be honest: RabbitMQ’s management UI is fantastic. Real-time graphs, queue inspection, connection monitoring — all in a nice web interface.</p><p>NATS JetStream doesn’t have an official UI comparable to RabbitMQ, but there are some community tools available.</p><p><strong>My Approach: Prometheus Exporter</strong></p><p>I enabled NATS Prometheus exporter (it’s built-in, just needs to be enabled):</p><pre>service:<br>  enabled: true<br>  ports:<br>    nats:<br>      enabled: true<br>    monitor:<br>      enabled: true<br><br>promExporter:<br>  enabled: true</pre><p>The metrics are there and Prometheus is scraping them. I haven’t built a Grafana dashboard yet — that’s on the backlog. For now, I’m monitoring through Prometheus queries and basic alerts.</p><p>Is this ideal? No. RabbitMQ’s UI would be nicer. But for the client’s needs and my time constraints, having metrics exposed and queryable is sufficient. The dashboard will come when there’s time.</p><p><strong>The Reality:</strong></p><ul><li>✅ Metrics are being collected</li><li>✅ Basic alerting is in place</li><li>⏳ Pretty dashboard is “nice to have”</li><li>✅ Client has Prometheus/Grafana already, so it integrates with existing stack</li></ul><h3>The Decision</h3><p>After implementing both approaches, the choice became clear: <strong>NATS JetStream</strong>.</p><h3>Why NATS Won</h3><p><strong>1. I was writing custom code either way</strong></p><p>RabbitMQ’s Spring Boot integration looked appealing, but when I needed specific retry behavior (exponential backoff, configurable retries, DLQ routing), I had to build it myself regardless. Given that, why not build it on a simpler foundation?</p><p><strong>2. Exactly what I need, nothing more</strong></p><p>My @NatsListener annotation expresses business requirements directly:</p><p>java</p><pre>@NatsListener(<br>            subject = CREATE_SALES_ORDER_ITEMS,<br>            dlq = &quot;sales-order.create-items-dlq&quot;,<br>            initialBackoffMs = 60000,<br>            maxBackoffMs = 300000,<br>            maxAttempts = 5,<br>            backoffMultiplier = 2.0,<br>            autoAck = true<br>    )</pre><p>vs. RabbitMQ’s approach:</p><pre>@RabbitListener(queues = &quot;invoice.migration&quot;)<br>// + Configure dead letter exchanges<br>// + Configure retry queues<br>// + Install plugins manually<br>// + Write custom retry logic anyway</pre><p><strong>3. Simpler operations</strong></p><p>The client’s IT team manages one official Helm chart. No Erlang expertise required. No plugin maintenance. No memory tuning. No building custom deployment manifests. They can actually operate this long-term.</p><p><strong>4. Lower infrastructure costs</strong></p><p>NATS is more efficient with resources:</p><ul><li><strong>RabbitMQ</strong>: 4GB memory minimum, grows with queue depth</li><li><strong>NATS JetStream</strong>: 500MB-1GB for our workload</li></ul><p><strong>5. CNCF backing</strong></p><p>NATS is a Cloud Native Computing Foundation <strong>incubating project</strong>. While not yet graduated (like Kubernetes or Prometheus), it’s production-ready, actively developed, and has a growing community. The CNCF backing provides confidence in long-term sustainability, proper governance, and security practices.</p><p><strong>6. Modern &amp; enjoyable</strong></p><p>Honestly? It felt good to work with something modern and clean rather than fighting with established-but-heavy tooling to behave differently than designed.</p><h3>What I’m Missing</h3><p>Let’s be honest about the tradeoffs:</p><p><strong>✗ No official UI</strong> RabbitMQ’s management interface is excellent. I miss it. But Prometheus/Grafana covers what we need.</p><p><strong>✗ Smaller ecosystem</strong> Fewer Stack Overflow answers. More reading documentation. But for this specific use case, I didn’t need a massive ecosystem.</p><p><strong>✗ I built it myself</strong> My custom annotation framework is ~500 lines of code I maintain. But:</p><ul><li>I’d have written similar code for RabbitMQ anyway</li><li>I understand it completely (no black boxes)</li><li>It does exactly what I need</li></ul><p><strong>✗ Less familiar to the team</strong> The client’s IT team knew RabbitMQ by name. NATS was new. But the simplicity helped — it’s actually easier to learn than RabbitMQ’s complexity.</p><h3>Lessons Learned</h3><h3>1. “Industry Standard” Isn’t Always Right</h3><p>RabbitMQ is proven and mature, but that doesn’t mean it’s the best fit for every use case. For a straightforward integration platform, its complexity was overkill.</p><h3>2. Sometimes Building Your Own Is Better</h3><p>When existing solutions don’t fit your requirements naturally, building on a simpler foundation can be cleaner than fighting with a complex tool to behave differently.</p><h3>3. Operational Simplicity Matters</h3><p>The client’s IT team was a key constraint. A solution they can actually operate long-term is more valuable than one with more features they’ll never use.</p><h3>4. Modern Tools Can Be Production-Ready</h3><p>NATS being newer doesn’t mean it’s not production-ready. <strong>CNCF incubating status</strong>, active development, and growing adoption gave confidence.</p><h3>5. Enjoy Your Tools</h3><p>This matters more than people admit. Working with NATS was enjoyable. The clean design, good documentation, and helpful community made development faster and more pleasant.</p><h3>The Bottom Line</h3><p>For this accounting migration and integration platform, <strong>NATS JetStream with custom annotations</strong> proved to be the right choice.</p><p><strong>Choose NATS JetStream if:</strong></p><ul><li>You need specific behavior (like exponential backoff) that isn’t built-in elsewhere</li><li>Operational simplicity is critical</li><li>You have a small team managing infrastructure</li><li>You’re comfortable building exactly what you need</li><li>Cost efficiency matters</li><li>You value modern, clean design</li></ul><p><strong>Choose RabbitMQ if:</strong></p><ul><li>You need its specific features out-of-the-box (management UI, plugin ecosystem)</li><li>Your team already knows RabbitMQ well and has deployment experience</li><li>You’re integrating with existing AMQP infrastructure</li><li>You prefer not to build custom frameworks</li><li>You have resources to maintain custom Kubernetes deployments</li><li>You want maximum community support and Stack Overflow answers</li></ul><p><strong>The Real Lesson:</strong> Don’t choose technology based on “industry standard” or hype. Understand your actual requirements, prototype both options, and pick what fits your constraints — team size, operational capabilities, budget, and timeline.</p><p>For this project, building intelligent retry handling on NATS JetStream’s simple foundation beat fighting with RabbitMQ to behave differently than designed.</p><h3>Resources</h3><p><strong>NATS JetStream</strong></p><ul><li>Official docs: <a href="https://docs.nats.io/nats-concepts/jetstream">https://docs.nats.io/nats-concepts/jetstream</a></li><li>GitHub: <a href="https://github.com/nats-io/nats-server">https://github.com/nats-io/nats-server</a></li><li>NATS by Example: <a href="https://natsbyexample.com/">https://natsbyexample.com/</a></li><li>Official Helm Charts: <a href="https://github.com/nats-io/k8s">https://github.com/nats-io/k8s</a></li></ul><p><strong>RabbitMQ</strong></p><ul><li>Official docs: <a href="https://www.rabbitmq.com/documentation.html">https://www.rabbitmq.com/documentation.html</a></li><li>Spring AMQP: <a href="https://spring.io/projects/spring-amqp">https://spring.io/projects/spring-amqp</a></li><li>Cluster Operator: <a href="https://github.com/rabbitmq/cluster-operator">https://github.com/rabbitmq/cluster-operator</a></li><li>Delayed Message Plugin: <a href="https://github.com/rabbitmq/rabbitmq-delayed-message-exchange">https://github.com/rabbitmq/rabbitmq-delayed-message-exchange</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b7bc739f540" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>