<?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 Pratish Bhatnagar on Medium]]></title>
        <description><![CDATA[Stories by Pratish Bhatnagar on Medium]]></description>
        <link>https://medium.com/@pratish.bhatnagar?source=rss-ae4b39efe6f9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HQsmzu6OWsRC6A4C</url>
            <title>Stories by Pratish Bhatnagar on Medium</title>
            <link>https://medium.com/@pratish.bhatnagar?source=rss-ae4b39efe6f9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 16:06:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pratish.bhatnagar/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 We Scaled Up The Sales Catalog API]]></title>
            <link>https://blog.dtdl.in/how-we-scaled-up-the-sales-catalog-api-19eb582b5c97?source=rss-ae4b39efe6f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/19eb582b5c97</guid>
            <category><![CDATA[scaling-up]]></category>
            <category><![CDATA[api-bottlenecks]]></category>
            <category><![CDATA[throughput]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Pratish Bhatnagar]]></dc:creator>
            <pubDate>Wed, 24 Jan 2024 08:14:21 GMT</pubDate>
            <atom:updated>2024-01-24T08:41:54.940Z</atom:updated>
            <content:encoded><![CDATA[<p>In the digital landscape, APIs are the life of any business. They enable different systems to communicate with each other and exchange data. Now this communication and transfer of data needs to be as fast as possible. This becomes even more concerning when there are special events and a huge or sudden load falls on the APIs.</p><p>For an e-commerce platform, this can be a festive season, a sale, a social media campaign or even a product launch. These scenarios lead to extreme and in some cases sudden, load on the system. The APIs need to accommodate this increased load or spike in traffic to ensure the high availability of the system.</p><p>This brings up the problem at hand, API scaling.</p><h3><strong>Understanding Scalability</strong></h3><p>Scalability of APIs can be achieved either by Horizontal Scaling or Vertical Scaling or by a combination of both these techniques.</p><h4><strong>Horizontal Scaling vs. Vertical Scaling</strong></h4><p>Horizontal scaling involves adding more machines or nodes to your system and distributing the load across multiple servers. This method ensures that the system can handle increased traffic by adding more computing power. On the other hand, vertical scaling focuses on enhancing the existing server’s capacity by adding more resources such as CPU, RAM, or storage.</p><h3><strong>The Problem Statement: Scaling Sales Catalog APIs and OneShop APIs</strong></h3><p>Now let’s move to the problem at hand, scaling Sales Catalog APIs and in turn, scaling OneShop APIs.</p><p>The backstory goes like this — A few months back, the business decided to check how the OneShop performs when put under heavy load and in a sudden burst of traffic. To our surprise, the system did not scale up as expected and instead started failing and throwing errors to the end user. Our device and tariff listing pages had failed us -_-</p><h3><strong>Now, what we did?</strong></h3><p>As any engineer would do when faced with API failures due to load, the first thing we did was to increase the number of Sales Catalog API Pods (Horizontal Scaling). This increased the throughput (the number of successful requests served against a given time period) to an extent but we started getting failures after a point.</p><p>The next thing that came to our mind was to increase the resources available to the APIs. In this case, it meant increasing the number of nodes in our ElasticSearch Cluster and also increasing the size of each ElasticSearch Node in the cluster. This further reduced the number of API failures and provided us with much-needed time to dig deep into this problem.</p><h3><strong>The Next Steps</strong></h3><h4><strong>Reducing the Response Size</strong></h4><p>The next thing we did was to start analyzing the response from each layer, the databases and each API being called to serve the listing response.</p><p>We found out that we were passing HUGE pieces of HTML Content (Thank you Admins :-) ) that were of no use in the listing response. So, we chalked that out. And voila! The APIs started performing as expected! Sadly, this was not the case. The performance improved but was nowhere near what we wanted.</p><h4><strong>Caching — The Way To Go?</strong></h4><p>The next thing we introduced was caching, because why not! We introduced a separate Caching layer in our application. The expectation after introducing caching was clear, blazing-fast responses for duplicate requests. This is what we thought as well. Yet again, this was not the case.</p><p>In our load tests, we found that the throughput did not increase much even after adding a caching layer. It started plateauing around 600 RPS. This is what we had already achieved after scaling up the production environment and was not something we were aspiring for.</p><h4><strong>Thread Dump Analysis</strong></h4><p>The next thing we tried was taking thread dumps from pods and start analyzing them. We found something very unexpected during our analysis.</p><h4><strong>Logs</strong></h4><p>Till this point, we had not expected our logs to be a bottleneck for the application. After all, these are the best weapons we have when fighting a production issue.</p><p>During our thread dump analysis, we found that the application threads were in a WAITING state just to write logs. Now for us, this opened multiple fronts -</p><ol><li>We are printing too many unnecessary logs.</li><li>The log size is very large and needs to be reduced.</li><li>Since our response payload can be fairly large, it meant an increased load on the logging system</li><li>The logs are written in a synchronous fashion</li></ol><p>We performed these steps to overcome these problems -</p><ol><li>We are printing too many unnecessary logs. : We removed the unnecessary logs and updated the log levels as per the severity.</li><li>The log size is very large and needs to be reduced. — We stopped unnecessary printing of objects in logs</li><li>Since our response payload can be fairly large, it meant an increased load on the logging system — We removed the response objects from our logs</li><li>The logs are written in a synchronous fashion — We moved to asynchronous writing of logs</li></ol><h4><strong>Thread Dump Analysis 2.0</strong></h4><p>After fixing the logs, we went again to further analyze the thread dumps. We further found issues with the code. The threads were still in a WAITING state. We found that we were unnecessarily converting objects to string and visa-versa before responding to the request. We fixed this as well and were ready for our last leg.</p><h4><strong>Machine Throughput Limits and Burst Credits</strong></h4><p>After all the optimizations, we started performing regular load tests on the APIs and overnight soak tests. We observed that after multiple successful runs, an odd run would fail unexpectedly or the system would not scale as much or would scale down and plateau to a constant RPS.</p><p>Upon digging deep into this problem, we read about machine network limitations and burst credits. To summarize, each EC2 machine can only send out a limited response size per second. This can be increased by increasing the instance size or momentarily using burst credits.</p><p>Now we had found the answers! :-) We had achieved the limits of the available hardware and were even using the burst credits. This was the reason for the dip in response and plateauing of the RPS graph.</p><h4><strong>Miscellaneous Issues We Encountered — EFS</strong></h4><p>In our tests, we found that the throughput depended upon the state of the AWS Elastic File System as well. This is the place where we write our logs. When the EFS filled up, the RPS reduced and the system would not scale up.</p><h3><strong>The Tools We Used</strong></h3><p>We use ELK Stack for our logging needs. So we leveraged that to plot graphs to measure the response times against the critical operation times. These should be very much near each other.</p><p>We also used Grafana and Prometheus to fetch the critical metrics of the application.</p><p>We also used AWS CloudWatch extensively to get first-hand information on our infrastructure.</p><h3><strong>Conclusion and Way Ahead</strong></h3><p>Using the above-mentioned approach, we were able to increase the throughput of the APIs from 600 RPS to around 2800RPS. Our P95 Graphs also improved indicating the improvement in response times.</p><p>We were able to increase these metrics and the system survives under spikes and huge loads. However, the API performance track cannot be closed and is a never-ending process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0J2tmLCWxc4lh5a9ITEnaA.png" /><figcaption>Peak RPS of ~2.8K and plateau after burst credits expired</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3qkIWUMLxL1T1jUaiIUV7A.png" /><figcaption>Increased RPS and decreased response time in the load runs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFj0sSgQymmvP4rz0t9PPA.png" /><figcaption>Graph of Critical Operations Vs Execution Time</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19eb582b5c97" width="1" height="1" alt=""><hr><p><a href="https://blog.dtdl.in/how-we-scaled-up-the-sales-catalog-api-19eb582b5c97">How We Scaled Up The Sales Catalog API</a> was originally published in <a href="https://blog.dtdl.in/">Deutsche Telekom Digital Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>