<?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 Halil Sarial on Medium]]></title>
        <description><![CDATA[Stories by Halil Sarial on Medium]]></description>
        <link>https://medium.com/@halil.sarial?source=rss-d6a0b5c5d647------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*GpsE1RpfUtldK-vX</url>
            <title>Stories by Halil Sarial on Medium</title>
            <link>https://medium.com/@halil.sarial?source=rss-d6a0b5c5d647------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 09:04:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@halil.sarial/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[How I Solved High-Traffic Error Handling with Spring Reactive Web]]></title>
            <link>https://medium.com/mobileaction-tech/how-i-solved-high-traffic-error-handling-with-spring-reactive-web-5802cf9e8c70?source=rss-d6a0b5c5d647------2</link>
            <guid isPermaLink="false">https://medium.com/p/5802cf9e8c70</guid>
            <category><![CDATA[spring-webflux]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[spring-reactive]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Halil Sarial]]></dc:creator>
            <pubDate>Fri, 03 Oct 2025 06:55:58 GMT</pubDate>
            <atom:updated>2025-10-03T07:09:32.772Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Memory Crashes to Stability</h3><h4><strong>1. Background</strong></h4><p>In one of our projects, we developed an API service responsible for receiving mobile app events generated by users. The service is a critical piece of infrastructure, designed to handle beyond <strong>1000 requests per second (RPS)</strong>.</p><p>Initially, the service was implemented using Spring Web. It worked well in the success path, handling regular requests efficiently.</p><p>But then… I faced a <strong>critical risk</strong>.</p><h4>2. The Problem</h4><p>The trouble started when the service began receiving a <strong>large volume of invalid requests</strong> (e.g., malformed payloads, validation errors).</p><ul><li>Under normal traffic → memory usage was stable.</li><li>Under failure traffic (lots of invalid requests) → <strong>memory consumption spiked rapidly</strong>, and eventually the JVM crashed.</li></ul><h4>Why?</h4><p>Spring Web follows a <strong>blocking, thread-per-request model</strong>:</p><ul><li>Each request occupies a thread until it is completed.</li><li>When too many error cases occur at the same time:</li><li><strong>Exception objects + error responses + logging overhead</strong> accumulate in memory.</li><li>Garbage collection struggles.</li><li>The app eventually goes <strong>OutOfMemoryError</strong> and dies.</li></ul><h4>3. The Solution: Switching to Spring Reactive Web (WebFlux)</h4><p>To solve this, I migrated the service from <strong>Spring Web → Spring WebFlux (Reactive Web)</strong>.</p><h4><strong>Key Reasons:</strong></h4><ul><li><strong>Non-blocking I/O</strong> → threads are not tied up waiting for slow consumers or error responses.</li><li><strong>Backpressure support</strong> → the system adapts if downstream components (or clients) are slower.</li><li><strong>Lightweight memory footprint</strong> → errors don’t pile up in threads like in the blocking model.</li></ul><h4>4. Migration Approach</h4><ul><li>Converted controllers from <strong>@RestController</strong> returning <strong>objects</strong> → to <strong>returning reactive types (Mono, Flux)</strong>.</li><li>Replaced blocking calls with <strong>non-blocking reactive equivalents</strong>. KinesisClient -&gt; KinesisAsyncClient<br>RedisTemplate -&gt; ReactiveRedisTemplate<br>RestTemplate -&gt; WebClient</li><li>Implemented a <strong>global reactive exception handler</strong> (<strong>@RestControllerAdvice</strong>) that returns reactive types instead of large exception payloads.</li></ul><p><em>Example: Reactive Controller</em></p><pre>@RestController<br>@RequestMapping(&quot;/postback&quot;)<br>public class PostbackController {<br>    @GetMapping(&quot;/custom/{apiKey}&quot;)<br>    public Mono&lt;ResponseEntity&lt;Object&gt;&gt; processCustomPostbackInstallEvents(@PathVariable String apiKey, <br>                                                                           @RequestParam String keywordId)<br>    {<br>        KinesisEventDto kinesisDto = new KinesisEventDto(keywordId);<br><br>        return kinesisService.sendToKinesis(apiKey, kinesisDto)<br>                .onErrorMap(e -&gt; e);<br>    }<br>}</pre><h3>5. Results After Migration</h3><p>After switching to Spring WebFlux, the difference was dramatic:</p><p>✅ <strong>Memory usage stabilized</strong> — even under large bursts of invalid requests.</p><p>✅ The service <strong>continued to operate normally</strong> instead of crashing.</p><p>✅ Resource usage decreased because <strong>fewer threads</strong> were required to handle the same throughput.</p><p>✅ The system became <strong>resilient against error floods</strong> (malformed payloads, abusive clients, etc.).</p><h4>Performance Metrics (Memory Usage — Throughput)</h4><p>Below are the performance metrics captured from the Heroku dashboard, highlighting the system’s behavior under real traffic conditions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*twg5nddPyctsVyPSfyaLiQ.png" /><figcaption>Before Migration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wpgv6dtRDIKLpqXsFO9laA.png" /><figcaption>After Migration</figcaption></figure><h3>6. Lessons Learned</h3><ul><li><strong>Spring Web works fine</strong> for synchronous, CPU-bound, and low-traffic apps.</li><li>But for <strong>high-traffic, error-prone, I/O-heavy workloads</strong>, Spring WebFlux shines.</li><li><strong>Reactive programming introduces complexity</strong> (debugging, learning curve), but the benefits in stability and scalability are worth it for critical systems.</li></ul><h3>7. Conclusion</h3><p>Reactive programming isn’t always the answer, but in my case, it <strong>saved the service</strong>. By migrating to <strong>Spring Reactive Web</strong>, I resolved memory spikes, prevented crashes, and developed a service that can <strong>withstand high invalid request rates with ease</strong>.</p><blockquote><em>If your Spring Web app struggles under high concurrency or error storms, it might be the right time to consider </em><strong><em>Spring WebFlux</em></strong><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5802cf9e8c70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mobileaction-tech/how-i-solved-high-traffic-error-handling-with-spring-reactive-web-5802cf9e8c70">How I Solved High-Traffic Error Handling with Spring Reactive Web</a> was originally published in <a href="https://medium.com/mobileaction-tech">MobileAction Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>