<?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 koalatime on Medium]]></title>
        <description><![CDATA[Stories by koalatime on Medium]]></description>
        <link>https://medium.com/@koalatime?source=rss-afab2a88db49------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ujyo5-7AlwJHRf2wKQd2Ew.png</url>
            <title>Stories by koalatime on Medium</title>
            <link>https://medium.com/@koalatime?source=rss-afab2a88db49------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:58:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@koalatime/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[Learn Unit Testing in Go from Scratch]]></title>
            <link>https://medium.com/@koalatime/learn-unit-testing-in-go-from-scratch-12d0ae693fbf?source=rss-afab2a88db49------2</link>
            <guid isPermaLink="false">https://medium.com/p/12d0ae693fbf</guid>
            <category><![CDATA[table-driven-testing]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[koalatime]]></dc:creator>
            <pubDate>Sun, 16 Aug 2026 22:31:15 GMT</pubDate>
            <atom:updated>2026-08-16T22:31:15.543Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*DMieZakBET090eJ2DT_9Dg.png" /></figure><p>Code and tests go hand in hand. Unit tests help us verify that our code has a deterministic output and that previously supported behaviour continues to work.</p><p>In this article, we’ll use a simple greet() function in main.go to explore how unit testing works in Go. We’ll start by creating a Go module and adding our function to main.go.</p><pre>go init example.com/gotest-example<br>touch main.go</pre><pre>package main<br><br>import (<br> &quot;flag&quot;<br> &quot;fmt&quot;<br>)<br><br>// usage: go run main.go -lang=en<br>func main() {<br> var lang string<br> flag.StringVar(&amp;lang, &quot;lang&quot;, &quot;hi&quot;, &quot;The required language, eg: en, fr&quot;)<br> flag.Parse()<br><br> greeting := greet(language(lang))<br> fmt.Println(greeting)<br>}<br><br>//language represents the ISO 639 language code <br>type language string<br><br>//phrasebook holds greeting for each supported language<br>var phrasebook = map[language]string {<br> &quot;en&quot;: &quot;Hello world&quot;, //English<br>  &quot;fr&quot;: &quot;Bonjour le monde&quot;, // French<br>  &quot;de&quot;: &quot;Hallo Welt&quot;, // German<br>  &quot;hi&quot;: &quot;नमस्ते दुनिया&quot;, // Hindi<br>  &quot;ja&quot;: &quot;こんにちは世界&quot;, // Japanese<br>  &quot;zh&quot;: &quot;你好，世界&quot;, // Chinese<br>}<br><br>// greet returns a greeting to the world<br>func greet(l language) string {<br> greeting, ok := phrasebook[l]<br> if !ok {<br>  return fmt.Sprintf(&quot;unsupported language: %q&quot;, l)<br> }<br> return greeting<br>}</pre><p><strong>Add a test file</strong></p><p>Now, we’ll create a test file to add unit tests for our greet() function. Following Go’s naming convention, we’ll call it main_test.go.</p><pre>touch main_test.go</pre><p><strong>A simple unit test</strong></p><p>We’ll start by writing a couple of simple tests. TestGreet_English() tests the English greeting, while TestGreet_Hindi() tests the Hindi greeting.</p><pre>func TestGreet_English(t *testing.T){<br> lang := language(&quot;en&quot;)<br> want := &quot;Hello world&quot;<br><br> got := greet(lang)<br><br> if got != want {<br>  t.Errorf(&quot;expected: %q, got: %q&quot;, want, got)<br> }<br>}<br><br>func TestGreet_Hindi(t *testing.T){<br> lang := language(&quot;hi&quot;)<br> want := &quot;नमस्ते दुनिया&quot;<br><br> got := greet(lang)<br><br> if got != want {<br>  t.Errorf(&quot;expected: %q, got: %q&quot;, want, got)<br> }<br>}</pre><p>To run these tests:</p><pre>go test</pre><p>While this approach is worth remembering for its simplicity, it’s easy to notice the overlap between the two tests. There’s no need to duplicate the same code for each test.</p><p><strong>Table-driven tests</strong></p><p>We can make use of table-driven tests to enhance the reusability and clarity of our test file.</p><pre>func TestGreet(t *testing.T) {<br> type testCase struct {<br>  lang language<br>  want string<br> }<br><br> var tests = map[string] testCase {<br>  &quot;English&quot;: {<br>   lang : &quot;en&quot;,<br>   want : &quot;Hello world&quot;,<br>  },<br>  &quot;French&quot;: {<br>   lang : &quot;fr&quot;,<br>   want : &quot;Bonjour le monde&quot;,<br>  },<br>  &quot;Hindi&quot;: {<br>   lang : &quot;hi&quot;,<br>   want : &quot;नमस्ते दुनिया&quot;,<br>  },<br>  &quot;Empty&quot;: {<br>   lang: &quot;&quot;,<br>   want: `unsupported language: &quot;&quot;`,<br>  },<br> }<br><br> // range over all the scenarios<br> for name, tc := range tests {<br>  t.Run(name, func(t *testing.T) {<br>   got := greet(tc.lang)<br><br>   if got != tc.want {<br>    t.Errorf(&quot;expected: %q, got: %q&quot;, tc.want, got)<br>   }<br>  })<br> }<br>}</pre><p>In this approach, we introduced a struct to store the input and expected output for each test case. We then created a map representing a collection of test cases and iterated over them, calling greet() for each case and comparing the returned value with the expected output.</p><p><strong>Test coverage</strong></p><blockquote>Testing can prove the presence of bugs, but not the absence! — Edsger Dijkstra</blockquote><p>A single test won’t prove that our code is bug-free. Better test coverage means fewer bugs. Test coverage is a metric to know what % of our code is unit tested. (Alert! The goal is not to achieve 100% code coverage, but to test essential behaviour of our code through unit testing.)</p><p>Go provides built-in support for measuring test coverage. We can run:</p><pre>go test -cover</pre><p>This runs our tests and reports the percentage of statements covered by them.</p><p>If we want to save the coverage information for further analysis, we can generate a coverage profile:</p><pre>go test -coverprofile=coverage.out</pre><p>The generated coverage.out file can then be used with Go&#39;s coverage tools to inspect which parts of the code are covered.</p><p><strong>Last words</strong></p><p>In this article, we learned how to write tests in Go. It’s straightforward, thanks to Go’s simple yet powerful built-in testing tools. We started with adding a test file and some basic tests. Then reduced duplication by using table-driven tests and explored test coverage as a way to identify untested parts of our code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12d0ae693fbf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How a Software Engineer Deals with Death]]></title>
            <link>https://medium.com/@koalatime/how-a-software-engineer-deals-with-death-8efec9679154?source=rss-afab2a88db49------2</link>
            <guid isPermaLink="false">https://medium.com/p/8efec9679154</guid>
            <category><![CDATA[death]]></category>
            <category><![CDATA[immigrant-life]]></category>
            <category><![CDATA[corporate-life]]></category>
            <dc:creator><![CDATA[koalatime]]></dc:creator>
            <pubDate>Sun, 19 Jul 2026 02:01:59 GMT</pubDate>
            <atom:updated>2026-07-19T02:01:59.136Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Poorly.</strong></p><p>A few months into my job at a tech company, my life revolved around learning. There was always something new to read, review, or solve. I wanted to prove that I belonged there (to myself more than anyone else). But outside of work, life felt complete.</p><p>An Indian immigrant who had managed to build a life in the US. My mom was visiting me, and my dad and brother were supposed to visit soon. We had plans. Ordinary ones. The kind you don’t realise you will miss until they are taken away.</p><p>I remember that Sunday vividly. My mom and I were sitting by the apartment pool. I had brought my laptop because I had just tracked down a bug and figured I’d research a fix. Mom was listening to some music.</p><p>Then her phone rang.</p><p>They said my father wasn’t doing well, that she needed to come home immediately, and that I should come with her. My brain was flooded with questions. What exactly happened? Was he in the hospital? Did he have a heart attack? Was his blood pressure unstable? What’s his medical history? No idea.</p><p>The answers didn’t come back straightforwardly. We were told that my father was being taken to the hospital. For the next two hours, I was living in the wrong version of reality. We still had time. This could be a false alarm- he is still young. Two hours later, I learned the truth that he had passed away in his sleep.</p><p>Suddenly, every memory became suspect. Maybe it happened while my mom and I were sitting by the pool. Or, while we were laughing over brunch. Did that matter? An incident had happened, a sev 1. The world had changed, and I was paged late.</p><p><strong>Next steps.</strong></p><p>Close the laptop. Work will have to wait. Surf Google Flights. Book the earliest flight to New Delhi. Don’t think about the cost. Slack your manager. Tell them there’s a family emergency, and that there’s a bug the team will eventually discover. If the H-1B petition hasn’t been filed yet, ask them to stop. If it has, you’ll deal with it later. Right now, there’s only one place you’re supposed to be.</p><p>Get your mom home. Twenty-five hours. Maybe more. Pack in silence. Put in the gifts you bought for your brother. Take out the ones you bought for your dad- can’t look at those right now. Keep moving.</p><p>Shock is surprisingly efficient. I couldn’t cry yet because I had a checklist- phone, wallet, keys, passports, immigration documents. Tell mom it’ll be okay, even though you have absolutely no idea if it’ll be. Maybe eat something, or not. But make sure that mom does. Board the flight. Fight with the airline staff when they cancel your connection. Board a new flight.</p><p>Cool.</p><p>Go through grief. Stay with your family for a month and then fly back. Sometimes immigration asks you to make impossible choices. My H-1B petition couldn’t move forward if I didn’t return to the US. Staying longer meant risking the career I’d spent years building. I didn’t want my grief to make rash decisions on my behalf.</p><p>Back in the US. Everything looks the same as I’d left it. The office is both impossible and comforting. I don’t think people noticed my absence from work for a month. For them, I was just OOO. My bug was still waiting for me. As it appears, it wasn’t that big a deal. The codebase and priorities had changed while I was away. In a way, it was all still the same, really. So deterministic.</p><p>Every evening, I come back to an empty apartment. To process that my father has gone, and the life that I have paused is expected to continue. It wasn’t my first death, nor my first emergency trip back to the other side of the world. I had done this before. I <em>should</em> be strong enough to deal with this. But nothing about this is easy. I keep thinking about my mom, who lost her partner. About my younger brother, who is expected to step up.</p><p>But even the biggest event of my life hasn’t left a trace on anyone else. The world keeps moving on silently. New responsibilities. New features. New meetings. Mid-year reviews.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M2nzUOCcBHTYWcqc.jpg" /></figure><p>I’ve realised that the pain lives alongside, and you’re supposed to keep going. So every morning, I open my laptop and write more code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8efec9679154" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Preparing for the MongoDB Associate Developer Exam in 2025]]></title>
            <link>https://medium.com/@koalatime/preparing-for-the-mongodb-associate-developer-exam-in-2025-a21623440236?source=rss-afab2a88db49------2</link>
            <guid isPermaLink="false">https://medium.com/p/a21623440236</guid>
            <category><![CDATA[certification-exam]]></category>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[associate-developer]]></category>
            <category><![CDATA[certification-preparation]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[koalatime]]></dc:creator>
            <pubDate>Sat, 01 Feb 2025 08:02:45 GMT</pubDate>
            <atom:updated>2025-03-07T04:34:52.164Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjyUmOfu4XDsev1vzayHUw.png" /></figure><p><strong>Preface</strong></p><p>It’s January, and I’m surprisingly motivated — a rare feeling for me. My company partners with MongoDB, and they’re offering us free certifications, a perk that usually costs $150. MongoDB University offers a discount (50% for professionals, 100% for students) that can be attained after completing their <a href="https://learn.mongodb.com/catalog?query=developer%20associate">Developer Associate Learning Path on MongoDB University</a>. I was eligible to get the 50%, but free is even better! I’m excited because, well, who doesn’t love free certifications?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L76pW3BSJr4pKeQSSXNKpQ.jpeg" /><figcaption>MongoDB exam prep with my MongoDB pen</figcaption></figure><p><strong>Exam Format</strong></p><p>The certification exam consists of 53 multiple-choice questions, giving you just over a minute per question within the 75-minute time limit. It’s an online, proctored exam, and the proctoring service may take up to 72 hours to review your session before you receive your digital badge from <strong>Credly</strong>.</p><p>Exam passing score is determined by unique exam-specific statistical data. Since no reference materials are permitted, make sure you’re thoroughly familiar with all the topics.</p><p>Occasionally, the exam might have more than 53 questions. MongoDB sometimes includes a few unscored, statistical questions that won’t affect your final grade.</p><p><strong>Exam Objectives</strong></p><p>The exam topics along with weights are as follows:</p><pre>+----------------------------------+---------+--------------+<br>| Section 1 | MongoDB Overview &amp; the document model   | 8%  |<br>| Section 2 | CRUD                                    | 51% |<br>| Section 3 | Indexes                                 | 17% |<br>| Section 4 | Data Modeling                           | 4%  |<br>| Section 5 | Tools and Tooling                       | 2%  |<br>| Section 6 | Drivers(selected programming language)  | 18% |<br>+----------------------------------+---------+--------------+</pre><p><strong>Exam Preparation</strong></p><p>A. Developer Associate Learning Path on MongoDB University</p><p>I began my preparation with the <a href="https://learn.mongodb.com/learning-paths/using-mongodb-with-c-sharp">C# Developer Associate Learning Path</a>. You can choose the programming language of your choice. This self-paced course, packed with quizzes and hands-on lab exercises, is an excellent foundation for the exam.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OR1zVwZ2KHgjiq-UleLO-A.png" /></figure><p>I finished the learning path in ~3 days. If you prefer not to spend a weekend on it like I did, you could easily complete it over a week or two by dedicating some study time.</p><p>To test my readiness, I took this free <a href="https://learn.mongodb.com/courses/associate-developer-c-sharp-practice-questions">mock exam</a> available on the platform. This revealed that I needed a more thorough review of the documentation. While the learning path covers the fundamentals, it lacks the practice questions needed for comprehensive exam preparation.</p><p>B. MongoDB Official Docs</p><p>TLDR is usually my mantra but in this case, I knew I had to dive into the documentation. It was recommended by fellow exam takers. <a href="https://www.mongodb.com/docs/manual/">Here</a>’s your starting point. To stay focused, I kept the <a href="https://learn.mongodb.com/learn/course/mongodb-associate-developer-exam-study-guide/main/associate-dba-exam-study-guide?client=customer">exam study guide</a> open while I worked. I tackled each objective section by section, reviewing the corresponding documentation. Any hands-on exercises or code examples I encountered, I saved to <a href="https://github.com/kgujral2612/mongodb-dev-associate-csharp-study/tree/main">this repo</a>.</p><p><strong>Additional Practice</strong></p><p>I enrolled into <a href="https://www.udemy.com/course/mongodb-associate-developer-exam-preparation/">this course on Udemy</a> by <a href="https://www.udemy.com/course/mongodb-associate-developer-exam-preparation/?couponCode=KEEPLEARNING#instructor-1">Bartosz Pretnik</a>. The course offers 6 practice exams, each with 70 questions, which should provide ample preparation for the real thing. I worked through the first two, carefully reviewing all the questions I missed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UiJg0x3vbtmpMRvtR5j__A.png" /><figcaption>Mock Exam#1 Results</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zJhwHYzZ3G-XPp47CvycOw.png" /><figcaption>Mock Exam#2 Results</figcaption></figure><p>My practice sessions helped me pinpoint my weaker areas. I identified the below problem areas:</p><ul><li><strong>Questions with multiple correct answers:</strong> I frequently missed one of the correct options, resulting in a zero score for the entire question. I needed to be more meticulous with these.</li><li><strong>Syntax-based questions:</strong> I often struggled with the syntax, like whether sum() could be used with find(), or if the correct setting was maxPoolSize or maxConnections.<br>Some questions presented nearly identical options, except for a single syntax error (e.g., db.col.aggregate([]) vs. db.col.aggregate({}) vs. db.aggregate([])). I had to pay more attention.</li><li><strong>Similar options:</strong> Query questions were particularly tricky, with options differing only slightly, such as {&quot;age&quot;: 1} vs. {&quot;age&quot;: &quot;1&quot;}. I would open my eyes wide to catch the tiny details.</li><li><strong>Partially correct options:</strong> I learned to read each sentence carefully, as some options were only partially correct.</li><li><strong>Questions I had no idea about:</strong> Given the vast documentation, I encountered questions on topics I’d either forgotten or hadn’t covered. In these cases, I made educated guesses to the best of my ability.</li></ul><p><strong>The Exam</strong></p><p>It’s a good idea to get settled with your computer about 15 minutes before the exam starts, as there are system checks to complete. Remember, the environment is remotely proctored.</p><p>My mock exam scores were 70% and 71%. I am a nervous test-taker, and I was a bit nervous heading into the real thing. I just needed to pass.</p><p>I moved quickly through the exam, answering every question, and finished with 20 minutes to spare for review. I was stuck on a few questions which only added to my nervousness.</p><p>Alright. It’s time. Free certification or a failed attempt?</p><p><em>Drumroll</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*eGBczzBSktn_ELxJBnxl4Q.png" /><figcaption>A snippet of the pass certificate</figcaption></figure><p>Phew.</p><p><em>PS: You can find the exam details on the mongo university dashboard. </em>🎯<em><br>Another PS: You can find your name in the </em><a href="https://www.credly.com/organizations/mongodb/directory"><em>directory of certificate earners</em></a><em>. </em>👩‍🎓</p><p><strong>References</strong></p><ul><li><a href="https://learn.mongodb.com/learn/course/mongodb-associate-developer-exam-study-guide/main/associate-dba-exam-study-guide?client=customer">Associate Developer Exam Study Guide</a></li><li><a href="https://www.mongodb.com/docs/manual/">MongoDB Documentation</a></li><li><a href="https://www.mongodb.com/docs/atlas/getting-started/">MongoDB Atlas Documentation</a></li><li><a href="https://www.mongodb.com/docs/drivers/csharp/current/">MongoDB C# Driver</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a21623440236" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elevate Your Competency Level as a Software Engineer: From Beginner to Guru]]></title>
            <link>https://medium.com/@koalatime/elevate-your-competency-level-as-a-software-engineer-from-beginner-to-guru-a9646fda9a78?source=rss-afab2a88db49------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9646fda9a78</guid>
            <category><![CDATA[job-preparation]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-engineer-career]]></category>
            <category><![CDATA[techgrowth]]></category>
            <category><![CDATA[software-engineer]]></category>
            <dc:creator><![CDATA[koalatime]]></dc:creator>
            <pubDate>Tue, 10 Dec 2024 01:23:06 GMT</pubDate>
            <atom:updated>2024-12-10T17:45:51.919Z</atom:updated>
            <content:encoded><![CDATA[<p>Software Engineering roadmaps always feel like a big iceberg — as you learn more, you learn that there are too many things to learn. You might guess there is a lot to uncover both horizontally and vertically. Your job title says “Software Engineer” but what’s your level of competency? How do you compare to other software engineers in the industry? What does it take to jump to the next level?</p><p>Only gaining more years of experience won’t do it. True professional growth transcends tenure. Targeted skill development and a clear understanding of career progression are crucial for advancement. A well-defined competency framework provides a structured roadmap, enabling individuals to identify skill gaps, engage in meaningful discussions with senior colleagues, and cultivate a growth-oriented mindset.</p><p>I received this competency chart from a mentor, and it has given me a lot of direction. I regularly review this framework to track my progress and visualize my career trajectory. I’ve embedded a <a href="https://docs.google.com/document/d/18rchMF9TyB4Ry7pDzeyoc0GTSDhmEIFjphWS1TUBjJw/edit?usp=sharing">google doc</a> that you can make a copy of and keep it some place you visit often.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fdocs.google.com%2Fdocument%2Fd%2F18rchMF9TyB4Ry7pDzeyoc0GTSDhmEIFjphWS1TUBjJw%2Fpreview%3Fembedded%3Dtrue&amp;display_name=Google+Docs&amp;url=https%3A%2F%2Fdocs.google.com%2Fdocument%2Fd%2F18rchMF9TyB4Ry7pDzeyoc0GTSDhmEIFjphWS1TUBjJw%2Fedit%3Fusp%3Dsharing&amp;image=https%3A%2F%2Flh7-us.googleusercontent.com%2Fdocs%2FAHkbwyJ_mWzm2y6-viObqmD-bZOtKwVZeAfSdbSFNaNi-p8MVFgWqA51KMGFCdkiuioq_bW_6TXbXid4Tgll_aWC3KXQWcnzGk8lbW7o8niQ5YQQF6yJO4tt%3Dw1200-h630-p&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=google" width="700" height="530" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fcfadfb10b329b88b8ae7b68c209e37/href">https://medium.com/media/3fcfadfb10b329b88b8ae7b68c209e37/href</a></iframe><p><strong>How to use this chart?</strong></p><ul><li><strong>Understand the Chart:</strong> This chart is language or technology agnostic and rates engineers with respect to these areas of contribution: <em>planning/progress, design, coding, quality, innovation, </em>and <em>devOps</em>.</li><li><strong>Understand Proficiency Levels</strong>: The chart uses proficiency levels ranging from developing (newbie), competent, mastery, <a href="https://www.google.com/search?q=T-shaped+individual">T-shaped</a>, to guru.</li><li><strong>Identify Skill Gaps: </strong>Analyze the chart to determine the skills and knowledge you have at the moment and what’s required for the next level of your career. Focus on the areas where you need to improve.</li><li><strong>Create a Development Plan:</strong> Set Specific, Measurable, Achievable, Relevant, and Time-bound (SMART) Goals. Example: “Learn to implement and deploy a basic microservices architecture within the next 3 months.” Consider taking online courses, reading books, working on projects, attending workshops or conferences, et cetera.</li><li><strong>Track Your Progress: </strong>Regularly review your plan and keep coming back to this chart to tick the items you have achieved. You can also use the chart to discuss your career goals and development plan with your manager during performance reviews.</li></ul><p>Support by likes or claps, and please sharing your thoughts! :-))</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9646fda9a78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Your Daily D.O.S.E.]]></title>
            <link>https://medium.com/@koalatime/getting-your-daily-d-o-s-e-cacd5962a1a3?source=rss-afab2a88db49------2</link>
            <guid isPermaLink="false">https://medium.com/p/cacd5962a1a3</guid>
            <category><![CDATA[mental-health]]></category>
            <category><![CDATA[corporate-culture]]></category>
            <category><![CDATA[well-being-at-work]]></category>
            <category><![CDATA[wellbeing]]></category>
            <dc:creator><![CDATA[koalatime]]></dc:creator>
            <pubDate>Thu, 26 Sep 2024 23:23:51 GMT</pubDate>
            <atom:updated>2024-09-26T23:23:51.689Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*U9cABPrKddpHyNfdM-yWmw.jpeg" /></figure><p>Feeling unmotivated at work? Enhancing your daily D.O.S.E. can significantly improve not only your mental well-being, but also your chances at innovation, productivity and work engagement.</p><p>D.O.S.E. are an acronym for brain’s happy chemicals:<br>D = Dopamine, O = Oxytocin, S = Serotonin, E = Endorphins</p><p><strong>Dopamine</strong></p><p><em>Your motivation and reward chemical</em><br>Completing a task, self care activities, eating food, celebrating small wins, receiving recognition, listening to music, massages, workouts</p><p><strong>Oxytocin</strong></p><p><em>Your trust and love chemical</em><br>Animals, babies, holding hands, hugging, meaningful conversations/connections, acts of service</p><p><strong>Serotonin</strong></p><p><em>Your mood stabilizing chemical</em><br>Sunshine, meditation, running, sleep, being out in nature, self-care</p><p><strong>Endorphins</strong></p><p><em>Your natural pain reliever</em><br>Laughing, exercise, chocolate, intimate connections</p><p>Here are some effective strategies to get that daily D.O.S.E.</p><ol><li><strong>Organize your day</strong>: It might sound cliché and feel like a chore, but planning your day and tasks can significantly improve your mood. Personally, I prefer waking up at least one to two hours before starting work. This gives me ample time to stretch, meditate for a few minutes, and plan my meals for the day (I’m a foodie). Once my workday begins, I open my calendar and block out periods labeled “Deep Work” for specific tasks I aim to accomplish during those times. This approach provides me with a clear roadmap for the day and serves as a useful indicator of the work I completed the previous day. Highly recommended!</li><li><strong>Incorporate regular breaks</strong>: After every “Deep Work” session, I make it a point to stretch, take a short walk outside, chat with colleagues, or grab a snack. These activities are a great distraction — these help me clear my mind and elevate my mood.</li><li><strong>Staying Active:</strong> While everyone suggests hitting the gym, it’s not always. Your motivation to visit the gym will significantly increase if it’s a group activity. Or, you could take up a challenge, such as a <a href="https://www.today.com/health/diet-fitness/30-day-walking-core-workout-plan-rcna168531">30-day walking challenge</a>, or the <a href="https://sunnyhealthfitness.com/blogs/health-wellness/75-soft-challenge-rules-checklist-get-better-results?srsltid=AfmBOoo3fiT9CdLcDWDVuiqqneUfQWJKiVb8ole9-3nAOdm9-zxbM_ti">75-soft challenge</a> to make things interesting. Completing a challenge always feels incredibly rewarding!</li><li><strong>Balanced Diet:</strong> Another cliche. But I’ve noticed a significant difference in my overall mood and productivity when I eat poorly and skip physical activity. It’s all interconnected. When you don’t eat healthy, you often lack the energy or motivation to exercise. While it can get difficult sometimes, your gut will thank you if you cut down processed foods and opt for whole foods. I like to follow the 80–20 rule where 80% of my meals are healthy.</li><li><strong>Engage in Creative Activities:</strong> If you’re thinking about joining that hackathon, go for it. Participate in brainstorming sessions, problem-solving tasks, or team-building activities to unleash and showcase your creativity.</li><li><strong>Connect with Colleagues:</strong> Humans thrive on social interactions. Building positive relationships not only creates a more enjoyable work environment but also helps keep everyone motivated. Take the time to recognize and engage with your colleagues; this can foster better teamwork and open up opportunities for collaboration.</li></ol><p>We all want to feel like we’re progressing and not vegetating. Getting your daily D.O.S.E. can lead to increased motivation, enhanced focus, and overall job satisfaction. Try to incorporate the above strategies in your life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*RH3PmOMpQp39dQu-SFGbsg.jpeg" /></figure><p><em>Support by hitting a like and share your thoughts in the comment section :-)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cacd5962a1a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design: Rate Limiter]]></title>
            <link>https://medium.com/@koalatime/system-design-rate-limiter-3cb39c6aab84?source=rss-afab2a88db49------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cb39c6aab84</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[koalatime]]></dc:creator>
            <pubDate>Sun, 15 Sep 2024 03:50:50 GMT</pubDate>
            <atom:updated>2025-06-20T04:34:01.905Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*qR0v_RoWFKf0dcs3zB_VtQ.png" /><figcaption>a depiction of rate limiter in modern systems</figcaption></figure><p><strong>What is a Rate Limiter?</strong></p><blockquote>Rate limiter is a system for limiting network traffic. It puts a cap on how often someone can repeat an action within a certain timeframe.</blockquote><p>In other words, a rate-limited app is your friend who shouts, “Whoa there, buddy!” when you’re pounding the snacks at a party. Or your brain shutting off after studying for a few hours. Or… okay, you get the point.</p><p>In essence, when a user exceeds the defined request rate, a rate-limited system enforces a pause/slowdown, effectively signaling the user to reduce the frequency of their requests and adhere to the established rate limits.</p><p>Systems may put a limit on <a href="https://support.google.com/accounts/thread/52598991/my-gmail-can-t-been-recovered-due-to-too-many-failed-attempts-i-have-tried-after-24-hours-same?hl=en">the number of login attempts</a> or <a href="https://techhq.com/2023/07/why-has-twitter-introduced-rate-limits/">the number of tweets you can read each day</a>. Rate limiting serves as a mechanism to mitigate malicious bot activities and to alleviate server load at the same time. By applying restrictions and quotas to shared resources, rate limiting ensures fair access and availability for all users.</p><p><strong>Problem Statement</strong>: Limit the number of requests issued by a user or an IP address in a window of time. <br>Requirements:</p><ul><li>should limit the use of the application</li><li>should not slow down web requests too much</li><li>consider rate limiting in a distributed system</li></ul><p><strong>High-Level Architecture</strong></p><p>The server has access to all requests making it a good place to put the rate-limiting code. Placing the rate limiter on the client side has the potential risk of being modified.</p><ul><li>Introduce a rate limiter middleware before the server</li><li>When a client sends a request, it first reaches the rate limiter middleware, where the rate limiting logic is executed. The middleware determines whether the request should be forwarded to the server based on the rate limiting rules.</li></ul><p>The rate limiting algorithm will know the threshold limit and will essentially keep track of the number of requests that have been sent over a period. The number can be represented using a stateless counter (increase it each time by 1 when you receive a request) which needs to be stored somewhere. A database is the first choice, but using that may result in performance degradation due to slower disk access. And that will further increase system latency. We can do better.</p><ul><li>Leverage an in-memory cache, such as Redis, to store and manage the request count.</li><li>The rate limiter retrieves the request count from Redis to assess if the predefined limit has been reached. If the limit has been exceeded, the request is denied; otherwise, the counter is incremented by 1.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m3q_t_pUvd-LcsZNgHdF8g.png" /><figcaption>high-level architecture of a rate limiter</figcaption></figure><p><strong>Detailed Design</strong></p><p><em>Q. Which rate limiting algorithm should be used?</em></p><p>In general, a rate limiting algorithm will maintain the count of the incoming requests. You may try to write your own algorithm. There are, however, a few known ones summarised quite aptly on <a href="https://blog.algomaster.io/p/rate-limiting-algorithms-explained-with-code">this link</a>.</p><ul><li>Token Bucket</li><li>Leaky Bucket</li><li>Fixed Window Counter</li><li>Sliding Window Log</li><li>Sliding Window Counter</li></ul><p><em>Q. What is the process for defining and applying rate-limiting rules?</em></p><p>Rate limit rules can be stored on disk for persistence. Storing rate limits instead of hear-coding them allows us to change rules during special events and varied traffic hours. The rate limiter reads rules from the disk and then caches the rules temporarily. Following the Single Responsibility Principle, we can assign a set of workers to handle getting the rules from the cache and let our rate limiter read directly from the cache.</p><p><em>Q. How should rate-limited requests be managed, and what is the client’s experience during such events?</em></p><p>Although decisions about accepting or rejecting requests are made on the server, you must convey to the client more information on the rate limits.</p><p><strong>Return a 429 status code and add headers. </strong><br>When a rate limit is reached, your HTTP services should return</p><pre>429 Too Many Requests</pre><p>along with some useful headers such as those used by GitHub:</p><ul><li>x-ratelimit-limitThe maximum number of requests that you can make per hour</li><li>x-ratelimit-remainingThe number of requests remaining in the current rate limit window</li><li>x-ratelimit-usedThe number of requests you have made in the current rate limit window</li><li>x-ratelimit-resetThe time at which the current rate limit window resets, in UTC epoch seconds</li></ul><p>Think of a high-traffic scenario such as annual deals on an e-commerce website. The HTTP status code along with the headers gives enough indication to the client about how many requests to send (avoid being rate limited) and <em>when</em> to retry (if they were rate limited). A common way to deal with retries is by using an <a href="https://en.wikipedia.org/wiki/Exponential_backoff"><em>exponential backoff </em></a><em>mechanism</em>. If requests are still unsuccessful, the delays between requests should increase over time until the request is successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GeZof6lXNXM0d5kTCHr56A.png" /></figure><p>Depending upon your use case, you might wanna consider whether you’d want to have a hard or soft rate limiting implementation.</p><p>Hard Rate Limiting<strong>: </strong>reject the request</p><p>Soft Rate Limiting: save the request on a queue for later processing</p><p><strong>Rate limiter in a distributed environment</strong></p><p>In a distributed environment with multiple instances of a rate limiter, each server will have its own rate limiter instance. This setup introduces synchronization challenges, particularly if each instance maintains its own cache. To address this, we aim to use a single Redis cache to store the counter state, allowing all rate limiters to share a common, stateless cache. <em>For more on stateful versus stateless architecture see </em><a href="https://medium.com/@connect2kaushambi/system-design-scale-from-zero-to-millions-of-users-part-ii-9666dd4902b0"><em>here</em></a><em>.</em></p><p>Race Condition: two concurrent requests can read the same value of the counter and one of the updates will be lost. For example, if the counter value is ‘9’, two concurrent requests might both read this value and write ‘10’, resulting in an incorrect counter value of ‘10’ instead of ‘11’.</p><p>This race condition is a common problem in multithreaded environments, typically addressed with locks. However, locks can introduce performance overhead.</p><p>As a faster alternative, Redis provides Lua scripting, which reduces overhead compared to traditional locking mechanisms and improves rate limiter performance.</p><p><strong>References</strong></p><ul><li><a href="https://www.cloudflare.com/learning/bots/what-is-rate-limiting/">What is rate limiting?</a></li><li><a href="https://www.figma.com/blog/an-alternative-approach-to-rate-limiting/">Figma’s approach to rate limiting</a></li><li><a href="https://eng.lyft.com/announcing-ratelimit-c2e8f3182555">Lyft’s Ratelimit</a>; <a href="https://github.com/envoyproxy/ratelimit">Code</a></li><li><a href="https://developers.google.com/docs/api/limits">Google Docs Usage Limits</a></li><li><a href="https://telnyx.com/resources/rate-limit-headers">Understanding Rate Limit Headers</a></li><li><a href="https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#checking-the-status-of-your-rate-limit">GitHub: Checking the status of your rate limit</a></li><li><a href="https://redis.io/docs/latest/develop/interact/programmability/eval-intro/">Scripting with Lua</a></li></ul><p><em>I had fun learning about rate limiters; I hope you did too!</em></p><p><em>If you found this article useful, please give it a clap and share your thoughts in the comments!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cb39c6aab84" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design: Back of the Envelope Estimation]]></title>
            <link>https://medium.com/@koalatime/system-design-back-of-the-envelope-estimation-bc49dfc3f723?source=rss-afab2a88db49------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc49dfc3f723</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[koalatime]]></dc:creator>
            <pubDate>Thu, 12 Sep 2024 05:38:05 GMT</pubDate>
            <atom:updated>2024-09-12T05:38:05.714Z</atom:updated>
            <content:encoded><![CDATA[<p>Back-of-the-envelope estimations provide an initial assessment of which system design may meet the specified requirements. This approach needs an understanding of the costs associated with various processes and involves approximating calculations. These are particularly useful in system design interviews.</p><p><strong>Round off and approximate</strong></p><p>You are designing a large-scale social media application. You (or your interviewer) could ask, what will be the number of writes on this social media app? <br>In reality, the numbers from a real social media app could be 8.79% writes and 11343476 total active users, but we are here only to estimate, so assume 10% writes with 10 million active users per day. That is 1 million writes per day. It is way easier to calculate the rounded-off numbers.</p><p>How about the number of write requests per second (RPS: requests per second)?</p><pre>1 day : 1,000,000<br>1 sec:  1,000,000/(24 * 60 * 60) <br>     : 1,000,000/86,400 ==&gt; do you REALLY want to calculate this in an interview?<br>Or would you rather do this: <br>1 sec: 1,000,000/100,000 = 10, i.e 10 requests per second</pre><p><strong>Numbers every software engineer must know (or at least have an idea about)</strong></p><ol><li>Writes are expensive as they require disk seek <br>Assume 10 ms per disk seek<br>i.e 100 disk seeks per sec</li><li>Reads are cheaper than writes — once data is read from the disk, it can be easily cached<br>Assume 250 μs for 1 MB of data from memory<br>i.e 4GB per sec</li><li>Power of Two</li></ol><pre>+-------+---------------+-------------------+----------------+<br>| Power | Actual Value  | Approximate Value |   Measurement  |<br>+-------+---------------+-------------------+----------------+<br>| 10    | 1024          | 1000              | 1 KB (Kilobyte)|<br>| 20    | 1048576       | 1000000           | 1 MB (Megabyte)|<br>| 30    | 1073741824    | 1000000000        | 1 GB (Gigabyte)|<br>| 40    | 1.0995116e+12 | 1000000000000     | 1 TB (Terabyte)|<br>| 50    | 1.1258999e+15 | 1000000000000000  | 1 PB (Petabyte)|<br>+-------+---------------+-------------------+----------------+</pre><p>4. Availability Numbers</p><p>What would mean for your most-used app to be 99% available? It means it will NOT be available 1% of 365 days, i.e., 3.65 days in a year. Oh no!</p><pre>+----------------+-------------------+--------------------+<br>| Availability % | Downtime per year | Donwtime per month |<br>+----------------+-------------------+--------------------+<br>| 99             | 3.65 days         | 7.31 hours         |<br>| 99.9           | 8.77 hours        | 43.83 minutes      |<br>| 99.99          | 52.60 minutes     | 4.38 minutes       |<br>| 99.999         | 5.26 minutes      | 26.30 seconds      |<br>| 99.9999        | 31.56 seconds     | 2.63 seconds       |<br>+----------------+-------------------+--------------------+</pre><p>5. Latency Numbers</p><p>These numbers are from a presentation given by <a href="https://research.google/people/jeff/?&amp;type=google">Jeff Dean</a> at a Google All Hands. You don’t need to memorize these but get an idea.</p><pre>Latency Comparison Numbers (~2012)<br>----------------------------------<br>L1 cache reference                           0.5 ns<br>Branch mispredict                            5   ns<br>L2 cache reference                           7   ns                      14x L1 cache<br>Mutex lock/unlock                           25   ns<br>Main memory reference                      100   ns                      20x L2 cache, 200x L1 cache<br>Compress 1K bytes with Zippy             3,000   ns        3 us<br>Send 1K bytes over 1 Gbps network       10,000   ns       10 us<br>Read 4K randomly from SSD*             150,000   ns      150 us          ~1GB/sec SSD<br>Read 1 MB sequentially from memory     250,000   ns      250 us<br>Round trip within same datacenter      500,000   ns      500 us<br>Read 1 MB sequentially from SSD*     1,000,000   ns    1,000 us    1 ms  ~1GB/sec SSD, 4X memory<br>Disk seek                           10,000,000   ns   10,000 us   10 ms  20x datacenter roundtrip<br>Read 1 MB sequentially from disk    20,000,000   ns   20,000 us   20 ms  80x memory, 20X SSD<br>Send packet CA-&gt;Netherlands-&gt;CA    150,000,000   ns  150,000 us  150 ms<br><br>Notes<br>-----<br>1 ns = 10^-9 seconds<br>1 us = 10^-6 seconds = 1,000 ns<br>1 ms = 10^-3 seconds = 1,000 us = 1,000,000 ns</pre><p><strong>References</strong></p><ul><li><a href="https://highscalability.com/numbers-everyone-should-know/">Numbers everyone should know</a></li><li><a href="https://highscalability.com/google-pro-tip-use-back-of-the-envelope-calculations-to-choo/">Using back-of-the-envelope estimation</a></li><li><a href="https://gist.github.com/jboner/2841832">Latency numbers every programmer should know</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc49dfc3f723" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design: Scale From Zero To Millions of Users (Part II)]]></title>
            <link>https://medium.com/@koalatime/system-design-scale-from-zero-to-millions-of-users-part-ii-9666dd4902b0?source=rss-afab2a88db49------2</link>
            <guid isPermaLink="false">https://medium.com/p/9666dd4902b0</guid>
            <category><![CDATA[system-architecture]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[koalatime]]></dc:creator>
            <pubDate>Sun, 08 Sep 2024 19:29:51 GMT</pubDate>
            <atom:updated>2024-09-08T19:32:13.623Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is written in continuation of <a href="https://medium.com/@connect2kaushambi/system-design-scale-from-zero-to-millions-of-users-part-i-9f544407d44e">Part I</a>.</p><p><strong>Stateful vs Stateless Architecture</strong></p><blockquote>A stateful architecture remembers client data (state) from one request to the next.</blockquote><p>By default, a classic load balancer routes a new request to the server with the smallest load, but we can configure it to bind a user to a specific server instance. This is referred to as <em>sticky sessions</em> or <em>session affinity</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b9Tfc_w8GqjhkkkQuBSsjg.png" /></figure><p>In a stateful architecture, all requests for user A must be routed to server 1 since user A’s session data is stored on server 1. Thus adding, and removing servers as well as handling server failures is challenging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pLknlCZBW5CQ0Zn6E6Ff1A.png" /></figure><p>On the other hand, HTTP requests are sent to any server in a stateless architecture. The servers fetch state data from a shared data store. A stateless system is simpler and more robust.</p><p><em>If the state is relatively small, it can be stored in cookies. The state is maintained in the web browser rather than on the web server.</em></p><p>The updated system architecture now incorporates shared storage for managing state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xN8usnNzT8unIaXaVmlglg.png" /></figure><p><strong>Data Centers</strong></p><p>Servers in the same location are grouped by data centers. A website might have two data centers, one in India and the other in the US. With GeoDNS it’s possible to create a DNS record for which clients in different locations get the IP address of the data center closest to them, i.e clients from India are routed to the Indian data center where as those from the US are routed to the American one. In the event of any significant data center outage, all traffic is directed to the healthy data center.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zod2o1oH00Ho027Bpg3xCQ.png" /></figure><p><strong>Message Queue</strong></p><blockquote>A message queue is a form of asynchronous service-to-service communication.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nNRGQ3iK7g0WX6CkdFdQvQ.png" /></figure><p>The producer creates tasks that line up on the queue for the consumer to pick. You can decouple heavyweight processing into a separate application/service and use a message queue to trigger it.</p><p>Your application offers document processing features like converting formats, compressing files, and extracting text. These processing tasks can be time-consuming. By using a message queue, you can decouple the document processing jobs from the main application code (producer) and send them to specialized processing workers (consumers). This separation allows you to independently scale either the web servers or the document processing workers based on demand.</p><p><strong>Logging, metrics, and automation</strong></p><p>Logging, collecting different types of metrics, and building automation for CICD are good practices. While these may not be a necessity in small applications, they are most useful in large-scale applications.</p><ul><li>Quickly identify errors by reading logs</li><li>Collect metrics such as CPU usage, Memory usage, performance of a tier, revenue, user retention, etc</li><li>CICD helps improve developer productivity</li></ul><p><strong>Database Scaling: Vertical vs Horizontal (Sharding)</strong></p><p>Scaling? Again!!</p><p>Database servers can be scaled vertically the same way as web servers, i.e. by increasing CPU, RAM, etc, and this approach suffers the disadvantage of having hard limits and being a SPOF.</p><p>Horizontal scaling in databases, aka sharding, is the practice of adding more servers. Sharding separates large databases into smaller parts called shards where each shard contains its unique data. Naturally, the schema remains the same for all shards.</p><p>How is data distributed across shards? One strategy is our good old hash function: <em>x % y. </em>For example, partitioning the database based on user_id column and creating 5 shards will need: <em>user_id % 5</em>. If result = 1, data must be on shard 1.</p><p>This approach still has some problems:</p><ul><li>Resharding: Resharding is needed when a single shard can no longer hold more data and new shards must be added. This requires updating the sharding function and moving data around.</li><li>Celebrity Problem/Hotspot Key Problem: what if data for Taylor Swift, Justin Bieber, and Drake are all on the same shard? These will be frequently accessed, thereby increasing the load on that shard.</li><li>Joins: It is hard to perform joins across shards</li></ul><p><strong>Closing Remarks</strong></p><p>Let’s revisit the important points learned in this article:</p><ul><li>Support multiple data centers</li><li>Split heavy-weight processes using message queues</li><li>Monitor your system and use automation tools</li><li>Scale your data tier by sharding</li></ul><p>Thank you for making it through the article. You now have all the knowledge you need to create a large-scale application.<br>Support by hitting a like :-)</p><p><strong>References</strong></p><ul><li><a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-sticky-sessions.html">Configure sticky sessions for your classic load balancer</a></li><li><a href="https://en.wikipedia.org/wiki/GeoDNS">GeoDNS</a></li><li><a href="https://nickcraver.com/blog/2013/11/22/what-it-takes-to-run-stack-overflow/">What it takes to run Stack Overflow</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9666dd4902b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design: Scale From Zero To Millions of Users (Part I)]]></title>
            <link>https://medium.com/@koalatime/system-design-scale-from-zero-to-millions-of-users-part-i-9f544407d44e?source=rss-afab2a88db49------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f544407d44e</guid>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[system-design-course]]></category>
            <category><![CDATA[large-scale-application]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <dc:creator><![CDATA[koalatime]]></dc:creator>
            <pubDate>Sun, 08 Sep 2024 04:14:44 GMT</pubDate>
            <atom:updated>2024-09-09T16:46:22.264Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Note:</strong> This article references extensively from the book <a href="https://www.amazon.com/System-Design-Interview-insiders-Second/dp/B08CMF2CQF/ref=sr_1_1?crid=1I010DBNDOBBU&amp;dib=eyJ2IjoiMSJ9.CZwZ7txhICEtME2JuLCqj9Bkde4opffmKt_uE1rHfELYAuf586LOvm5lRHqs9kSjQChEI7-2HMtRBglW6zXJ4WaMrasODHyNsciWcJXZduvct1GWpcaff_505mHl80hdNruXdfVIRmNt5wzMuqn5hah_jkFTxNGsVw5AfTtrgoGHjrToypQkU1vcfqsECbVfqfKeuLegDQjsBeNmpgy4ahdA23M2DBKCUPYL_0clRjM.iN7M35QF0d0sPI7g7wK_El6G2FeQeKG-9d3Q-uSS6gk&amp;dib_tag=se&amp;keywords=System+design+interview+alex+xu&amp;qid=1725754172&amp;s=books&amp;sprefix=system+design+interview+alex+xu%2Cstripbooks%2C136&amp;sr=1-1"><em>System Design Interview — An Insider’s Guide</em> by Alex Xu</a> (Volume I), which I reviewed thoroughly. The definitions and illustrations provided herein are majorly sourced from this text because of its high clarity.</p><p>The initial focus will be on designing a system capable of supporting a single user. Next, the discussion will progress to scaling the system to accommodate millions of users. The objective is to equip you with foundational knowledge in system design and offer insight into the underlying architecture of today’s applications. This knowledge will serve you well in your daily job. Let’s go!</p><p><strong>Single Server Setup</strong></p><p>Here’s a breakdown of the request flow in a simplistic single-server setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dBKgLLkKlyPUdsp3bxppDA.png" /></figure><ul><li>Users access websites through domain names, such as “mysite.com”. Domain names are strings that map to IP (Internet Protocol) addresses and reside inside a DNS (Domain Name Server). <em>Fun fact, there are over 300 million registered domain names.</em></li><li>The IP address is returned to the user. For example, in the image above 15.125.23.214 is returned.</li><li>HTTP (Hypertext Transfer Protocol) requests are sent directly to your web server using the IP address.</li><li>The web server returns HTML pages (or JSON response) for rendering.</li></ul><p><strong>Decouple Database and Web Server</strong></p><p>As your user base expands, a single server won’t be enough. The next logical step is to decouple the web server (web tier) from the database (data tier), allowing for independent scaling of each component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e0jFr1Gr6NHJMDaetTs1UA.png" /></figure><p><strong>Which Database to Use? SQL vs NoSQL</strong></p><p>Everyone probably knows this by now, but relational (SQL) databases represent and store data in tables and rows. These offer an ability to establish relations between tables and perform join operations. Eg: MySQL, Oracle, PostgreSQL.</p><p>Non-relational (NoSQL) databases are grouped into 4 categories: document, graph, column and key-value stores, each offering distinct features. Joins are generally not supported in these types of databases.</p><p>In most cases, a relational db would be a decent option. But, you might wanna switch to a NoSQL db if:</p><ul><li>Your application requires super-low latency</li><li>Your data are unstructured</li><li>You only need to serialize/deserialize data (why store it as a string in relational db?)</li><li>You need to store a MASSIVE amount of data</li></ul><p><strong>Scaling: Vertical vs Horizontal</strong></p><blockquote>Vertical scaling or “scaling up” refers to adding more power (CPU/RAM) to your servers. Horizontal scaling or “scaling out” refers to adding more servers.</blockquote><p>Which is more powerful?</p><p>Vertical scaling is a great option when traffic is considerably low due to its simplicity and cost. But, when traffic starts going berserk, you’d start noticing limitations of vertical scaling:</p><ul><li>It has a hard limit: you can only add limited CPU and memory to a single server.</li><li>No failover/ redundancy: if the server goes down, everything goes down (a single server is a SPOF: Single Point of Failure)</li></ul><p>Hence, in high-traffic scenarios (large-scale applications) horizontal scaling is a better option. If one server fails, others can serve data. Additionally, as traffic increases, additional servers can handle the incoming requests. But wait, how is each request directed to the appropriate server?</p><p><strong>Load Balancer</strong></p><p>A load balancer evenly distributes incoming traffic among web servers that are defined in a load-balanced set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ag9rEOmedV2oNFeS4PftTw.png" /></figure><p>The users connect to the public IP of the load balancer (88.88.88.1 in the image above). Notice how the web servers are unreachable as they now reside in a private network and only the load balancer can interact with the servers through a private IP.</p><p>With this setup, we have considerably improved the availability of the web tier. If the traffic grows more, adding more servers will solve the problem gracefully as we already have a load balancer in place.</p><p>And, if any one of the servers goes down, all the traffic will be routed to the other servers preventing the website from going completely offline. How amazing is that!</p><p>Having successfully replicated the web servers, the next step is to apply the same approach to the databases.</p><p><strong>Database Replication</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4EHvyffta07eq3EJ24Ml6g.png" /></figure><blockquote>Database replication refers to the process of copying data from a primary database to one or more replica databases.</blockquote><p>The primary database typically handles write operations exclusively, while secondary databases manage read operations and are periodically synchronized with the latest data. This configuration, with one primary database for writes and multiple secondary databases for reads, is employed because real-world applications often exhibit a high read-to-write request ratio: you’d probably spend more time surfing an e-commerce website than actually making a purchase.</p><p>Note: The image above contains a “cluster control” for all db servers. This is analogous to the load balancer with a web server. I won’t add that in the other diagrams and should be assumed to be present.</p><p>Advantages of Database Replication:</p><ul><li>Better performance: more queries can be processed in parallel</li><li>High Availability: even if one db server is down, your application can access data using other db servers</li><li>Reliability: In the event of one database server being destroyed due to a natural disaster, the other servers act as a data backup because the data is usually replicated across multiple locations</li></ul><p>What happens when a database server goes down?</p><p>If a secondary db server goes down, read operations will still be served through other secondary servers. If there was only a single server, then the request must go to the primary server temporarily till the secondary server is finally restored.</p><p>If the primary db server goes down, then one of the secondary servers is promoted to become the primary server. (This might be complicated because the secondary server might not be up to date)</p><p>Below is the architecture of our system following the design and scaling of the web and data tiers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*RpPN2GDLgeEZ4EPMpAd-8A.png" /></figure><p>Next, let’s improve load/response time.</p><p><strong>Cache</strong></p><blockquote>A cache is a temporary storage area that stores the result of expensive responses or frequently accessed data in memory so that subsequent requests are served more quickly.</blockquote><p>The advantage of incorporating a cache tier is to reduce the load on the database tier. Caching strategies have been well summarized on <a href="https://codeahoy.com/2017/08/11/caching-strategies-and-how-to-choose-the-right-one/">this link</a>. In one approach called <em>cache-aside</em>, the application talks to both the cache and the database servers. If the requested data is present in the cache, it is returned to the client. If the data is not cached, the request is forwarded to the database servers.</p><ul><li>Consider using a cache when data is read frequently but modified infrequently</li><li>A cache should never be used as a persistent storage- if the cache server restarts, all data in memory will be lost</li><li>It is good practice to maintain an <em>expiration policy</em> on data. Expired data should be removed from the cache.</li><li>A cache should be in sync with the latest data</li><li>Once the cache is full, any requests to add items to the cache cause existing items to be removed. Commonly used eviction policies include Least-frequently-user (LFU), Least-recently-used (LRU), and First-in-first-out (FIFO)</li><li>Consider adding multiple cache servers spread across different locations to avoid SPOF</li></ul><p>Next, let’s cache static content and further improve website load times.</p><p><strong>Content Delivery Network (CDN)</strong></p><blockquote>A CDN is a network of geographically dispersed servers used to deliver static content. CDN servers cache static content like images, videos, CSS, Javascript files, etc.</blockquote><p>When a user visits a website, a CDN server closest to the user will deliver static content. If the content is not on the CDN, it is fetched from the server and stored on the CDN for future users. As illustrated below, image.png is initially fetched from the server for user A (as it is not yet cached in the CDN). Subsequently, when user B requests image.png, it is served from the CDN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4OWPkEk7d0Ox-kUxl1wagQ.png" /></figure><p>Notice how JS files for <a href="https://www.dell.com/en-in/shop/deals">dell.com deals pages</a> are being rendered via a CDN:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmY2S-vUlngzYJwn19wj3g.png" /></figure><ul><li>CDNs are run by third-party providers and come with a cost</li><li>Set content expiry on the CDN cache</li><li>Consider fallback strategies in case of CDN failure (clients should be able to request content from the original server)</li></ul><p><strong>Closing Remarks</strong></p><p>Let’s look at the steps we took to scale our system to support millions of users:</p><ul><li>Decouple tiers</li><li>Building redundancy at every tier: replicate web and database servers</li><li>Improve system performance by using caches: cache data to load off database servers and host static assets in CDN to load off web servers</li></ul><p>Below is the architecture of our system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g8G8iGG-da-Z81gp_wMH0w.png" /></figure><p>I would recommend that you scroll all the way up and see how much the system has leveled up!</p><p>There are a few more concepts that are covered in <a href="https://medium.com/@connect2kaushambi/system-design-scale-from-zero-to-millions-of-users-part-ii-9666dd4902b0">part II</a>. <br>Support by hitting a like :-)</p><p><strong>References</strong></p><ul><li><a href="https://blog.teamtreehouse.com/should-you-go-beyond-relational-databases">Should you go beyond relational database</a>s</li><li><a href="https://highscalability.com/what-the-heck-are-you-actually-using-nosql-for/">What the heck are you actually using NoSQL for?</a></li><li><a href="https://www.qlik.com/us/data-replication/database-replication#:~:text=Database%20replication%20refers%20to%20the,system%20fault%2Dtolerance%20and%20reliability.">What is database replication?</a></li><li><a href="https://www.mongodb.com/docs/manual/core/replica-set-architecture-three-members/#primary-with-a-secondary-and-an-arbiter">Three Member Replica Sets in Mongo DB</a></li><li><a href="https://codeahoy.com/2017/08/11/caching-strategies-and-how-to-choose-the-right-one/">Caching Strategies and how to choose the right one</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f544407d44e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>