<?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 Mohammed Jasil on Medium]]></title>
        <description><![CDATA[Stories by Mohammed Jasil on Medium]]></description>
        <link>https://medium.com/@jasil1414?source=rss-6ed3e33392ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5ZovVyHkeKXJZT6I.png</url>
            <title>Stories by Mohammed Jasil on Medium</title>
            <link>https://medium.com/@jasil1414?source=rss-6ed3e33392ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 15:13:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jasil1414/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[Breaking the Timeout Barrier: A Quest for Customer Satisfaction]]></title>
            <link>https://medium.com/@jasil1414/breaking-the-timeout-barrier-a-quest-for-customer-satisfaction-dfdd9bbe8a3b?source=rss-6ed3e33392ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfdd9bbe8a3b</guid>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[504-gateway-timeout]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[polling]]></category>
            <dc:creator><![CDATA[Mohammed Jasil]]></dc:creator>
            <pubDate>Wed, 08 Jan 2025 05:41:24 GMT</pubDate>
            <atom:updated>2025-01-08T05:41:24.105Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t_rXmji4Vj15jPq35gD1zA.png" /><figcaption>Cloudflare’s Gateway Timeout Error</figcaption></figure><h4>The Gateway Timeout Challenge</h4><p>Imagine you’re a customer dealing with a massive amount of data. You come to our platform to process it, but — boom! A dreaded gateway timeout error strikes. This was exactly the situation for one of our customers, who faced persistent timeout issues while handling large aggregations on our platform.</p><p>At first, the solution seemed straightforward. Our ingress timeout configuration was set shorter than Cloudflare’s default timeout of 100 seconds. We raised the limit, giving longer-running requests a chance to complete. For a time, this worked. But as the dataset grew over the months, the errors returned — this time, even more frequently and severely.</p><p>Faced with the challenge of quickly resolving this, we had two potential options:</p><ol><li><strong>Disabling Reverse Proxying via Cloudflare:</strong><br> This would bypass Cloudflare’s timeout limit but at the cost of losing their robust security features — an option that we weren’t comfortable with.</li><li><strong>Upgrading to an Enterprise Plan:<br> </strong>An enterprise plan would have allowed us to extend the timeout, but it came with a price tag — one that wasn’t feasible for a startup like ours.</li></ol><p>The challenge was clear: We needed a solution that could process large datasets efficiently without overloading our system or compromising the user experience. With Cloudflare’s default 100-second timeout as a limiting factor and the enterprise plan out of reach, we had to find a more sustainable and innovative path forward.</p><h4><strong>A Temporary Fix with Indexing</strong></h4><p>Before diving into architectural changes, we tried to squeeze every ounce of performance out of our existing database. One solution? Adding an <strong>index</strong> to speed up the aggregation queries. The results were promising at first — queries that previously took seconds were now blazing fast.</p><p>But, as the size of the data grew, this optimization began to buckle under pressure. What once worked beautifully soon gave way to the same timeout issues, especially during peak loads.</p><p>It reminded us of our earlier attempt to increase the timeout on our ingress controllers, which initially seemed like a fix until it collided with Cloudflare’s 100ms hard limit. Both fixes, while helpful in the short term, were like band-aids on a deeper problem.</p><h4><strong>The O(n²) Culprit</strong></h4><p>As the timeout issues persisted, We turned our attention to a specific section of code in the aggregation process. It had an <strong>O(n²)</strong> implementation, which seemed like an obvious bottleneck. Assuming this was the root of the problem, We refactored the code to reduce its complexity and thoroughly tested the changes.</p><p>The result? The timeout errors continued to rear their ugly head. While the optimization was important and improved overall performance, it wasn’t the silver bullet we needed.</p><p>This was another critical realization: no single optimization could solve the problem. We needed a more creative, systematic solution.</p><h4><strong>Thinking Outside the Box</strong></h4><p>It was time to shift our perspective. Instead of attacking the problem from the inside (optimizing queries, tweaking code, etc.), we zoomed out and looked at the bigger picture. What if we could break the process into smaller, digestible chunks and focus on managing the user’s experience rather than brute-forcing everything at once?</p><h4><strong>Polling and Caching to the Rescue</strong></h4><p>We designed a <strong>polling and caching strategy</strong> to handle long-running processes without overwhelming the system. Here’s how it worked:</p><p><strong>Step 1: Caching with Redis</strong></p><p>We used <strong>Redis</strong> as our distributed cache to store the aggregation status. Redis was a perfect fit because:</p><ul><li>It was fast and could handle the scale of requests.</li><li>It allowed us to share data across multiple app instances, essential since in-memory caching wasn’t a viable option in a distributed system.</li></ul><p><strong>Step 2: Status States</strong></p><p>Instead of tracking intermediate results, we focused on three simple states:</p><ul><li><strong>Pending:</strong> The aggregation is still in progress.</li><li><strong>Completed:</strong> The aggregation is done, and the report is ready.</li><li><strong>Error:</strong> Something went wrong, and the client should retry.</li></ul><p><strong>Step 3: Real-Time Feedback for Clients</strong><br> Whenever a client sent a polling request, the system would:</p><ul><li>Check the cache to determine the current status.</li><li>If the status was “Pending,” the client was informed to check back later.</li><li>If the status was “Completed,” the client was sent the S3 URL to download the report.</li><li>If the status was “Error,” the cache key was manually invalidated to prevent customers from reading an error state during retries, particularly within the TTL period. This ensured that customers wouldn’t encounter outdated or erroneous information while retrying.</li></ul><p>This approach helped us keep the system lightweight while avoiding redundant computations during the cache invalidation period.</p><p><strong>Step 4: Uploading the Report to S3</strong></p><p>Once the aggregation was completed, the report was generated and uploaded to <strong>S3</strong>. The cache was then updated with the “Completed” status, along with the S3 URL for the client to download the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-cNsMi4rUL9jf2rw2INL0g.png" /><figcaption>Flow diagram illustrating the polling and caching solution for handling aggregation status updates.</figcaption></figure><h4><strong>A Happy Ending for the Customer</strong></h4><p>With the new system in place, the gateway timeout errors disappeared. Customers handling large datasets could now track the real-time progress of their requests, receiving timely updates on the status as it progressed. Once the process was complete, they received a link to download their report, hassle-free.</p><p>This approach not only solved the immediate problem but also set the stage for scalable solutions as our platform grows. It’s a story of turning constraints into creativity and using polling, and caching to deliver a better customer experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfdd9bbe8a3b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>