<?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 archana narayanan on Medium]]></title>
        <description><![CDATA[Stories by archana narayanan on Medium]]></description>
        <link>https://medium.com/@archananarayanan223?source=rss-2c3290b88d04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*LHVv8iK-sLkFzDu0</url>
            <title>Stories by archana narayanan on Medium</title>
            <link>https://medium.com/@archananarayanan223?source=rss-2c3290b88d04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 01:57:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@archananarayanan223/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[Designing a Rate Limiter]]></title>
            <link>https://medium.com/@archananarayanan223/designing-a-rate-limiter-aef470e67946?source=rss-2c3290b88d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/aef470e67946</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[rate-limiter]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[redis]]></category>
            <dc:creator><![CDATA[archana narayanan]]></dc:creator>
            <pubDate>Sun, 19 May 2024 03:25:41 GMT</pubDate>
            <atom:updated>2024-05-19T03:25:41.154Z</atom:updated>
            <content:encoded><![CDATA[<p><em>First of all, WHY?</em></p><blockquote>- Prevent resource starvation caused by DOS (Denial of Service)</blockquote><blockquote>- Reduce cost by limiting excess requests — ie. fewer servers &amp; allocating more resources to high-priority needs.</blockquote><blockquote>- Prevent servers from being overloaded — caused by bots or me, just trying to test if a service has Ratelimiter designed as part of their defense strategy ;)</blockquote><p>But seriously, do you not include a Ratelimiter as part of your design? come on, we all know better by now!</p><h4>Types of RateLimiting Algorithms —</h4><ol><li>Token Bucket — Easy to implement, Memory Efficient</li></ol><p><em>one token for each user/ IP / any other unique entity.</em></p><blockquote>1. Start at a pre-defined set of <strong>x</strong> tokens in each bucket.</blockquote><blockquote>2. Each request is matched with a token &amp; the request goes through</blockquote><blockquote>3. If there are no tokens left in the bucket, the request is denied.</blockquote><blockquote>4. we have a refill <strong>y </strong>— ie. to refill the bucket with new y tokens after a set of periods.</blockquote><p>2. Leaky Bucket — Easy to Implement, Memory Efficient</p><blockquote>we use a queue of fixed size and if the queue overflows, we ignore those requests.</blockquote><blockquote>The requests that are queued are processed at a fixed rate, therefore this type of algorithm is more suited for applications with stable outflow.</blockquote><blockquote>If we think about it, a major flaw in this algorithm especially for implementing it for today’s applications — A burst of traffic can fill up the queue, dropping all the latest requests.</blockquote><p>3. Fixed Window Counter —</p><blockquote>The timeframe is divided into windows of fixed size and each window is rate limited by no.of.requests.</blockquote><blockquote>Eg: if the window size is 1 minute and the number of requests allowed is 5, then we allow 5 requests from 2:01–2:02, and 5 from 2:02–2:03 …, any requests exceeding this count will be denied.</blockquote><blockquote>now let’s say, we maintain the same configuration above - however, the request pattern is — 0 requests at 2:01, 3 requests at 2:013, 2 requests at 2:015, 2 requests at 2:02, and 3 requests at 2:023.</blockquote><blockquote>we still have 5 requests during the window 2:01–2:02, but how about the window from 2:013–2:023 ?, which is still about the same time BUTTT…..</blockquote><blockquote>yes, we have 10 requests, exceeding the configuration.</blockquote><p>4. Sliding Window Counter — Not Memory Efficient, Complex Implementation, addressing flaws from the algorithms above.</p><blockquote>we maintain a log, that allows x no.of.requests within the range [t, t+y) time. If the request exceeds the limit x and within the time limit, we deny the request. If the request exceeds x, but away from the time limit, the new limit is logged and the previous entry is removed.</blockquote><blockquote>Eg: if we receive a request at 2:01, we create a new log as [2:01, 2:10), and set a limit x for requests in these limits. Any request within the time limit, exceeding x requests count, will be denied. When a new request comes in at 2:15, which happens to be say (x+n)th request, we allow the request and set the new log as [2:15, 2:25), linearly moving the window frame.</blockquote><h4>Types of Rate Limiting —</h4><p>Apart from deciding what kind of algorithm we would want to use, we can also explore ways on how we want to utilize these algorithms.</p><ol><li>Request Rate Limiting — Simple and Straightforward, one type of configuration for the complete application. E.g. 100 requests/user for 50 secs.</li><li>Concurrent Rate Limiting — We maintain a list of requests in progress and set a limit on this list instead of setting complete control over the count. This type of configuration is highly useful when we have resource constrained applications. We can allow/deny requests based on resource utilization.</li><li>Load Shedding — We configure the request count based on the type of traffic, i.e. we allocate x count for non-critical resources and y &gt; x for critical resources. If these request types exceed the threshold (respectively), we deny the requests.</li><li>Worker Utilization Load Shedding — This type of configuration is more on the recovery side of rate limiting. If threads are executing different types of requests, and the utilization seemingly exceeds, then we start dropping requests/threads with the least critical traffic and keep dropping until the service is stable again.</li></ol><h4>Implementing the Rate Limiter — (finally !)</h4><p>Designing the rate limiter, with the knowledge of the above basics, might sound simple — but it involves all the characteristics of a full-fledged service that should be highly available, with minimum latency — i.e. We want it Distributed.</p><p>The major consideration here is the type of storage that we want to use to store the user and request details — such as IP, Request Tags, TimeStamp, etc. These are very primitive data and would not require the full-blown functionality of a SQL or NoSQL database.</p><blockquote>I decided to use Redis, to implement my Rate Limiter — which incorporates Token Bucket Algorithm and exposes 2 different APIs to understand request rate limiting and concurrent rate limiting.</blockquote><p>The application is developed using Go with Gin web framework and Redis as Data Storage.</p><p>With inherent support for Horizontal Scaling using Redis Cluster, we can address both High Availability and by distributing the shared — we can achieve low latency, with minimum LLC (low-level code).</p><p>The application has 2 APIs —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngfyjEQd6bXd-y9TWdetqA.png" /><figcaption>go-swagger (swaggo)</figcaption></figure><p>with different configurations for critical requests and general requests —</p><pre>NONCRITICAL: {<br>      REFILL_RATE: 15,<br>      REFILL_TOKEN: 4,<br>      BUCKET_SIZE: 4<br>    }<br>CRITICAL : {<br>      REFILL_RATE: 30,<br>      REFILL_TOKEN: 8,<br>      BUCKET_SIZE: 10<br>    }</pre><p>Every time the service receives a request, we extract the IP information of the service and access the corresponding bucket. These APIs can be further extended to redirect the requests on granted access and respond with 429 (TooManyRequests) when the request limit is reached.</p><h4>Configure Redis with Horizontal Scaling —</h4><p>We are building Redis as docker containers, configuring both the master and the slave instances.</p><p>Setup the configuration file for each node with</p><pre>port 6372<br>cluster-enabled yes<br>cluster-config-file nodes.conf<br>cluster-node-timeout 5000<br>appendonly yes</pre><p>remember, we have 6 Redis instances to be created, therefore 6 config files or we can automate the creation of these files by executing scripts.</p><pre>redis-1:<br>        image: redis<br>        command: redis-server /usr/local/etc/redis/conf/redis.conf<br>        volumes:<br>            - ${PWD}/redis/node-1/:/usr/local/etc/redis<br>        ports:<br>            - &quot;6372:6372&quot;<br>        network_mode: &quot;host&quot; <br>  redis-2:<br>        image: redis<br>        command: redis-server /usr/local/etc/redis/conf/redis.conf<br>        volumes:<br>            - ${PWD}/redis/node-2:/usr/local/etc/redis<br>        ports:<br>            - &quot;6373:6373&quot;<br>        network_mode: &quot;host&quot; <br>  redis-3:<br>        image: redis<br>        command: redis-server /usr/local/etc/redis/conf/redis.conf<br>        volumes:<br>            - ${PWD}/redis/node-3:/usr/local/etc/redis<br>        ports:<br>            - &quot;6374:6374&quot;<br>        network_mode: &quot;host&quot; <br>  redis-4:<br>        image: redis<br>        command: redis-server /usr/local/etc/redis/conf/redis.conf<br>        volumes:<br>            - ${PWD}/redis/node-4/:/usr/local/etc/redis<br>        ports:<br>            - &quot;6374:6374&quot;<br>        network_mode: &quot;host&quot; <br>  redis-5:<br>        image: redis<br>        command: redis-server /usr/local/etc/redis/conf/redis.conf<br>        volumes:<br>            - ${PWD}/redis/node-5:/usr/local/etc/redis<br>        ports:<br>            - &quot;6376:6376&quot;<br>        network_mode: &quot;host&quot; <br>  redis-6:<br>        image: redis<br>        command: redis-server /usr/local/etc/redis/conf/redis.conf<br>        volumes:<br>            - ${PWD}/redis/node-6:/usr/local/etc/redis<br>        ports:<br>            - &quot;6377:6377&quot;<br>        network_mode: &quot;host&quot; </pre><p>Build the containers with</p><pre>docker-compose up --build</pre><p>Once the containers are up, we can configure our cluster by executing —</p><pre>redis-cli --cluster create 127.0.0.1:6372 127.0.0.1:6373 127.0.0.1:6374 127.0.0.1:6375 127.0.0.1:6376 127.0.0.1:6377 --cluster-replicas 1 --cluster-yes</pre><p>At the end of the command, the runtime will respond with an <strong>OK</strong>, indicating the successful creation of masters and their slaves.</p><p>We can access the redis instances by using the default redis port — 6379 as part of our application. Based on the key hash and the shard mapping, the data will be distributed amongst our instances.</p><p>source code — <a href="https://github.com/archananarayanan/RateLmiter">https://github.com/archananarayanan/RateLmiter</a></p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aef470e67946" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Modern Fairytale]]></title>
            <link>https://medium.com/@archananarayanan223/the-modern-fairytale-d495af5331df?source=rss-2c3290b88d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/d495af5331df</guid>
            <category><![CDATA[dog-lover]]></category>
            <category><![CDATA[dog-love]]></category>
            <dc:creator><![CDATA[archana narayanan]]></dc:creator>
            <pubDate>Sat, 28 Nov 2020 08:12:42 GMT</pubDate>
            <atom:updated>2020-11-28T08:21:44.977Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s a warm summer morning, sun beaming right through the white framed window. Beethoven’s medley was playing from Alexa. Although, the house sounded like a 90’s jazz stage. With Beethoven’s lighting key strokes, quick 3 minute whistles from the pressure cooker, irritating “Grrrrr….” from the grinding juicer making avocado drink and the yelling of jack and diya, the modern day couple who just moved into a stunning apartment at a whopping 18th floor with a view of a magnificent garden on one side and the necklace lake on the other.</p><p>The cute couple is a social media buzz, they own an Instagram handle “One_True_Love” which is a major hit. Me and diya worked together at Gap as fashion designers. We work with major celebrities and went from rages to riches. Jack has his own business and stays home all day. I rang the door bell and picked her up from the apartment. All along the ride, she prattled about the fight they had back at home. We had an important meeting with Gucci that afternoon. She was anxious and in a hurry. Jack, being the sweet guy that he is, approached her to plant a kiss. As he went up to her, he accidentally stumbled upon the crystal lady in the shelves , that was presented as an award and broke. AND THE MUSIC STARTS… diya stormed out of the house.</p><p>We crossed the beach where jack and diya used to spend most of their time, it’s enroute to the restaurant where we had the meeting. I remember she telling me that one day when they were taking a walk by the shores, It was one of their first dates back then. she went up to a store to buy a fancy white shell, she is very fond of em. When she came back she found jack to be gone. Diya was embarrassed and felt awkward with such a behaviour from the guy for whom she is going crazy about. She started crying and walked back. To her surprise, there was jack, standing next to her car with a big ocean shell that he picked up from the shore. Diya was overwhelmed with tears as she recollected the glass bowl of shells that they picked from every walk on that very beach. I provided her solace to my very best and we prepped for the meeting for the rest of the ride.</p><p>As we reach the restaurant, the Gucci man was waiting in the lobby. We approached him with a confident gleam and pitched the new silhouette sequel. Awed by the idea, he accepted the deal and invited us for dinner. With the new win and the excitement of our dream come true, we completely forgot about the two year anniversary dinner with jack. Yes, it’s their two year. It was already 10, as we finished up our dinner he handed us a gift and left. We were headed back home when diya asked me to stop at the beach. We soaked our feets in the ocean and sat near a stranded boat. Diya took out her gift and bursted out in tears as she saw the red bow wrapped around. It resembled the bow that jack wore when they first met. As she opened the wrap, unveiled a frame with a picture of her &amp; jack on the beach which was taken a year back, the picture with highest hearts in her Instagram. Unable to hold back her emotions, diya rushed back home and I drove to mine. The End</p><p>I stopped and smiled at Dave , who by the way was my best friend. We were having dinner and happened to talk about love. I continued , “ So, when you ask me what it is like to fall in love and if I were pressed to answer, I’d say maybe it’s a bit like walking through a forest and finding yourself lost in the ocean. It’s unclear. Despite being lost, you start admiring the waves. Like when diya left home to be away from jack, but he is all she can think about for the rest of the day. And, that my man is Love ”. With a twinkle in his eye &amp; a smile in his lips, Dave asked about what jack did when diya reached home.</p><p>Jack being jack, ofcourse was worried sick and waited by the door for her. As soon as she stepped in, jack jumped on top of her, kissed all her face and wagged his tail all night with rejoice, as the love of his life had returned !!</p><p>— To all the Dog Lovers out there ❤</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d495af5331df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dear moon,
The world is in a bad shape now.]]></title>
            <link>https://medium.com/@archananarayanan223/dear-moon-the-world-is-in-a-bad-shape-now-4e5ccef9299a?source=rss-2c3290b88d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e5ccef9299a</guid>
            <category><![CDATA[moon]]></category>
            <category><![CDATA[letters]]></category>
            <dc:creator><![CDATA[archana narayanan]]></dc:creator>
            <pubDate>Sun, 10 May 2020 06:44:16 GMT</pubDate>
            <atom:updated>2020-05-10T06:44:16.457Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*mqzMWOGaDHsWJs9ocql6QQ.jpeg" /></figure><p>Dear moon,<br>The world is in a bad shape now. Wars, quakes , germs and tantrums everywhere. Amidst this chaos, how do you manage to shine so big and bright. Years of deprived silence finally hits the ears of people and made them realise what’s real after all. The loud prayers from the mosque suddenly doesn’t seem to be divine, but the cheers from the neighbour on winning the game of carrom with his family does. Its like when you are in love, days are long, time is meaningless, happy that we spend time with our family, sad that we are losing our other families, caged and the same time freedom from the routine. Is it boon or bane? But at this minute, nothing really matters to me, but your gleam. None of the things that is surrounding me feels right, but your trance of sliver light, that aligns with my strand of hair does. Too fanatic to be true, but so is life - a luicd dream. How does the world look for you from there, is it calmer than ever, did the bird feel wierdness in the silence. Are the trees aligned on the street feeling alive again. Ruthless! We were. Tainting the earth as on to adhere, creed caste and class. To what yield, stagger at lives far afield. Despite the melancholy i try to form a montage, soothing to the eye, swerve my mind to the sweven of the breaking dawn- The annoying cock-a-doodle-do of the rooster, the blaring ding-dong of the milkman, awakened by the exasperating Suprabhātam, refusing to set foot outside the porch and get to work. The roaring enfields and the vrooming fzs, passing past my honda pleasure (mi amor), keeping up with the gusting wind, screeching round the bend. Code, compile and test all day with sundry other hustles, along with ceasless farce, puns and gossips. Feeling the tick of my watch, worn out and weary, I cruze back home. Exhilarated by the bow-wow of pluto, changing into PJs, lazing around as he comes back home to plant the perfect kiss. Warmer as we get, the twilight passes by with the hopes for the crack of dawn. As the alarm buzzed, I snapped out. Recoiling by minutes, I realised how calm the world was despite the mayhem. For we are lost stars trying to light up the dark, scuffling in the realms of space, attempt to revive humanity. Until then, I settle down in the depths of dreams, wake me just as you have done your magic work of making species what they are and the world not as it seems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e5ccef9299a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TRACK — The iron Railings, Athlete’s opportunity, the Journey]]></title>
            <link>https://medium.com/@archananarayanan223/track-the-iron-railings-athletes-opportunity-the-journey-1b4923b7150b?source=rss-2c3290b88d04------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b4923b7150b</guid>
            <category><![CDATA[thoughts]]></category>
            <category><![CDATA[life]]></category>
            <dc:creator><![CDATA[archana narayanan]]></dc:creator>
            <pubDate>Sat, 14 Dec 2019 11:37:30 GMT</pubDate>
            <atom:updated>2019-12-14T11:37:30.963Z</atom:updated>
            <content:encoded><![CDATA[<h3>TRACK — The iron Railings, Athlete’s opportunity, the Journey</h3><p>As I board my train, Again! getting back to the routine, I started wondering why there is always a rush in people’s life? Do you happen to stop or pause for a moment in the race called <strong>life</strong> as it happened. “Rush”, such a strong word, like my mom saying “Hush, Little baby don’t cry”. As the train’s carriage carries all the coal, where is all the load stressed. Is it on the carrier or the wheels that hold on to the carrier or the tracks in which the wheels move phases. Throughout the path we don’t realize that there is a load, we move towards the destination in a rush. How did something physical (the load) become something imaginary and at the destination that becomes the hypothesis for which the journey started. If we notice, the journey for the carrier, wheel and the track has a pause. Wherever the weight maybe stressed does not matter. They take a pause, relax on the break, get them a fresh start if necessary. But do we give ourselves such a break to get ourselves restarted or reframed? Most of the times we don’t. We often rush towards the destination without knowing the purpose.</p><p>People say that <strong>life is a running race.</strong> If it is so then who gets to decide the winner. Does not make sense. Even if it is a race, <strong>Observe </strong>! observe the booing and the cheering crowd, seek out to the ones who wants to rise along. Be thankful to the cheering crowd if there is any. And if you get to complete the race, get to see the crossing line; if there is no one on the other side to give you the big winning hug or to rise you up when you cross the line with all the energy lost; if there is no one to see you have your big victory moment, then whats the point of finishing the bloody race. Whats the point if there is no one to share your big moment with. <strong>Take a Pause </strong>! may be the person on the other side is the one who ran the race along with you, just crossed you to hold you when you reach the line. Just because you didn’t notice doesn’t mean that the other person skipped the race. Sometimes the race path changes leading you to a different cheering crowd, to a different finish line. The longer the race, the greater the feel of victory will be.</p><p>Now lets relate these metaphors to something associated us. We’ll start with the load, something we always assume that we carry along. We carry lot of load without knowing their actual purpose, but at the end no matter what we carry, we just unload them all assuming that they’ve given us a purpose to exist. Now the wheels, people who hold on to us no matter what and support our deeds. People who wait for us at the finishing line to celebrate <strong>our victory. </strong>The Tracks- that leads to our destination, sometimes switches according to our journey. No one really knows how much switch is ahead of us, but we just keep travelling on the hope to reach our destination, reach the end line. The cheering crowds on the stands are the friends and relations that we make. Take a Pause! notice your path, observe your crowd. If you are lucky enough someone from the stands might be at the end line waiting for you. So as the people say, Life is just a running race! As I write this, I’m still in my train hoping to reach the destination. With all my cheering crowds in the stands and the special ones at the end line, I continue to run the race called <strong>Life</strong> in which this piece of writing is a little break.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b4923b7150b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>