<?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 Clovis Carmezini on Medium]]></title>
        <description><![CDATA[Stories by Clovis Carmezini on Medium]]></description>
        <link>https://medium.com/@cloviscarmezini14?source=rss-93b214d4353------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3rRJHbxguHnnrEu1gGyfAQ.jpeg</url>
            <title>Stories by Clovis Carmezini on Medium</title>
            <link>https://medium.com/@cloviscarmezini14?source=rss-93b214d4353------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:07:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cloviscarmezini14/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[The Importance of Optimized Algorithms in Large-Scale Environments]]></title>
            <link>https://medium.com/@cloviscarmezini14/the-importance-of-optimized-algorithms-in-large-scale-environments-73503a1d3696?source=rss-93b214d4353------2</link>
            <guid isPermaLink="false">https://medium.com/p/73503a1d3696</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[better-programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Clovis Carmezini]]></dc:creator>
            <pubDate>Wed, 22 Jul 2026 21:52:10 GMT</pubDate>
            <atom:updated>2026-07-22T21:52:10.544Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zpiYHyvA8LaFUlW6-2j-ZA.png" /></figure><p>As a Software Engineer and Tech Lead, I participate in planning sessions and feature development every day. But like many developers, a lot of what I do is already abstracted away. The language I work with most frequently today (JavaScript) <strong>abstracts</strong> away all the low-level <strong>complexities</strong> that languages like C force us to manage. Over the years, we end up dealing mostly with <strong>surface-level </strong>and <strong>basic problems</strong> when it comes to pure algorithms — such as avoiding exponential iterations, or choosing the appropriate libraries and methods.</p><p>That being said, I believe that even if I don’t have the opportunity to work with <strong>low-level code on a daily basis</strong>, it is crucial to understand and clearly keep in mind how to apply the right a<strong>lgorithm for each problem</strong>.</p><p>So recently, I started practicing Data Structures and Algorithms (DSA). Even though I understood the theory from college, I decided to <strong>dive deeper</strong> and investigate how choosing an appropriate algorithm <strong>impacts</strong> a real <strong>production</strong> environment.</p><p><strong>Spoiler:</strong> The answer can be a bit disappointing, because in reality… it depends!</p><p>Let’s assume we are talking about minimally functional algorithms (without obvious bottlenecks). For learning purposes, let’s consider a scenario where we need to return a user’s <strong>X most listened-to tracks</strong>.</p><p>A few factors will contribute to understanding whether it makes a REAL difference:</p><ul><li>The volume of people <strong>consuming</strong> this algorithm.</li><li>The <strong>volume of data</strong> being manipulated (number of users, tracks, listen counts).</li></ul><p>Considering that this calculation happens on the <strong>backend</strong>: the slower the request, the more people remain “plugged” into the server <strong>simultaneously</strong>. The longer a request takes, the higher the chance of this number <strong>multiplying</strong>, as other users continue to use the service normally while the server hasn’t resolved the ongoing requests. This escalates the issue further, demanding more server resources, increasing costs, and creating a real risk of <strong>overloading</strong> the server.</p><p>If your environment is small — say, around <strong>1,000</strong> daily visits, <strong>100</strong> users, and a small track catalog — you will hardly see a REAL difference that justifies immediately implementing something more elaborate.</p><p>On the other hand, a <strong>major streaming platform</strong> offering this feature might have <strong>50,000</strong> people consuming this data simultaneously, holding a <strong>massive</strong> volume of data to process. In this scenario, the game changes completely: every millisecond counts!</p><p>To make this scenario more <strong>tangible</strong>, I built a lab with mock data. In this lab, I can simulate both the number of users accessing our system concurrently and how many tracks enter the list for computation. With this setup, we can simulate both scenarios mentioned above.</p><p>The method receives 2 parameters:</p><ol><li><strong>data:</strong> a list of X<strong> </strong>items containing the user’s overall consumption, formatted like this:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DQ2JSKUmmqGvCHFV" /><figcaption>User consumption representation</figcaption></figure><p>2.<strong> K :</strong> the number of top-listened tracks we want to retrieve.</p><p>Now, let’s look at <strong>two common solutions </strong>for this type of problem:</p><p>The quickest and simplest way to solve this is to sort the plays field (how many times the user listened to a track) using a <strong>SORT</strong> algorithm and slice the list to keep the first K items, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uq19lFpOrWhMdtDf" /><figcaption>Algorithm using SORT</figcaption></figure><p>Simple, right?</p><p>For a small number of elements, this indeed <strong>solves the problem</strong>. But on a large list, it becomes a bottleneck.</p><p>In <strong>Big O</strong> notation, the time complexity of this algorithm is O(N Log N), meaning that for every item in the list, we have to reorder the array, reading and reorganizing <strong>100% </strong>of the array in the worst-case scenario.</p><p>The second solution for this problem is using a <strong>MinHeap</strong> (<a href="https://www.geeksforgeeks.org/dsa/binary-heap/"><em>understand MinHeap here</em></a>).</p><p>Since a MinHeap creates an ordered binary tree from smallest to largest value, we create a MinHeap of size K, iterate through data, allow a new value into the MinHeap whenever it is <strong>greater than the current top</strong>, and remove the top value that was &quot;surpassed&quot;.</p><p>In practice, the code looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X6ycV8RxnMhDKxVZ" /><figcaption>Algorithm using MinHeap</figcaption></figure><p><strong><em>Note:</em></strong><em> In JavaScript, we need to create a class implementing the MinHeap manually, as unlike languages like Python, JS doesn’t provide one natively.</em></p><p>This algorithm is much more complex than the first one, but significantly more efficient. Instead of reordering an entire list, it ignores most of the values that are not eligible (values smaller than the top of the MinHeap).</p><p>In terms of <strong>Big O</strong>, this solution is O(N Log K), where N is the total number of elements and K is the number of top items we want to retrieve.</p><p>Alright, enough code, let’s jump into practice, shall we? Is there really a relevant difference between the two?</p><p>I built a <strong>benchmark</strong> script that runs both algorithms in isolated OS child processes across 5 different rounds (eliminating execution bias). It works as follows:</p><p>I specify the number of simulated users, and each user gets a generated list of tracks to be calculated.</p><p>This allows me to simulate these algorithms in both a small-scale and a large-scale system.</p><p>Keep in mind that this is a <strong>SIMULATION</strong>. A real production environment is far more complex and involves many other factors that can impact performance, but for educational purposes, this setup helps us understand the scale of the problem and the true impact of optimized algorithms.</p><p>Here are the test results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dDPm6XYDONsnYW20rsJksA.png" /><figcaption>Small-scale environment results</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u4N0-YwwNLXg7qvrbnqVrg.png" /><figcaption>Large-scale environment results</figcaption></figure><p>Incredible, isn’t it? The difference as the system scales is huge.</p><p><strong>Conclusion:</strong></p><p>In the low-traffic scenario, the <strong>Sort algorithm</strong> performed <strong>1.21x better</strong>, with a difference of just 0.32 ms (1.79 ms vs 1.47 ms). Regardless of which algorithm was used, the choice would not impact user experience or overload a server. If your system is an MVP with low traffic, you can afford less performant algorithms — overthinking these details might even become over-engineering and delay your project’s progress. However, if your project has growth projections, this should be mapped as technical debt to be addressed in the future.</p><p>At large scale, the impact is astronomical: there is nearly a <strong>3-second difference</strong> (2921.89 ms vs 161.29 ms) in favor of the <strong>MinHeap</strong>. In this scenario, deploying less efficient algorithms should not be an option unless you are targeting small audiences. For a broad user base, this choice could cost you service availability.</p><p>One point that stands out to me based on my experience as a Tech Lead: for our use case, the less performant solution for large scale (Sort) can easily become a <strong>trap</strong>. To <strong>less attentive eyes</strong>, the solution might not even be perceived as a problem, given that it’s short code, uses a traditional pattern, and leverages built-in JavaScript methods.</p><p>By the time the “bomb” goes off, it’s already too late.</p><p>If you’re interested in seeing the full code, check out the repository on my GitHub <a href="https://github.com/cloviscarmezini/benchmark-minheap-vs-sort/blob/main/main.js">[here]</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73503a1d3696" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>