<?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 Seemanth Achari on Medium]]></title>
        <description><![CDATA[Stories by Seemanth Achari on Medium]]></description>
        <link>https://medium.com/@seemanthachari?source=rss-a6e89f885a65------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7rO_M3imFIfejh2Z.jpg</url>
            <title>Stories by Seemanth Achari on Medium</title>
            <link>https://medium.com/@seemanthachari?source=rss-a6e89f885a65------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 23:53:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@seemanthachari/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[Everybody needs a good manager ft. SHARDS]]></title>
            <link>https://seemanthachari.medium.com/everybody-needs-a-good-manager-ft-shards-f89d2438d83d?source=rss-a6e89f885a65------2</link>
            <guid isPermaLink="false">https://medium.com/p/f89d2438d83d</guid>
            <category><![CDATA[sharding]]></category>
            <dc:creator><![CDATA[Seemanth Achari]]></dc:creator>
            <pubDate>Tue, 07 Feb 2023 16:16:53 GMT</pubDate>
            <atom:updated>2023-02-07T16:23:30.183Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*gQRlb3f8AecEBpn34rJ0vA.jpeg" /></figure><h4>What is sharding?</h4><p>Sharding is storing a large set of data in logical parts across different machines. It is used to scale out applications in terms of the data they can store and process, to provide better response time and ensure high availability of the application.</p><h4><strong>Where is it used?</strong></h4><ul><li>Large databases: <a href="https://www.mongodb.com/docs/manual/sharding/#:~:text=Sharding%20is%20a%20method%20for,capacity%20of%20a%20single%20server.">MongoDB</a></li><li>ML inference: <a href="https://medium.com/workday-engineering/scaling-multi-tenanted-machine-learning-applications-on-kubernetes-3f744ae543e2">Scaling Multi-tenanted Machine Learning Applications on Kubernetes</a></li><li>Stream processing <a href="https://towardsdatascience.com/introduction-to-stream-processing-5a6db310f1b4#:~:text=sharding%20and%20replication.-,Sharding,a%20key%20with%20each%20record.">Introduction to Stream Processing</a></li></ul><h4><strong>What do we need to do to implement a shard manager?</strong></h4><p>A proper sharding implementation needs to solve many hard problems such as shard placement, load balancing, shard discovery &amp; request routing, and application lifecycle management.</p><p><strong>Load balancing</strong>: We need high availability and a fast response time from the application. Now, the shards are placed in the servers. It is then required that the server not be over capacitated. So the shard manager needs to be mindful of the server state as the application size grows.</p><p><strong>Shard placement: </strong>A shard may have multiple geo-distributed replicas in order to provide resilience against large-scale failures, to shorten network latency to certain clients, or simply to increase the request-handling throughput of the shard. The placement of shard replicas on application servers needs to consider all these factors in addition to balancing load.</p><p><strong>Shard discovery and request routing</strong>: The shards are placed somewhere. There are thousands of them, but which ones are where? And where should we direct a client looking for some small drop in this large ocean of data?</p><p><strong>Application lifecycle management: </strong>More of container lifecycle management, concerned with availability, to handle planned updates and restarts of the containers. It has been observed that planned failures (due to infrastructure/cluster maintenance) occur thousand times more than unplanned failures.</p><p>Sounds like a lot huh? Facebook Inc. came up with a framework called <strong>Shard Manager </strong>(0 effort on the name xD) to ease our lives.</p><p>Introducing <strong>Shard Manager: A Generic Framework for Geo-distributed Applications</strong></p><h4><strong>Architecture of Shard Manager:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*A2zeTtF2Sldo-9UcS8ya_g.png" /><figcaption>Architecture of Shard Manager</figcaption></figure><p><strong>Orchestrator:</strong> The orchestrator is the central managing unit monitoring the health and resource consumption of the shards assigned to servers.</p><p><strong>Allocator:</strong> Whenever a server fails or the load on the server exceeds a certain limit, the orchestrator calls upon the allocator to create a new shard-to-server assignment.</p><p><strong>Service Discovery System:</strong> Once a shard-to-server assignment is generated, the orchestrator distributes this information to the clients via the Service Discovery System.</p><p><strong>Service router:</strong> Each client runs a service router engine to route the requests to appropriate shards.</p><p><strong>SM Task Controller: </strong>As mentioned earlier, most of the times a shard is unavailable is due to the planned failures. Hence SM needs to coordinate with the cluster management engine running underneath (Kubernetes, Twine etc.) to negotiate and be informed of the maintenance jobs.</p><p><strong>ZooKeeper:</strong> Apache ZooKeeper is an open-source server for highly reliable distributed coordination of cloud applications. It is used here to store the persistent state of the orchestrator and keep track of the health of the application servers.</p><h4><strong>How to maintain high availability: Graceful migration of the shard</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*WYJ00JuHu0p547LqZS7f-Q.png" /><figcaption>Graceful primary replica migration</figcaption></figure><p>SM allows for multiple replicas of the shard to load balance the client requests. There is a primary replica and multiple secondary replicas. The primary replica is responsible to resolve the write requests from the clients. In the case where the container hosting the primary replica needs to be shut down, SM follows a graceful transitioning to promote a secondary replica to a primary replica and then allow for a shut down. It is made sure that no client request is dropped.</p><blockquote>1. The P_new is notified that it needs to behave as the Primary now and needs to accept primary related requests from P_old</blockquote><blockquote>2. The P_old is instructed to forward any write requests to P_new</blockquote><blockquote>3. P_new is now officially the primary and can accept primary related requests directly from the client</blockquote><blockquote>4. The clients are notified of the change</blockquote><blockquote>5. P_old is now permitted to drop the shard</blockquote><p>As we can see, the client requests are never dropped during the transition. In case of an unplanned failure, the orchestrator needs to discover that the primary has failed and make other arrangements, the write operations would not be possible till then.</p><h4><strong>Shard Placement and Load Balancing</strong></h4><p>In a geo-distributed application or otherwise also, an application can have many requirements as to where it’s shards are placed. We classify them as hard requirements and soft goals.</p><p><strong>Hard requirements</strong>:</p><p>Server capacity: For each load-balancing (LB) metric (e.g., CPU), the aggregate consumption of all shards on a server should not exceed the server’s capacity</p><p>System stability: Limit the number of shard replicas being moved from a server to avoid network clogging or limit the number of replicas of the same shard that can be moved simultaneously to ensure high availability etc.</p><p><strong>Soft goals:</strong></p><p>Region preference: SM allows a fine-grained control of placing individual shards at different regions</p><p>Spread of replicas: For better availability, it is preferred to place a shard’s replicas across fault domains at all levels, including regions, data centers, and racks.</p><p>Shard Manager uses <em>ReBalancer</em>, a constraint solver which provides a high-level API interface to specify constraints and goals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*W_qGMAWI5kc5fME569Iebw.png" /><figcaption>Examples of specifying hard placement constraints and soft goals using the ReBalancer APIs.</figcaption></figure><p>So if you are looking to develop a sharded application and don’t want to reinvent the wheel while managing your shards, Shard Manager is your go to tool!!</p><p>Now that we know what sharding is and how to manage the shards, someone asked if we could break down the shards even further?</p><p>Introducing <strong>Sharding the Shards: Managing Datastore Locality at Scale with Akkio</strong></p><h4><strong>Micro-sharding: Sharding the shards</strong></h4><p>A micro-shard is a <strong>small</strong> unit of <strong>self-contained</strong> logical data having <strong>access locality</strong>. This means that each micro-shard is independent and there are no references across micro-shards. To give an idea of the size, a typical dataset may contain about 10⁹ to 10¹² micro-shards.</p><p>Micro-shards may mean different things for different applications. For a messaging application, while a shard may refer to all message threads of a few hundred people, a micro-shard may be a single person’s message thread with another person. This example illustrates the independence of micro-shards compared to shards.</p><p>Not everything can be partitioned into micro-shards. Your Facebook friend circle (technically a graph) can’t be constituted into micro-shards. Your posts have access to your friends across the world (no locality) and their reactions may share some interconnections (loss of self-containment).</p><p>A shard typically contains tens of GBs of data and 10–100 shards are assigned to every node. In case of failures, the migration overhead is pretty high. It would make more sense to partition shards into small micro-shards because of a reduction in migration overhead. Since a micro-shard is independent of all other micro-shards, availability of one micro-shard will not affect the availability of other micro-shards.</p><h4><strong>What does Akkio do?</strong></h4><p>The theoretical background behind sharding is to store complete copies of shards in multiple locations across the words to provide better fault tolerance and access times. Akkio adds locality to this discourse to reduce the access times even further. This is done by tracking the data access pattern of the client application and deciding when and where to migrate the micro-shard to. Akkio also tells the client application where to access the micro-shard from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*XGj3jPW856jkyVsJEbKubg.png" /></figure><p>Consider the picture above, the large rectangular boxes inside a datacenter represent the shards, and the small rounded rectangles represent the micro-shards. Due to the high demand of the micro-shard x in Datacenters A and B (maybe x is locality specific), Akkio migrates it from shard 78 in C to shard 1 in A. Since this is a micro-shard this migration does not affect anything else because of no dependencies. Micro-shard x is read-only replicated in all replicas of shard 1. Depending on what the client application demands, Akkio also tells it whether to access x from A or B.</p><h4><strong>Akkio Architecture</strong></h4><p>This might be a good place to mention that Akkio is not responsible for breaking your data into micro shards, it only helps to manage them once the application has done so. Also, migration of the data is the responsibility of the database system your application uses. Akkio is merely the control unit keeping track of access patterns of the micro shards and deciding where they should reside.</p><p>Now, Akkio has three major services:</p><p><strong>Location service:</strong> Deployed in each datacenter, it keeps track of the location of the micro shards. It persists location information in the datastore and maintains a cache to facilitate quick accesses.</p><p><strong>Access Counter Service:</strong> It is deployed in each datacenter and keeps track of where the micro shards are accessed from and the frequency with which they are accessed. This acts as the basis for the Data Placement Service to decide where each micro shard should reside.</p><p><strong>Data Placement Service:</strong> This service is the brain of the architecture, as in it is the decision making unit. It decides where each micro shard should reside. Once the migration process is initiated, it keeps track of the movement and keeps updating the location service of the the location of the micro shard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7pQDHEpp4kAZR6A_9GCWPQ.png" /></figure><h4><strong>Limitations of Akkio</strong></h4><p>Akkio works only on datasets that can be partitioned into micro-shards. As mentioned earlier, there are quite a few examples of datasets which cannot be partitioned into micro-shards. Akkio is of no use in that domain.</p><h4>References</h4><p>[1] <em>Sangmin Lee, Zhenhua Guo, Omer Sunercan, Jun Ying, Thawan Kooburat, Suryadeep Biswal, Jun Chen, Kun Huang, Yatpang Cheung, Yiding Zhou, Kaushik Veeraraghavan, Biren Damani, Pol Mauri Ruiz, Vikas Mehta, and Chunqiang Tang. 2021. Shard Manager: A Generic Shard Management Framework for Geo-distributed Applications. In Proceedings of the ACM SIGOPS 28th Symposium on Operating Systems Principles (SOSP ‘21). Association for Computing Machinery, New York, NY, USA, 553–569. </em><a href="https://doi.org/10.1145/3477132.3483546"><em>https://doi.org/10.1145/3477132.3483546</em></a></p><p>[2] <em>Muthukaruppan Annamalai, Kaushik Ravichandran, Harish Srinivas, Igor Zinkovsky, Luning Pan, Tony Savor, David Nagle, and Michael Stumm. 2018. Sharding the shards: managing datastore locality at scale with Akkio. In Proceedings of the 13th USENIX conference on Operating Systems Design and Implementation (OSDI’18). USENIX Association, USA, 445–460.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f89d2438d83d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KWoC Project Report]]></title>
            <link>https://seemanthachari.medium.com/kwoc-project-report-eacba6b0131b?source=rss-a6e89f885a65------2</link>
            <guid isPermaLink="false">https://medium.com/p/eacba6b0131b</guid>
            <dc:creator><![CDATA[Seemanth Achari]]></dc:creator>
            <pubDate>Fri, 08 Jan 2021 08:02:59 GMT</pubDate>
            <atom:updated>2021-01-08T08:38:16.065Z</atom:updated>
            <content:encoded><![CDATA[<p>Year 2020</p><p><strong>About KWoC</strong><br>Kharagpur Winter of Code is a 5-week long online program for students who are new to open source software development. The program not only helps students to get involved in open source, but also prepares them for many open source summer programs; Google Summer of Code being one of them.</p><p><strong>Project: </strong>Intelligent Question Paper Search (IQPS)<br><strong>Mentor: </strong>Shubham Mishra (<a href="http://github.com/grapheo12">GitHub handle</a>)</p><p><strong>About Project:<br></strong>Intelligent Question Paper Search (IQPS) is a project which aims to provide necessary upgrades to the existing website <a href="https://qp.metakgp.org/">https://qp.metakgp.org/</a> which is a repository for previous year question papers of IIT Kharagpur, using a fully functional web-app.<br><a href="https://github.com/grapheo12/iqps"><strong>GitHub repository</strong></a></p><p><strong>My Experience: <br></strong>My experience in KWoC was enriching. I took part in KWoC to learn to something new, and found a suitable project pretty quick. I chose an issue which would require me to have a proper understanding of whatever I was attempting to do. It really increased my confidence in my ability to comprehensively understand the dynamics of a new system. I was able to make only one pull request, which got merged successfully.</p><p><strong>Issue I contributed to: </strong>Ease of installation<br>The installation process required the user to run two scripts, namely, <em>install.sh</em> and <em>init.sh</em>. I attempted to merge both into one, such the only one would be needed to run.</p><p><strong>Contribution<br></strong>Once the docker container was built and run for the first time (through <em>install.sh</em>), the user was required to manually kill the process upon display of the below message</p><pre>db_1   <strong>|</strong> 2020-05-25 16:37:33 0 [Note] mysqld: ready <strong>for</strong> connections.<br>db_1   <strong>|</strong> Version: &#39;10.4.12-MariaDB-1:10.4.12+maria~bionic&#39;  socket: &#39;/var/run/mysqld/mysqld.sock&#39;  port: 3306  mariadb.org binary distribution</pre><p>I redirected the logs to a hidden text file <em>log.txt, </em>using <strong><em>docker-compose logs — no-color &gt; “.log.txt”; </em></strong>and ran a while loop to periodically pattern-match if the string “<em>mysqld: ready for connections</em>” is present in the file. While doing so, an issue arose that running the above command, printed logs of previous runs as well. <br>To work around that, after making the file <em>log.txt, </em>I ran the command once, and replaced all occurrences of the “<em>mysqld: ready for connections</em>” with “<em>mysqld: was ready for connections</em>” using <strong><em>sed</em></strong>.</p><p>So, when the pattern matched for the first time, I used <strong><em>docker-compose stop;</em></strong><em><br></em>to stop the process from within the script and broke out of the while loop.</p><p>To run the above commands in the same terminal while the container was up, I had to use the <strong><em>docker-compose up -d;</em></strong><em> </em>instead of <strong><em>docker-compose up; </em></strong>to run the processes in background.</p><p>Further, I simply concatenated the <em>init.sh </em>script to the changed <em>install.sh.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CcefVgugT0BDXLEXVo9g0w.png" /><figcaption>Using <em>docker-compose up -d</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CQeYa05RBpfs9tWMsAnqYA.png" /><figcaption>Periodically checking for pattern match</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLDgsCFAcfGNghDtQqbs8g.png" /><figcaption>Stopping the process if pattern matched</figcaption></figure><p><strong>Conclusion<br></strong>The issue was successfully resolved and the installation process became less tedious.</p><p><strong>Gratitude<br></strong>I am thankful to my mentor Shubham Mishra for the guidance and inputs he offered during the coding period and for helping me understand how a web application is deployed in real-time. Lastly, I would like to thank KOSS, IIT Kharagpur for conducting this program and having newbie introduced to the world of open source.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eacba6b0131b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>