<?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 Atishay Jain on Medium]]></title>
        <description><![CDATA[Stories by Atishay Jain on Medium]]></description>
        <link>https://medium.com/@atishayjn?source=rss-a185bbff0ad6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ATsPjdUdVt7kczytpg_QCA.jpeg</url>
            <title>Stories by Atishay Jain on Medium</title>
            <link>https://medium.com/@atishayjn?source=rss-a185bbff0ad6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:17:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@atishayjn/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Hitchhiker’s Guide to Interning in Tech]]></title>
            <link>https://medium.com/@atishayjn/the-hitchhikers-guide-to-interning-in-tech-370968f6dae8?source=rss-a185bbff0ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/370968f6dae8</guid>
            <category><![CDATA[intern]]></category>
            <category><![CDATA[experience]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[Atishay Jain]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 07:32:15 GMT</pubDate>
            <atom:updated>2024-07-08T07:32:15.382Z</atom:updated>
            <content:encoded><![CDATA[<p>I have recently completed my internship, fresh out of college, as a software developer associate, and it seems like a good time to write about my experience. I tried to write this with a touch of wit and, as evident from the title, paying homage to the genius Douglas Adams.</p><h3>Don’t Panic</h3><p>I, a humble software engineer intern, crossed the threshold into the strange new world of corporate engineering, armed with only boundless curiosity and the immortal advice: “Don’t Panic.”</p><h3>Navigating the Sea of Acronyms</h3><p>The first thing I noticed was the peculiar dialect spoken within these high-tech Babel. Acronyms floated around the office like cosmic debris: RFC, QA, UAT, EQE, and the ever-elusive CI/CD. This alphabet soup the seasoned developers used to juggle effortlessly, adding to my imposter’s syndrome. Here’s a leaked excerpt from the confines of my MS Teams:</p><blockquote>“So, this record is in RC status, that’s why it needs to be handled differently”<br>“Ah, yes. But, sorry what was RC again?”<br>“Well, a record is marked as RC when it comes between JDS and NDS timing”<br>“That… that makes sense, thanks”</blockquote><p>The answer to the meaning of one acronym is a bunch of other acronyms, thus going on this never-ending chain.</p><p>Where’s the glossary when you need it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xNnDBt2DFPZQ3xu1br66YA.png" /></figure><h3>Freedom To Fail</h3><p>On the scale of 1–100, initially a manager’s expectation from an intern is about -42, and one of the great comforts of an intern is the vast margin of error they are allowed.</p><p>Accidently merging your branch with the main can surely contribute to you having a mini heart attack until your colleague, with the twist of his wand, revert the commit and you can finally breathe properly again.</p><p>Each misstep was a chance to explore the boundaries of my knowledge and to expand them. Supervisors and mentors, with their godly patience, guided me through my blunders with corrections and valuable insights.</p><p>It was here that I discovered the true value of a supportive environment, <strong>sometimes the freedom to fail can be the greatest gift of all.</strong></p><h3>The Daily Stand-Up</h3><p>Every evening, the team gathered for the ritual known as the Daily Stand-Up. What do you guys think when you hear the word ‘stand-up’? A comedy special? A guy telling a bunch of jokes and the crowd bursting into laughter? Great. Now think the exact opposite.</p><p>A group of intelligent beings attempting to distill the essence of their work into succinct, jargon-laden summaries. Imagine explaining the plot of <em>Inception</em> in a single tweet.</p><p>As a fresh-faced intern, my contributions were generally met with polite nods, a resounding “Thank you Atishay” and the occasional, “That’s….. interesting.”</p><h3>The Infinite Loop of Learning</h3><p>The universe, as someone astutely observed, is big. Enormous really. And the universe of software development is no different. It was like being adrift in the cosmos of perplexing frameworks and bewildering codebase.</p><p>Each new task revealed layers of complexity and a seemingly infinite loop of learning. Just when I thought I was starting to get a grip on one concept, another, more convoluted challenge would appear before me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_RWkFq35Gf8hgpN_CWUbzQ.png" /></figure><h3>Finding My Footing</h3><p>Gradually, I began to find my footing. The acronyms started to make sense, the managers’ expectations became manageable, and the Daily Stand-Up transformed from a source of dread to a quirky routine. I even learned to navigate the labyrinthine codebase with something resembling confidence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NUy4wcHczyGdRsh6v4bd7w.png" /></figure><h3>So Long, and Thanks for All the Coffee</h3><p>As my internship progressed, I came to appreciate the beautiful chaos of the software galaxy. It was a place where logic and creativity meet, where challenges are stepping stones to growth. Through it all, I clung to the wisdom:</p><blockquote>“Time is an illusion, and lunchtime doubly so.”</blockquote><p>I learned the importance of communication and collaboration, and though it never got emphasized enough at the university, one should place it right there at the podium with technical know-how.</p><p>So, to all the future interns out there, I offer this advice: <strong>Communicate well with your colleagues. Don’t fear unknown acronyms. Never stop learning. Enjoy the journey and above all — Don’t Panic.</strong></p><p>So, that was (kind of) my account of my first-ever internship. I am all set to join as a full-fledged software developer starting next month. Let me know if I managed to make you smile :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=370968f6dae8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BNY Mellon Interview Experience]]></title>
            <link>https://medium.com/@atishayjn/bny-mellon-interview-experience-c0d94c397716?source=rss-a185bbff0ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0d94c397716</guid>
            <category><![CDATA[bny-mellon]]></category>
            <category><![CDATA[campus-placements]]></category>
            <category><![CDATA[fresher-jobs]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Atishay Jain]]></dc:creator>
            <pubDate>Thu, 11 Jan 2024 13:39:32 GMT</pubDate>
            <atom:updated>2024-01-11T13:39:32.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*3heyA8VPIgSYoADM" /></figure><p><a href="https://medium.com/u/f8dfb61c56be">BNY Mellon</a> visited our campus in mid-August 2023 for recruiting. The Bank of New York Mellon Corporation is an American banking and financial services corporation. The bank offers investment management, investment services, and wealth management services. With over 230 years of pioneering spirit, it’s one of the oldest US banks and the largest custodian bank in the world.</p><p>In this blog, I’ll share my interview experience in detail, focusing on each round and the lessons learned, which may be valuable for anyone preparing for a similar role.</p><h3>Round 1: Online Assessment</h3><p>The OA comprised four questions of medium to hard difficulty. The test was conducted on the Hackerrank platform and the duration was of 1.5 hours. The questions in the OA explored topics like <strong>graphs</strong>, <strong>strings</strong> and <strong>arrays</strong>, <strong>dynamic</strong> <strong>programming</strong>, and <strong>number</strong> <strong>theory</strong>. I found the questions harder than expected.</p><p>In the end, I did two questions completely and one partially. Results were announced in 2–3 days and 22 students in total moved to the interview rounds.</p><h4>Tip and Key Takeaways:</h4><ul><li>Even if you can’t come up with the most optimized solution right away, code what you come up with as it will pass some of the test cases and later improve upon it as you come up with ideas.</li><li>Check out what the company asks in their OAs on sites like <strong>Leetcode</strong> or <strong>Job</strong> <strong>Overflow</strong>. Most of the time, similar questions come if not the same. Also, try asking your friends on different campuses, if the company has visited there and the types of questions they asked.</li></ul><h3>Round 2: Technical Round 1</h3><p>The interview was scheduled online on Microsoft Teams. After a brief introduction, I was given two easy-level <strong>DSA</strong> questions which I was required to code on my desired code editor while screen-sharing. After that, a <strong>SQL</strong> problem was presented, I was not very comfortable with the syntax at the time, anyway, I conveyed my logic and wrote a query. After some questioning, he seemed satisfied.</p><p>After that, he asked me some questions on CS fundamentals which I answered:</p><ul><li>Primary Key v/s Unique. How do they handle null values?</li><li>Discussion on distributed systems</li><li>What is DNS?</li><li>Process v/s Threads</li><li>NoSQL v/s SQL</li></ul><h4>Tip and Key Takeaways:</h4><ul><li>Even if you don’t know something, try your best to answer the question instead of straight-up declining.</li><li>While answering theoretical questions, make sure to have a <em>flow </em>and that the interviewer follows your explanation.</li></ul><blockquote>For ex. while answering process v/s threads, start with ‘what is a program ?’. Then explain about process and then about threads and the relationship b/w them. Now, highlight the differences b/w process and a thread. Rather than jumping staright into the differences.</blockquote><h3>Round 3: Technical Round 2</h3><p>This round was overall more focused on CS fundamentals and general development. After a brief introduction, he took a look at my projects and noticed I have used the MERN stack, so he asked questions on <strong>REST</strong> architecture, <strong>NoSQL</strong> (MongoDB) databases, why <strong>Javascript</strong> is used?, <strong>DOM</strong> representation, and some more questions about JS. This felt more like a rapid-fire round, in which I was required to answer briefly (and concisely).</p><p>Further, He asked questions on <strong>OOP</strong> principles, mainly on <strong>static</strong> keyword, <strong>inheritance</strong>, and <strong>access</strong> <strong>modifiers</strong>. The problems were scenario-based, in which I had to tell the output or what value a particular variable holds for the code he was dictating. This was the major part of the interview and was a little tricky, I stumbled at some points but overall it went well.</p><p>After that, he asked me the difference between <strong>Encapsulation and Abstraction</strong>, which I explained with an example. He then gave me an <strong>SQL</strong> query which was a little trickier than what I was given in the previous round. I managed to write a query but was not sure if it was correct.</p><p>He then gave me an easy-level DSA question based on <strong>linked</strong> <strong>lists</strong>. Then we had a discussion on <strong>clustering</strong>/replica sets, <strong>sharding</strong>, and databases in general.</p><p>He asked me if I had been introduced to <strong>AI</strong> and <strong>Data</strong> <strong>science</strong>, and after a short discussion on the topic the interview concluded.</p><h4>Tip and Key Takeaways:</h4><ul><li>Read about the company and JD and tailor your answer according to that, For ex. BNY Mellon being a financial institution, naturally prefers SQL databases. So make sure to show your knowledge of the same.</li><li>If you are in CS, take your college courses seriously. They can be beneficial when the interviewer wants to discuss certain topics but they are not something you have particularly worked on (ex. AI, DS, or Information security). A basic understanding is all you need.</li></ul><h3>Round 4: Techno-Managerial Round</h3><p>This was taken by a director-level person as is generally the case. He started by asking about my day and then asked me about my favorite subjects. I said <strong>Operating Systems</strong>, <strong>Database Management</strong>, and <strong>Computer</strong> <strong>Security</strong>. He then started asking questions on the mentioned subjects.</p><p>The questions were like:</p><ul><li>Different types of OS(es), Linux v/s Windows, some Linux commands (grip, yum, ps, etc), Virtual Machines</li><li>Explain Semaphores with an example.</li><li>Discussion on Atomicity and Transactions. What is it and how to implement it in Java and Python? He wanted the actual code which I was not able to provide.</li><li>What are SQL injections?, vulnerabilities in unsecured DB, etc.</li></ul><p>He also asked me an easy-level DSA question related to the buying and selling of stocks, which I was required to code on a notepad.</p><p>After some general discussion around AI, Data science and software engineering, the interview ended.</p><h4>Tip and Key Takeaways:</h4><ul><li>Pick your favorite subjects carefully, when asked, as the rest of the interviews will be based on that.</li></ul><h3>Ending Note</h3><p>I finally got the offer. I remember being burned out by three back-to-back interviews the previous day when I had these interviews. But all the hardship proved to be worth it in the end. The internship starts this month and I am excited to join the company and gain valuable experience.</p><p>Find some of the resources and guides I used during my preparation linked below:</p><ul><li><a href="https://atigit15.github.io/Interview-Prep/">Interview Preparation Guide</a></li><li><a href="https://atigit15.github.io/Data-Structures-and-Algorithms">DSA Preparation Guide</a></li></ul><blockquote>Feel free to connect with me on <a href="https://www.linkedin.com/in/atishayjain15/">LinkedIn</a> and check out my projects and works at <a href="https://github.com/Atigit15">Github</a>. If you liked what you read, follow me <a href="https://medium.com/u/a185bbff0ad6">Atishay Jain</a> for more such content.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0d94c397716" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Media.net Interview Experience]]></title>
            <link>https://medium.com/@atishayjn/media-net-interview-experience-4dcce2bc7296?source=rss-a185bbff0ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dcce2bc7296</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[fresher-jobs]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[campus-placements]]></category>
            <dc:creator><![CDATA[Atishay Jain]]></dc:creator>
            <pubDate>Wed, 10 Jan 2024 09:33:46 GMT</pubDate>
            <atom:updated>2024-01-10T09:33:46.176Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*291HikNOMr-KI3sKsKJY5w.png" /></figure><p>Media.net visited our campus in August 2023 and was the first company to visit in the placement season. Media.net is a leading online ad-tech company that develops innovative products for advertisers and publishers. It is known for its rigorous interview process that places a strong emphasis on Data Structures and Algorithms (DSA).</p><p>Since this was my first interview experience, it gave me an opportunity to test my learnings and assess myself. In this blog, I’ll share my experience in detail, focusing on each round and the lessons learned, which may be valuable for anyone preparing for a similar role.</p><h3>Round 1: Online Assessment</h3><p>The OA comprised of 3 questions of medium to hard difficulty. the duration of the test was 1.5 hours.</p><ol><li>The first question ‘Red Zone’ was based on <strong>binary search</strong>. You can practice the question <a href="https://www.interviewbit.com/problems/red-zone/">here</a>.</li><li>The second question ‘Omega Primes’ was based on <strong>dynamic programming</strong> and <strong>bitmasks</strong>. It was similar to <a href="https://leetcode.com/problems/count-the-number-of-square-free-subsets/description/">this</a> medium-level leetcode problem. However, the recursion + memoization approach gave TLE/MLE, so was supposed to do the iterative way.</li><li>The third question ‘Fractional Knapsack’ was based on <strong>bit manipulation</strong> and <strong>implementation</strong>. We have to tell the minimum number of operations required to completely fill a knapsack with coins. The coin weights are powers of 2 and an operation is considered as breaking a coin in two equal halves.</li></ol><p>In the end, I did one question completely and one partially. Results were announced in 2–3 days and 11 students in total moved to the interview rounds.</p><h4>Tip and Key Takeaways:</h4><ul><li>Even if you can’t come up with the most optimized solution right away, code what you come up with as it will pass some of test cases and later improve upon it as you come up with ideas.</li><li>Be sure to check out what the company is asking in their OAs on sites like <strong>Leetcode</strong> or <strong>Job</strong> <strong>Overflow</strong>. Most of the time, similar questions come if not the same.</li></ul><h3>Round 2: DSA Round 1</h3><p>The interviewer straight-up asked me a DSA question. It was based on graphs. Given an undirected, unweighted, and connected graph(N, M) and K special nodes, one must find a pair of special nodes so that if connected the distance between node 1 and N changes as little as possible.</p><p>I couldn’t come up with the solution right away, after thinking for some while and listing my observations, I ended up giving a solution involving the BFS algorithm, once he was satisfied I was required to code it on the shared Google Docs file.</p><p>After that, he asked me some questions on CS fundamentals like:</p><ul><li>Difference between a process and a thread</li><li>What do you mean by indexing</li><li>Discussed horizontal and vertical scaling</li><li>Difference between abstract and interface class in OOP</li></ul><p>In the end, I asked him if he could tell me about the technologies he is currently working on and that concluded my round. 5 students moved to round 2.</p><h4>Tip and Key Takeaways:</h4><ul><li>It is okay to take your time and think, but communicate your thoughts and observations to the interviewer and make sure there are no long gaps of silence.</li><li>Write your code with proper comments with appropriate naming of functions and variables, and also focus on the overall structure of the code.</li></ul><h3>Round 3: DSA Round 2</h3><p>This time, the interview started with my brief introduction before jumping onto a DSA question. The question involved a 2D matrix (N*M) and K rectangles that lie on it. The task was to fix a l*h rectangle on the matrix such that the overlapped area with the existing rectangles was minimized. Finally, I was required to return this (minimized) overlapped area.</p><p>This time, I started with the brute force solution and slowly built up on it to arrive at an optimized solution that involved the 2D difference array concept. Once he was satisfied I coded it on the shared doc file.</p><p>After that, he asked me some questions like</p><ul><li>What are cookies?</li><li>Difference between session-based and token-based authentication, how is one better than the other?</li><li>What are race conditions? (regarding threads)</li></ul><p>I was able to answer them and this round lasted for about 45 minutes. 4 students were shortlisted for the final round.</p><h4>Tip and Key Takeaways:</h4><ul><li>Make sure you understand the task completely and ask clarifying questions until you get a clear picture.</li><li>Try to make it a two-way conversation. Start with the brute force and move towards the optimized solution while giving reasons for your choices.</li></ul><h3>Round 4: DSA/Project Round 3</h3><p>This round like the previous one started with my brief introduction. After that, the interviewer gave me a DSA question. It was a leetcode hard based on hash-table and linked list (<a href="https://leetcode.com/problems/all-oone-data-structure/">AllO’One question</a>), unfortunately, I couldn&#39;t come up with the most optimized approach for this problem in time. At last, he asked me to explain one of my projects, and that concluded my round.</p><h4>Tip and Key Takeaways:</h4><ul><li>The interviewer was friendly but didn’t provide a hint right away, he expected from me to come up with the solution.</li><li>I did not expect the last round to be based on DSA, but anything can happen in interviews so one must be prepared for anything.</li></ul><h3>Ending Note</h3><p>I ended up not getting the offer, nonetheless, it was a valuable experience and taught me how I can better articulate my thought process, optimize solutions, and work collaboratively with the interviewers to arrive at the solution. It also highlighted to me the importance of code readability, naming conventions, and the overall structure of the solution. In the end, it was a challenging yet enriching experience.</p><p>Find some of the resources and guides I used during my preparation linked below:</p><ul><li><a href="https://atigit15.github.io/Interview-Prep/">Interview Preparation Guide</a></li><li><a href="https://atigit15.github.io/Data-Structures-and-Algorithms">DSA Preparation Guide</a></li></ul><blockquote>Feel free to connect with me on <a href="https://www.linkedin.com/in/atishayjain15/">LinkedIn</a> and check out my projects and works at <a href="https://github.com/Atigit15">Github</a>. If you liked what you read, follow me <a href="https://medium.com/u/a185bbff0ad6">Atishay Jain</a> for more such content.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dcce2bc7296" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Worst Sorting Algorithms]]></title>
            <link>https://medium.com/@atishayjn/the-worst-sorting-algorithms-652f213a6a04?source=rss-a185bbff0ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/652f213a6a04</guid>
            <category><![CDATA[analysis]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[sorting]]></category>
            <dc:creator><![CDATA[Atishay Jain]]></dc:creator>
            <pubDate>Thu, 24 Aug 2023 17:35:30 GMT</pubDate>
            <atom:updated>2023-08-24T17:35:30.011Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZXzO4z9zJWQXzPij39l3GA.png" /></figure><p>In the realm of computer science, sorting algorithms stand as the backbone of various systems and have countless applications. However, not all sorting algorithms are equal, while some elegantly dance through huge datasets with grace, others stumble in the face of even moderately sized inputs.</p><p>In this article, we are going to discover some of the worst sorting algorithms in the history of computer science and also analyze their computational complexity. As we peer into the depths of these algorithmic failures, we gain not only a deeper understanding of various sorting strategies but also a newfound appreciation for the algorithms that make our digital world tick.</p><h3>Slow Sort</h3><p>This one is pretty similar to how merge sort works, the difference between the two algorithms lies in how the two sorted arrays are merged. In slow sort, we take the greatest (rightmost) elements of the two halves and place the maximum of them at the end (rightmost index of the second half).</p><p>The greatest element of the array is in its designated index, now we invoke the function again, this time excluding the last index. After this recursion is finished, the sorted array is obtained.</p><h4>Code</h4><pre>#include&lt;iostream&gt;<br>#include&lt;vector&gt;<br>using namespace std;<br><br>void slow_sort_util(vector&lt;int&gt; &amp;arr, int start, int end) {<br> if(start &gt;= end) return;<br> int mid = ( start + end ) / 2;<br> slow_sort_util(arr, start, mid);<br> slow_sort_util(arr, mid + 1, end);<br> if(arr[mid] &gt; arr[end]) swap(arr[mid], arr[end]);<br> slow_sort_util(arr, start, end - 1);<br>}<br><br>void slow_sort (vector&lt;int&gt; &amp;arr) {<br> int n = arr.size();<br> slow_sort_util(arr, 0, n - 1);<br>}<br><br>int main(){<br>    vector&lt;int&gt; arr = {2, 47, 12, 43, 67, 9, 3, 32};<br>    slow_sort(arr);<br>    for(auto i : arr) cout &lt;&lt; i &lt;&lt; &quot; &quot;;<br>}</pre><h4>Asymptotic Analysis</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*k1Qk0PHQ7wiRUEAyWCQt0g.png" /><figcaption>The run-time complexity for slow-sort</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/88/0*70xBLzHZg1elXwI3" /><figcaption>The best-case complexity for slow-sort</figcaption></figure><p>The best-case complexity for slow sort turns out to be even worse than the worst-case complexity for bubble sort.</p><h4>Comparison with Merge Sort</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QjsAELwGPBFsdD9jpxqDzg.png" /><figcaption>Plot of run-time v/s input size for merge sort</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kt0Ed-eVk9_ek9bT58alAQ.png" /><figcaption>Plot of run-time v/s input size for slow sort</figcaption></figure><h3>Bogo Sort</h3><p>Perhaps, this is the most popular <em>worst</em> algorithm for sorting. The algorithm is based on the<em> ‘generate and test paradigm’</em> and is pretty straightforward. It keeps on generating permutations of the given array and tests if that is sorted or not.</p><p>There are two ways we can go about it, the first being a deterministic way where we exhaustively keep moving to the next permutation until we get the sorted one, and the other way is to randomly shuffle the array and check.</p><h4>Code</h4><pre>#include &lt;bits/stdc++.h&gt;<br>using namespace std;<br><br>void bogo_sort (vector&lt;int&gt; &amp;arr) {<br> while(!is_sorted(arr.begin(), arr.end())) {<br>  random_shuffle(arr.begin(), arr.end());<br>  //for the deterministic way:<br>  //next_permutation(arr.begin(), arr.end());<br> }<br>}<br><br>int main(){<br>    vector&lt;int&gt; arr = {2, 47, 12, 43, 67, 9, 3, 32};<br>    bogo_sort(arr);<br>    for(auto i : arr) cout &lt;&lt; i &lt;&lt; &quot; &quot;;<br>}</pre><h4>Asymptotic Analysis</h4><ul><li><strong>Worst Case</strong>: O(∞). In the case of random shuffling, the array can keep on juggling between the non-sorted states and thus, there is no upper bound on when the array becomes sorted in the worst case.</li><li><strong>Average Case</strong>: Θ(n*n!). The cost of going through all the permutations of the array is O(n!) and the<em> is_sorted </em>check works in O(n).</li><li><strong>Best Case</strong>: Ω(n). When the given array is already sorted.</li></ul><h3>Sleep Sort</h3><p>Sleep sort is different from all other sorting algorithms. It utilizes concurrent execution and multithreading principles to get a sorted output from a given array. The idea is simple, create different threads for each of the elements in the array, and make each thread sleep for an amount of time equal or proportional to the value of the corresponding array element.</p><p>For example, if the array is [34, 12, 4, 67], then make four threads T1, T2, T3, T4, and make T1 sleep for 34 seconds, T2 for 12 seconds, and so on. The thread corresponding to the smallest value will wake up first and we get its value. The process continues until all the threads are awake.</p><h4>Code</h4><pre>#include &lt;vector&gt;<br>#include &lt;chrono&gt;<br>#include &lt;thread&gt;<br>#include &lt;windows.h&gt;<br>#include &lt;iostream&gt;<br>using namespace std;<br><br>vector&lt;int&gt; final_result;<br><br>void exec(int N) {  <br>  this_thread::sleep_for(chrono::seconds(N));<br>  final_result.push_back(N);<br>}  <br><br>void sleep_sort(vector&lt;int&gt; &amp;arr) {<br> int n = arr.size();<br> thread myThreads [n];<br> for (int i = 0; i &lt; n; i++) {<br>  myThreads[i] = thread(exec, arr[i]);<br> }<br> for(int i = 0; i &lt; n; i++) {<br>  myThreads[i].join();<br> }<br>}<br>int main(){<br>    vector&lt;int&gt; arr = {2, 47, 12, 43, 27, 9, 3, 32};<br>    sleep_sort(arr);<br>    for(auto i : final_result) cout &lt;&lt; i &lt;&lt; &quot; &quot;;<br>}</pre><p>There are some limitations of this algorithm such as it cannot be applied when there are negative numbers present in the array as a thread cannot be put to sleep for a negative duration. Also, if the array contains very large (~1e8) values, the run-time increases drastically.</p><h4>Asymptotic Analysis</h4><ul><li><strong>Worst Case</strong>: O(nlogn + max(input)). O(nlogn) as <em>n</em> threads need to be inserted in the priority queue by the OS for scheduling, also the time taken by all the threads to <em>wake up</em> depends upon the maximum element in the array.</li><li><strong>Space</strong>: Note that this algorithm is not in-place, we will need a separate array to store the result.</li></ul><h3>Stupid Sort</h3><p>Also known as <strong>Gnome sort</strong>, this can be considered as insertion sort but without the nested loops. The steps of this algorithm are as follows:</p><ul><li>If at the starting index, go one step forward.</li><li>If the previous element is less than the current element, go one step forward.</li><li>If the previous element is greater than the current one, swap them and move one step back.</li><li>Repeat the above two steps, until the end of the array is reached.</li></ul><h4>Code</h4><pre>#include &lt;bits/stdc++.h&gt;<br>using namespace std;<br><br>void gnome_sort(vector&lt;int&gt; &amp;arr) {<br> int n = arr.size();<br> int i = 0;<br><br> while (i &lt; n) {<br>  if (i == 0 || arr[i-1] &lt;= arr[i]) i++;<br>  else {<br>   swap(arr[i-1], arr[i]);<br>   i--;<br>  }<br> }<br>}<br>int main(){<br>    vector&lt;int&gt; arr = {2, 47, 12, 43, 67, 9, 3, 32};<br>    gnome_sort(arr);<br>    for(auto i : arr) cout &lt;&lt; i &lt;&lt; &quot; &quot;;<br>}</pre><h4>Asymptotic Analysis</h4><ul><li><strong>Worst Case</strong>: O(n²). At first glance, it might seem O(n), but note that our pointer in the while loop does not always get incremented, it gets decremented too. In the case of a strictly decreasing array, the complexity will be O(n²).</li><li><strong>Average Case</strong>: Θ(n²).</li><li><strong>Best Case</strong>: Ω(n). When the given array is already sorted.</li></ul><h4>Comparison with Insertion Sort</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*ckXN66Ps7GrhmOIp83dJsA.png" /><figcaption>Plot of run-time v/s input size for stupid sort</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*RV38sA11GOCm_g9mhTRqcw.png" /><figcaption>Plot of run-time v/s input size for insertion sort</figcaption></figure><p>It can be easily seen that the gnome sort becomes progressively worse than the insertion sort as the input size increases.</p><h3>Intelligent Design Sort</h3><p>This algorithm recognizes that the chance of an initial list’s order is so astronomically low that it must have been lovingly placed by an all-knowing Sorter. Attempting to impose our naïve understanding of ‘ascending order’ would be like tuning a piano in a world where harmony already reigns!</p><h4>Code</h4><pre>#include &lt;bits/stdc++.h&gt;<br>using namespace std;<br><br>void intelligent_sort(vector&lt;int&gt; &amp;arr) {<br> cout &lt;&lt; &quot;The array is already sorted :)&quot; &lt;&lt; &quot;\n&quot;;<br>}<br>int main(){<br>    vector&lt;int&gt; arr = {2, 47, 12, 43, 67, 9, 3, 32};<br>    intelligent_sort(arr);<br>    for(auto i : arr) cout &lt;&lt; i &lt;&lt; &quot; &quot;;<br>}</pre><h4>Asymptotic Analysis</h4><ul><li>This works in O(1). Bow down to the choice of The Universe!</li></ul><blockquote><em>Honorbale mentions — </em><a href="https://www.dangermouse.net/esoteric/bogobogosort.html"><em>bogobogosort</em></a><em>, </em><a href="https://iq.opengenus.org/bozosort/"><em>bozosort</em></a><em> and </em><a href="https://pages.cs.wisc.edu/~okushi/"><em>miraclesort</em></a><em>.</em></blockquote><p>So which one do <em>you</em> think is the worst of them all?</p><ul><li>Check out <a href="https://github.com/Atigit15/Sorting_Algorithms/tree/main">this</a> GitHub repository containing the implementation of these algorithms in C++.</li><li>Check out <a href="https://www.kaggle.com/iamatishay/sorting-algorithms-analysis">this</a> Kaggle notebook for contains the run-time analysis of some of these algorithms.</li></ul><p>If you learned something interesting, be sure to check out my other blogs —</p><ul><li><a href="https://medium.com/@atishayjn999/what-exactly-happens-when-you-enter-a-url-into-your-browser-2a47297833ca">What exactly happens when you enter a URL into your Browser?</a></li><li><a href="https://medium.com/@atishayjn999/the-backend-development-primer-part-2-2-7f9f19fbc1d0">The Backend Development Primer [Part 2/2]</a></li></ul><blockquote>Find me on <a href="https://www.linkedin.com/in/atishayjain15/">LinkedIn</a> and <a href="https://github.com/Atigit15">Github</a>.</blockquote><h3>References</h3><ul><li><a href="https://en.wikipedia.org/wiki/Slowsort">Wikipedia — Slow Sort</a></li><li><a href="https://www.youtube.com/watch?v=TzxLYTC8HL8&amp;list=PLsdq-3Z1EPT3S4zl9RT7SEFB4RhKoTg4s">Asli Engineering by Arpit Bhayani</a></li><li><a href="https://www.geeksforgeeks.org/bogosort-permutation-sort/">GFG — Bogo Sort</a></li><li><a href="https://en.wikipedia.org/wiki/Gnome_sort">Wikipedia — Gnome Sort</a></li><li><a href="https://www.geeksforgeeks.org/gnome-sort-a-stupid-one/">GFG — Gnome Sort</a></li><li><a href="https://www.geeksforgeeks.org/sleep-sort-king-laziness-sorting-sleeping">GFG — Sleep Sort</a></li><li><a href="https://stackoverflow.com/questions/2609857/are-there-any-worse-sorting-algorithms-than-bogosort-a-k-a-monkey-sort">Stack Overflow — Intelligent Design Sort</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=652f213a6a04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What exactly happens when you enter a URL into your Browser]]></title>
            <link>https://medium.com/@atishayjn/what-exactly-happens-when-you-enter-a-url-into-your-browser-2a47297833ca?source=rss-a185bbff0ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a47297833ca</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[computer-networking]]></category>
            <category><![CDATA[caching]]></category>
            <dc:creator><![CDATA[Atishay Jain]]></dc:creator>
            <pubDate>Mon, 17 Jul 2023 19:16:07 GMT</pubDate>
            <atom:updated>2023-07-18T09:22:58.419Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered what happens when you type a website address like <em>google.com</em> or <em>youtube.com</em> into your browser’s address bar and hit <em>enter</em>? Sure, if you are connected to the internet, you are presented with the desired web page. But exactly what goes behind the scenes is what we will be discussing in this blog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*31XUfx-opBI9LHIyNupsSw.jpeg" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><h3>Structure</h3><p>This blog will be divided into two parts, the first part will give a complete high-level overview of the whole process that starts with a client typing in a URL then, then converting the URL to an IP address (using DNS), establishing a connection to share resources and finally rendering the web page.</p><p>In the second part, we will learn about DNS and how it actually resolves the client-provided domain name into the corresponding IP address.</p><h3>Part 1: The Overview</h3><h4>1. URL Parsing</h4><ul><li>Let’s just first understand what a URL is-</li></ul><blockquote>URL stands for <strong>Uniform Resource Locator</strong>. It is composed of four parts namely- Scheme, Domain, Path and Resource, as shown in the image below.<br>If you are confused about path and resource, consider a file system and think of path as the directory path and the resource as the actual file (.txt / .cpp file or anything).</blockquote><figure><img alt="The four components of a URL" src="https://cdn-images-1.medium.com/max/908/1*SD-kvnDXamsDIwUgn28GSQ.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><p>The process starts with the client entering a URL into the browser’s address bar. The browser then parses this URL, which basically means it destructures it into components (see the diagram above). Now that the browser has the domain name extracted, the process of DNS resolution can start.</p><figure><img alt="User entering a URL to access a specific web page. For Ex: google.com" src="https://cdn-images-1.medium.com/max/509/1*z3Rda2iuA-MOwJZQTqxPrQ.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><h4>2. DNS Resolution</h4><p>The machine does not understand English, that’s what we humans understand and thus are provided to type the domain name of whatever site we need to refer to. To fulfill our request, the browser needs to know at exactly what address the web page is stored, and <em>that address must be a bunch of 0’s and 1’s!</em></p><p>In other words, it is required to convert the domain name into an IP address of the server that currently stores the files to render the required web page. After obtaining the IP, a connection can be established between the client’s machine and the server.</p><p>As soon as we hit enter, the browser first looks into something known as a DNS Cache. A cache is something where recently used information is stored for retrieval to reduce the load on servers. They are of two types-</p><ul><li><strong>Browser DNS Cache</strong> — Domain name and IP address mapping stored in the browser. If you are using Chrome, you can see your browser&#39;s DNS cache at chrome://net-internals/#dns</li><li><strong>OS DNS Cache</strong> — You can see the stored IP addresses in your computer by running ipconfig/displaydnson your terminal.</li></ul><figure><img alt="DNS resolution black box" src="https://cdn-images-1.medium.com/max/502/1*ne72S4MOCDa5IetBM7RSNQ.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><p>If the value is not found in these caches, the request goes on to the DNS resolver. For now, let’s treat it as a black box that receives a domain name and sends the corresponding IP address back to the browser. The actual working of DNS will be discussed in detail in Part 2 below.</p><h4>3. Establishing a Connection</h4><p>With the IP address obtained from the DNS resolution process, the browser can establish a TCP (<em>Transmission Control Protocol</em>) connection with the web server through a <a href="https://www.techopedia.com/definition/10339/three-way-handshake">three-way handshake</a>.</p><p>If the website uses HTTPS (secure), an additional step called SSL/TLS handshake occurs to establish a secure connection. You can read more about it <a href="https://www.ssl.com/article/ssl-tls-handshake-overview/">here</a>.</p><figure><img alt="The TCP connection to facilitate sharing of resources to and fro" src="https://cdn-images-1.medium.com/max/592/1*c9ZLd_v-XqIZsmvmsTik-Q.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><h4>4. Sending an HTTP Request</h4><p>Once the connection is established, the browser sends an HTTP (<em>Hypertext Transfer Protocol</em>) request to the web server. The request includes information about the resource you want to access (e.g., the path in the URL) and any additional data if you’re submitting a form or interacting with the website.</p><figure><img alt="Serving of HTTP request like GET,PUT,POST and DELETE" src="https://cdn-images-1.medium.com/max/629/1*YDcT5RCb5B_vL0PEA51fhA.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><h4>5. Receiving the HTTP Response</h4><p>After processing the request, the web server sends back an HTTP response to the browser. The response contains an HTTP status code, headers (e.g., Content-Type, Cache-Control), and the requested content itself (e.g., HTML page, images, CSS files).</p><h4>6. Rendering the Web Page</h4><p>Upon receiving the HTTP response, the browser starts rendering the web page. It interprets the HTML content, loads any additional resources referenced in the HTML (e.g., images, stylesheets, JavaScript files), and executes any JavaScript code.</p><blockquote>Finally you can interact with your favourite website and all this happens in few seconds, pretty neat isn’t it?</blockquote><figure><img alt="The final render of web page received from the server" src="https://cdn-images-1.medium.com/max/386/1*qdhLdR-R0nnwYD8oUBnXjg.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><h3>Part 2: DNS Resolution</h3><p>Now let&#39;s expand the black box we created in step 2.</p><blockquote>DNS stands for Domain Name System, it is essentially a distributed and decentralized collection of servers that works together in order to convert the domain name into a corresponding IP address.</blockquote><p>There are mainly four types of servers in DNS -</p><ul><li>DNS Resolver</li><li>The Root Server</li><li>Top Level Domain Server (TLD)</li><li>Authoritative Name Server</li></ul><figure><img alt="Figure showing the heirarchical model of domain names" src="https://cdn-images-1.medium.com/max/1024/1*qrRvisia6mYZ700NkDjA7A.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><p>We will be going through each of their functionality in detail. But before that, we need to know how our computer gets access to this DNS system. So, to answer that let’s learn about ISPs.</p><h4>1. ISP</h4><p>After a hurtful cache miss in the browser and OS cache storage, the browser turns to an ISP (<em>Internet Service Provider</em>). The ISP looks into its own cached records and if it is not able to find the domain name, it passes the IP address of the <strong>DNS Resolver</strong>.</p><blockquote>Some examples of ISP’s are verizon, AT&amp;T, etc. <br>In India some of the popular ones are Airtel, Reliance Jio, etc.</blockquote><h4>2. DNS Resolver</h4><p>A DNS resolver is anything that returns an IP address corresponding to a domain name, previously our browser, computer, and ISP acted as a DNS resolver. Since we met with cache miss in all the above three, we need to contact a higher authority, a place where we will be definitely able to get our IP address.</p><p>This place is nothing but the network of servers that we call DNS, and the thing that passes our query to this DNS system is the DNS resolver, it basically acts as an entry point to the DNS.</p><p>The address of a DNS resolver is provided by your ISP. But you can also change it by tinkering with the network settings. Changing your DNS can lead to a faster and more secure browsing experience. Maybe now’s a good time to learn what a VPN does (<em>but we will go off-topic, instead learn about it </em><a href="https://www.fortinet.com/resources/cyberglossary/how-does-vpn-work"><em>here</em></a><em> :)</em>).</p><blockquote>Some popular examples are Cloudfare&#39;s 1.1.1.1 and Google’s 8.8.8.8</blockquote><p>We will be discussing a ‘<em>recursive</em>’ type of DNS where we basically tell the DNS resolver to not come back until it has the IP address.</p><p>There is another type which is called — ‘<em>iterative</em>’. In this, the client makes a series of requests itself until it found a match. In case of a miss, the current server directs the client to try on some other server. Learn more about it <a href="https://www.techtarget.com/whatis/definition/iterative-DNS-query">here</a>.</p><h4>3. Root Server</h4><p>The root nameserver maintains an up-to-date index of <a href="https://www.computerhope.com/jargon/t/tld.htm">TLD</a> nameservers, each of which handles a specific TLD, such as <strong>.com</strong>, <strong>.org</strong>, or <strong>.net</strong>. The root nameserver also maintains a cache of records, if it is not able to find the queried domain name, it sends back the the address of the appropriate TLD server. (<em>For example, the address of the </em><strong><em>.in</em></strong><em> TLD server is sent if the query was for a</em><strong><em>mazon.in</em></strong>).</p><figure><img alt="Quering the root server" src="https://cdn-images-1.medium.com/max/719/1*L-uB1_Z0lLnRHJW22DpHEQ.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><p>The resolver then queries the specified TLD server.</p><blockquote>There are a total 13 sets of these root servers (A-M) which are strategically placed around the globe. They are managed by 12 organization. The map below shows the distribution of these root servers</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xxVePliwv5SYlDNbxi5tVg.png" /><figcaption><a href="https://root-servers.org/">https://root-servers.org/</a></figcaption></figure><h4>4. Top-Level Domain (TLD) Servers</h4><p>The TLD servers manage information about domain names under their specific TLDs. When the DNS resolver queries the TLD server for the IP address of the requested domain (e.g., “google.com”), the TLD server either provides the IP address directly(cache system) or refers the resolver to the authoritative name server responsible for that domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*bekexsmRPC5rfx_WxdFOmQ.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><h4>5. Authoritative Name Servers</h4><p>These are the final stop in the DNS resolution process. The authoritative name servers store the DNS records for specific domain names. Each domain typically has at least two authoritative name servers for redundancy and fault tolerance. When the DNS resolver contacts the authoritative name server for the requested domain, it receives the IP address of the server hosting the website associated with that domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*Y2K22dUVlj-LjfqenQ6CcQ.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><h4>6. IP Address Returned</h4><p>The client (<em>finally</em>) gets back the IP address from the DNS resolver, which caches the IP address in its local cache for future use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*MgTUeB8GVEZXig9zeTjzyw.png" /><figcaption>Image courtesy of ByteByteGo</figcaption></figure><p>Step 2 described in Part 1 is now complete, and we can move on with the rest of the steps as described.</p><p>Notice how caching mechanism is involved in every step of DNS resolution. And how the DNS system is distributed among various servers. This distributed network and the caching mechanisms are necessary in order to make the URL resolution process seamless and efficient.</p><p>If you learned something new, be sure to show your support and check out my other blogs —</p><ul><li><a href="https://medium.com/@atishayjn999/the-backend-development-primer-part-1-2-43a115dde891">The Backend Development Primer [Part 1/2]</a></li><li><a href="https://medium.com/@atishayjn999/the-backend-development-primer-part-2-2-7f9f19fbc1d0">The Backend Development Primer [Part 2/2]</a></li></ul><blockquote>Find me on <a href="https://www.linkedin.com/in/atishayjain15/">LinkedIn</a> and <a href="https://github.com/Atigit15">Github</a>.</blockquote><h3>References</h3><ul><li>A short<a href="https://www.youtube.com/watch?v=AlkDbnbv7dk&amp;t=1s">video</a> by ByteByteGo (Part 1)</li><li>DNS Resolution explanation by <a href="https://www.youtube.com/watch?v=mpQZVYPuDGU">PowerCert Animates Videos</a> (Part 2)</li><li>A short<a href="https://www.youtube.com/watch?v=27r4Bzuj5NQ"> video</a> by ByteByteGo (Part 2)</li><li><a href="https://www.computerhope.com/jargon/d/dns-resolver.htm">https://www.computerhope.com/jargon/d/dns-resolver.htm</a></li><li><a href="https://www.cloudflare.com/learning/dns/what-is-recursive-dns">https://www.cloudflare.com/learning/dns/what-is-recursive-dns</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a47297833ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Backend Development Primer [Part 2/2]: Caching, Scaling and more]]></title>
            <link>https://medium.com/@atishayjn/the-backend-development-primer-part-2-2-7f9f19fbc1d0?source=rss-a185bbff0ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f9f19fbc1d0</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[scaling]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Atishay Jain]]></dc:creator>
            <pubDate>Mon, 03 Jul 2023 11:37:01 GMT</pubDate>
            <atom:updated>2023-09-09T17:47:20.684Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we will continue where we left off. If you haven’t checked the ‘Part 1’ out, I highly recommend to read that first, so you get a basic understanding of how things work at the backend :) Now let’s get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tVuPiIyTWN0ng3dM.jpg" /><figcaption><a href="https://realpython.com/python-contact-book/">https://realpython.com/python-contact-book/</a></figcaption></figure><h3>Table of Contents</h3><ol><li>Databases</li><li>Authentication and Authorisation</li><li>Performance Optimisation</li><li>Caching</li><li>Scaling</li><li>Serverless Architecture</li></ol><h3>1. Databases</h3><p>Data persistence is integral to the vast majority of web applications. Being able to understand how to structure, build, and query your own database are important skills for any full stack developer to have.</p><p>Databases are split into “relational” and “non-relational” types of databases, and each handles data and scaling in different manners.</p><ul><li><strong>SQL</strong>(<em>Structured query language</em>) databases are relational databases that store and manage data using tables. They ensure data integrity, support powerful querying with SQL, and offer scalability, ACID transactions, and data security. Popular implementations include <em>MySQL, PostgreSQL, and Oracle Database.</em></li><li><strong>NoSQL</strong> (<em>Not only SQL</em>) databases offer flexible data models, scalability, and high performance. They don’t enforce strict schemas (like SQL) and excel in handling large volumes of unstructured data. Popular implementations include <em>MongoDB, Cassandra, and Redis</em>. They are ideal for real-time data, high-speed transactions, and large-scale analytics.</li></ul><p>Ultimately, which DB you chose depends on the type of functionality you want in your application. <a href="https://circleci.com/blog/sql-vs-nosql-databases/">This</a> article goes in depth with the difference between the SQL and NoSQL DB’s.</p><h3>2. Authentication and Authorisation</h3><p>Are they the same thing ? Definitely not.</p><p>Authentication is the process by which we determine whether a user is who he claims to be. Whereas authorization is the process of verifying what specific applications, files, and data a user has access to. Authorisation always comes after authentication.</p><p>There are various way of providing authentication, some of them being -</p><ul><li>Classic email and password verification</li><li>Google’s OAuth 2.0 protocol (sign in with google feature)</li><li>JWT tokens. <a href="https://www.youtube.com/watch?v=7nafaH9SddU&amp;ab_channel=TraversyMedia">Learn More</a>.</li><li>Using libraries such as passport and session. <a href="https://levelup.gitconnected.com/everything-you-need-to-know-about-the-passport-local-passport-js-strategy-633bbab6195">Learn More</a>.</li></ul><p>Note that hashing users&#39; passwords before storing it is a very important step, storing user’s password in plain text in your database is very dangerous flaw. A library called <em>bcrypt </em>helps with hashing and comparing the passwords.</p><blockquote>If you want to learn more about authentication, then I recommend reading about <a href="https://www.makeuseof.com/what-is-a-zero-knowledge-proof/">zero-knowledge proofs</a>, which is core concept in authentication.</blockquote><h3>3. Performance Optimisation</h3><p>In today’s fast-paced digital world, a slow-loading website or application can frustrate users and cause them to abandon it altogether. Therefore, it’s crucial to optimize the performance of MERN stack applications to ensure they can handle a high volume of traffic without compromising on speed and performance.</p><p>Performance optimisation can be categorised in to two parts -</p><ul><li><strong>Code Optimisation</strong> : This includes techniques like minification of code, lazy loading, server-side rendering, code splitting and load balancing.</li><li><strong>Database Optimisation</strong> : This includes techniques like indexing, denormalisation, caching, partitioning and database sharding.</li></ul><p>Note that these optimisation techniques becomes important when developing enterprise level applications. We will discuss caching and database sharding in detail in the upcoming sections.</p><p>If you want to know more about the techniques mentioned above. Check out <a href="https://dev.to/clickysoft/optimizing-mern-stack-performance-techniques-for-high-traffic-applications-628">this</a> article.</p><h3>4. Caching</h3><p>As discussed above, caching is database optimisation technique. A cache layer or server acts as a secondary storage layer, faster and highly efficient to temporarily store a subset of data which doesn’t change often and is frequently accessed by the client. To maintain it’s small size and freshness, the data items also have an expiration time.</p><p>Two caching paradigms-</p><ul><li><strong>Cache Aside Pattern</strong> : Also known as <em>lazy loading</em>, is the most common caching pattern available. Here, the cache is updated after the data is requested. In order to read data from the database, the cache is first checked to determine whether the data is available. If the data is available (also known as a <em>cache hit</em>), the cached data is returned. Otherwise (<em>cache miss</em>), the database is queried for the data and then the cache is the populated with this data.</li><li><strong>Write-Through Pattern</strong> : Here, when the application or backend process updates the primary database, the data is also updated in the cache. In case of cache miss, lazy loading pattern is deployed. Here, the chances of a cache miss is reduced but, the size of cache has increased and it’s also storing items which are infrequently accessed.</li></ul><p>‘<em>node-cache</em>’ and ‘<em>memcache</em>’ are two popular Nodejs packages. The most popular option for caching is using ‘<strong>Redis</strong>’. Being an in-memory database, its data access operations are faster than any other disk-based database, which makes Redis the perfect choice for caching.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eSJGKTXJLOPu5rNNlVVfHQ.png" /><figcaption><a href="https://redis.com/blog/design-pattern-mean-mern-stack-performance/">https://redis.com/blog/design-pattern-mean-mern-stack-performance/</a></figcaption></figure><p>Check out <a href="https://www.mydistributed.systems/2020/07/an-overview-of-storage-engines.html">this </a>article for difference between on-disk and in-memory databases.</p><h3>5. Scaling</h3><p>While developing an application in our local machine we have one server, to which we make a single request at a time. Also, our application acts as a single service. This type of system is called a <strong>monolithic system</strong> ((0,0,0) in the cube shown below)</p><p>However, an enterprise level application needs to handle multiple requests at the same time from possibly million of users. Surely, there is a need to scale our application so that it can perform in these type scenarios.</p><p>The diagram below shows three dimensions of scaling, let’s discuss each of them in brief below-</p><figure><img alt="The scale cube showing the three dimemsions to scaling" src="https://cdn-images-1.medium.com/max/972/1*a5gAFyDpvL2TwiNi0N1UKw.png" /><figcaption><a href="https://thenewstack.io/from-monolith-to-microservices/">https://thenewstack.io/from-monolith-to-microservices/</a></figcaption></figure><ul><li><strong>Cloning Services</strong>:</li></ul><p>To prevent one server to become swarmed with requests and thus take a lifetime to respond, we create multiple instances of our server listening for the same set of requests. We can implement this in our local machine, we use <em>cluster</em> module which is a inbuilt module in Nodejs, having multiple cores (or CPU’s) by running each instance in each of the core.</p><pre>const express = require(&#39;express&#39;);<br>const cluster = require(&#39;cluster&#39;);<br>const totalCpus = require(&#39;os&#39;).cpus.length;<br>//totalCpus will give total number of CPU&#39;s in your machine<br><br>if (cluster.isMaster) {<br>for (let i = 0; i &lt; totalCpus; i++) <br>  // create worker threads<br>  cluster.fork();<br>}<br>else {<br>  //each worker thread will execure this<br>  const PORT = 3000;<br>  const app = express();<br>  app.listen(PORT, () =&gt; {console.log(`Server running on ${PORT}`)};<br>}<br><br>//This will result in multiple servers listening on the same PORT and also <br>//connected to the database seperately.<br>//Output<br>/* Server running on 3000<br>   Server running on 3000<br>   Server running on 3000<br>   ....8 times, if running on octa-core machine.<br>*/<br></pre><p>Check out <a href="https://www.youtube.com/watch?v=f6u3xSsHylY&amp;ab_channel=JavascriptProgrammer">this </a>video to see the difference in response time of multiple requests while using one versus multiple servers.</p><ul><li><strong>Database Sharding</strong>:</li></ul><p>We saw above that we can create multiple server instances, but the problem is that all these server access the same database, thus querying a DB results in a bottleneck in our application’s performance. Database sharding provides the solution for this, using this technique each server is only responsible for only a subset of data.</p><blockquote>For example, let’s take the example of Amazon. Let’s assume that amazon servers are running on 3 servers (let’s call them server A,B and C). These servers are designed in such a way that each cater to the request of only a subset of the user. For instance, Servers A handles users whose names&#39; start with ‘A’ to ‘I’. Server B handles ‘J’ to ‘R’ and C handles ‘S’ to ‘Z’. Now suppose of server B requests data fromt he database, the database will now know that it needs to look in that partition that store users’ information with initial letter from ‘J’ to ‘R’.</blockquote><p>Thus, data partitioning, as shown in the above example can improve the application’s capacity and availability.</p><ul><li><strong>Microservices:</strong></li></ul><p>Microservices are an architectural and organizational approach to software development where software is composed of small independent services that communicate over well-defined APIs. Where as Z-axis scaling splits things that are similar, Y-axis scaling splits things that are different. At the application tier, Y-axis scaling splits a monolithic application into a set of services. Each service implements a set of related functionality such as order management, customer management etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*4YZlrJxQiDKvVL8EdNA_Mg.png" /><figcaption><a href="https://aws.amazon.com/microservices/">https://aws.amazon.com/microservices/</a></figcaption></figure><p>Now our multiple server instances can assigned to a different microservices. This way multiple independent functions in our app need not to wait for each other and can run at the same time. Note that how we divide our application into microservices are important and require careful planning.</p><p>Two ways to run your application that has been divided into microservices are using- container or serverless. A platform that provides container service is ‘<em>Amazon elastic container servic</em>e’. We will discuss serverless architecture in detail next.</p><p>If you are interested to know more about backend scalability, you can check out ‘<a href="https://www.oreilly.com/library/view/art-of-scalability/9780134031408/">The Art of Scalability</a>’. Or you can check out this <a href="https://www.youtube.com/playlist?list=PLrwNNiB6YOA3xc1dfQpHuaU8HsKxkEgiQ">youtube playlist</a>.</p><h3>6. Serverless Architecture</h3><p>As you may have noticed by now, maintaining a server, making it scalable and secured among other things is not an easy job. Thus, by adopting serverless architecture, developers can offload these responsibilities to a third-party provider, enabling them to focus on writing application code.</p><figure><img alt="Function as a Service (FaaS), a popular type of serverless architecture, allows developers to focus on writing application code.Function as a Service (FaaS), a popular type of serverless architecture, allows developers to focus on writing application code." src="https://cdn-images-1.medium.com/max/1024/1*AaDy-aykSB6gnqnsDHmNDQ.png" /><figcaption><a href="https://www.datadoghq.com/knowledge-center/serverless-architecture/">https://www.datadoghq.com/knowledge-center/serverless-architecture/</a></figcaption></figure><p>One of the most popular serverless architectures is <strong>Function as a Service</strong> (<strong>FaaS</strong>), where developers write their application code as a set of discrete functions. Each function will perform a specific task when triggered by an event, such as an incoming email or an HTTP request. Developers then deploy their functions, along with their triggers, to a cloud provider account.</p><p>When a function is invoked, the cloud provider either executes the function on a running server, or, if there is no server currently running, it spins up a new server to execute the function. This execution process is abstracted away from the view of developers, who focus on writing and deploying the application code.</p><p>Few of the major FaaS providers are <em>AWS Lambda, Google Cloud Functions and AWS Functions</em>.</p><h3>References</h3><ul><li><a href="https://www.theodinproject.com/lessons/nodejs-introduction-to-mongodb">https://www.theodinproject.com/lessons/nodejs-introduction-to-mongodb</a></li><li><a href="https://circleci.com/blog/sql-vs-nosql-databases/">https://circleci.com/blog/sql-vs-nosql-databases/</a></li><li><a href="https://www.sailpoint.com/identity-library/difference-between-authentication-and-authorization/">https://www.sailpoint.com/identity-library/difference-between-authentication-and-authorization/</a></li><li><a href="https://blog.logrocket.com/caching-node-js-optimize-app-performance/">https://blog.logrocket.com/caching-node-js-optimize-app-performance/</a></li><li><a href="https://dev.to/clickysoft/optimizing-mern-stack-performance-techniques-for-high-traffic-applications-628">https://dev.to/clickysoft/optimizing-mern-stack-performance-techniques-for-high-traffic-applications-628</a></li><li><a href="https://www.infoq.com/articles/microservices-intro/">https://www.infoq.com/articles/microservices-intro/</a></li><li><a href="https://www.datadoghq.com/knowledge-center/serverless-architecture/">https://www.datadoghq.com/knowledge-center/serverless-architecture/</a></li><li><a href="https://aws.amazon.com/microservices/">https://aws.amazon.com/microservices/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f9f19fbc1d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Backend Development Primer [Part 1/2]: Introduction to Backend]]></title>
            <link>https://medium.com/@atishayjn/the-backend-development-primer-part-1-2-43a115dde891?source=rss-a185bbff0ad6------2</link>
            <guid isPermaLink="false">https://medium.com/p/43a115dde891</guid>
            <category><![CDATA[overview]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[mern-stack]]></category>
            <dc:creator><![CDATA[Atishay Jain]]></dc:creator>
            <pubDate>Mon, 03 Jul 2023 11:35:42 GMT</pubDate>
            <atom:updated>2023-09-09T17:48:43.002Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will include all the major terms you hear when backend development is discussed. You can use this to skim through all the important concepts before an interview ;) Note that this article is written with the MERN stack in view, but the underlying concepts are universal.</p><figure><img alt="backend development" src="https://cdn-images-1.medium.com/max/806/1*TZ8VTtptGzn5-IxcxY0kyg.png" /><figcaption><a href="https://realpython.com/tutorials/front-end/">https://realpython.com/tutorials/front-end/</a></figcaption></figure><h3>Table of Contents</h3><ul><li><strong>Part 1</strong></li></ul><ol><li>Introduction</li><li>HTTP</li><li>Middleware Functions</li><li>REST Architecture</li><li>CRUD Operations</li><li>MVC Architecture</li><li>CORS</li><li>Frameworks</li></ol><ul><li><strong>Part 2</strong></li></ul><ol><li>Databases</li><li>Authentication and Authorisation</li><li>Performance Optimisation</li><li>Caching</li><li>Scaling</li><li>Serverless Architecture</li></ol><h3>1. Introduction to Backend</h3><p>The back-end is the code that runs on the server, that receives requests from the clients, and contains the logic to send the appropriate data back to the client. The back-end also includes the database, which will persistently store all of the data for the application.</p><p>The backend is made up of three parts :</p><ul><li>The <strong>server</strong> : This is the computer that receives requests. To make your machine a server, install Node.js which is runtime environment for Javascript and listen on desired <em>port</em> number.</li><li>The <strong>app</strong> : This is the application running on the server that listens for requests, retrieves information from the database, and sends a response. A framework like express helps in making these apps.</li><li>The<strong> database</strong> : Databases are used to organize and persist data. They can be classified into SQL and NoSQL databases. MERN stack follows MongoDB database which is a NoSQL database.</li></ul><h3>2. HTTP</h3><p>HTTP stands for <em>Hypertext Transfer Protocol</em> and is used to structure requests and responses over the internet. HTTP requires data to be transferred from one point to another over the network. The resources itself are transferred with the help of a TCP connection.</p><ul><li>Analogy</li></ul><blockquote>Suppose <strong><em>you</em></strong> are at restaurant and you call a <strong><em>waiter</em></strong> for him to take your order. You dictate your order in<em> </em><strong><em>english</em></strong> and the waiter notes it down, he then makes a <strong><em>track</em></strong> (at the speed of light) to the kitchen and tells the <strong><em>chef</em></strong><em> </em>to prepare the order. He comes back, while ripping of the track, with the dish or some unfortunate news that the dish can’t be prepared.</blockquote><figure><img alt="Explaining HTTP with a restraunt analogy" src="https://cdn-images-1.medium.com/max/782/1*nnI_hKrPcE5cn_EgLBY1wQ.png" /><figcaption><a href="https://apipheny.io/wp-content/uploads/2020/10/api-waiter-1.png">https://apipheny.io/wp-content/uploads/2020/10/api-waiter-1.png</a></figcaption></figure><p>Here, you are the client, the waiter the server and the chef is the database. To dictate your order you chose english, while the request on web uses HTTP, the track is the TCP connection to deliver resources, and whatever the waiter comes back with is the response. The dish you want to eat is the URL (uniform resource locator), this tells the server what actually the client needs.</p><ul><li>How it is different from HTTPS ?</li></ul><p>This ‘S’ in HTTPS stands for <strong>security</strong>. Coming to the analogy above, if you tell the waiter to include a secret sauce in the dish, it might not be a good idea for the waiter to note it in plain text, ( <em>it can be read by anyone at the track junctions !</em>) To secure sensitive and personal content, some servers may provide an encryption facility.</p><h3>3. Middleware Functions</h3><p><a href="https://expressjs.com/en/guide/writing-middleware.html">Middleware</a> is any code that executes between the server receiving a request and sending a response. These functions might modify the request object, query the database, or otherwise process the incoming request.</p><p>In the analogy, the actual preparation of the dish can be thought of a middleware. Middleware functions typically end by passing control to the next (using next()) middleware function, rather than by sending a response. You often see them recieve three parameters — req, res and next.</p><pre>const express = require(&#39;express&#39;)<br>const app = express()<br><br>//our middleware functions<br>const myLogger = function (req, res, next) {<br>  console.log(&#39;LOGGED&#39;)<br>  next()<br>}<br><br>app.use(myLogger)<br><br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello World!&#39;)<br>})<br><br>app.listen(3000)<br>// code excerpt taken from express documentation<br><br>//Output<br>/* Every time the app receives a request, <br>it prints the message “LOGGED” to the terminal.*/</pre><h3>4. REST Architecture</h3><p>REST, or<em> REpresentational State Transfer</em>, is an architectural style for building API’s , providing standards between computer systems on the web, making it easier for systems to communicate with each other.</p><p>A RESTful API uses commands to obtain resources. In REST, each resource is identified by a unique URI (Uniform Resource Identifier) and can be manipulated using standard HTTP methods such as:</p><ul><li>GET to retrieve a resource;</li><li>PUT to change the state of or update a resource, which can be an object, file or block;</li><li>POST to create that resource; and</li><li>DELETE to remove it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*efK5IVCzC_AbRGB2bIQNWQ.png" /><figcaption><a href="https://www.sitepoint.com/creating-restful-apis-express-4/#creating-the-api-for-the-movie-app">https://www.sitepoint.com/creating-restful-apis-express-4/#creating-the-api-for-the-movie-app</a></figcaption></figure><p>It is based on the idea that the REST APIs are <strong>stateless</strong>, meaning that calls can be made independently of one another, and each call contains all of the data necessary to complete itself successfully.</p><p>It also s<strong>eparates the concern of server and client</strong>, allowing their implementation to be done independently of each other.</p><blockquote>By using a REST interface, different clients hit the same REST endpoints, perform the same actions, and receive the same responses.</blockquote><h3>5. CRUD Operations</h3><p>CRUD stands for Create, Read, Update and Delete operations. Think of a simple blog website, the basic function you want to give your users are — creating a blog, reading blogs of other people, updating content and deleting a blog. It’s crucial for a developer to know and implement these CRUD operations.</p><p>Corresponding to each type of operation there is a different HTTP verb that is included in the request that the client makes. HTTP verbs for CRUD are POST, GET, PUT, and DELETE respectively. Apart from HTTP verbs, a client’s request have certain other fields like — header and accept parameter, a path to resource and optional body content. Read about it <a href="https://www.codecademy.com/article/what-is-rest">here</a>.</p><p>Similarly, server’s response consists of — content type, status code and any data the client requested for (read operation). Client will only accept the data if it’s type is one of the mentioned types in header of the request.</p><ul><li>Example</li></ul><pre>//Clients request :<br>GET http://fashionboutique.com/customers<br>Accept: application/json<br>/*<br>HTTP verb : GET<br>Resource Locator : fashionboutique.com/customers<br>Accept files which are application/json format.<br>*/<br></pre><pre>//Servers response<br>Status Code: 200 (OK)<br>Content-type: application/json<br>//followed by the customers data requested in application/json format.</pre><h3>6. MVC Architecture</h3><p>MVC stands for <em>Model, View, Controller</em> and refers to the architecture of your code. It is a way to organize your application by separating all of the actions into 3 main components: Models, Views and Controllers.</p><figure><img alt="Model-View-Controller Diagram" src="https://cdn-images-1.medium.com/max/1024/1*y8KWQU8u25nd6xYPCOpq2Q.png" /><figcaption><a href="https://www.interviewbit.com/blog/mvc-architecture/">https://www.interviewbit.com/blog/mvc-architecture/</a></figcaption></figure><ul><li><strong>Models</strong> are the basic building blocks of your database. So for every entry in your DB , you’ll create a model that holds the details of that entry. Models define the types of information that get used by your views and controllers. (<em>Mongoose</em>)</li><li><strong>Views </strong>are the component that generates the UI for your application. It uses data supplied by a controller, plug that data in html with the help of a<em> templating engine</em> and display the desired information.(<em>EJS or React-engine</em>).</li><li><strong>Controllers </strong>are the components that decide what view to display and what information is going to be put into it. It’s where the main logic of your server resides.</li></ul><h3>7. CORS</h3><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy">Same Origin Policy</a> is an important security measure that basically says “Only requests from the same origin (the same IP address or URL) should be allowed to access this API”.</p><p>But, we are specifically trying to set up our API so that we can access it from different origins, so to enable that we need to set up Cross-origin resource sharing, or<strong> CORS.</strong></p><p>Setting up CORS is very easy by using a npm library of the same name.</p><pre>//Simple Usage (Enable All CORS Requests)<br>var cors = require(&#39;cors&#39;)<br>var app = express()<br><br>app.use(cors())<br><br>app.get(&#39;/products/:id&#39;, function (req, res, next) {<br>  res.json({msg: &#39;This is CORS-enabled for all origins!&#39;})<br>})</pre><h3>8. Frameworks</h3><p>A framework is just boilerplate code bundled in an organised way. A obvious advantage of using a framework is that you don’t have to repeatedly write the same code. Another is that it gives you the organisation of files from the start according to MVC principles. Some good examples are —</p><ul><li><em>Express</em></li><li><em>Django,</em></li><li><em>Ember</em></li><li><em>Rails</em> and many more.</li></ul><p>Using frameworks can reduce the verbose, provide necessary abstraction and speed up your development .</p><blockquote>Check out the ‘<a href="https://medium.com/@atishayjn999/the-backend-development-primer-part-2-2-7f9f19fbc1d0">Part 2</a>&#39; of this primer to know about how to scale and optimise your application and other cool stuff.</blockquote><h3>References :</h3><ul><li><a href="https://www.codecademy.com/article/back-end-architecture">https://www.codecademy.com/article/back-end-architecture</a></li><li><a href="https://www.codecademy.com/article/http-requests">https://www.codecademy.com/article/http-requests</a></li><li><a href="https://www.codecademy.com/article/what-is-rest">https://www.codecademy.com/article/what-is-rest</a></li><li><a href="https://www.theodinproject.com/lessons/nodejs-express-102-crud-and-mvc">https://www.theodinproject.com/lessons/nodejs-express-102-crud-and-mvc</a></li><li><a href="https://www.theodinproject.com/lessons/nodejs-api-basics">https://www.theodinproject.com/lessons/nodejs-api-basics</a></li><li><a href="https://expressjs.com/en/resources/middleware/cors.html">https://expressjs.com/en/resources/middleware/cors.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43a115dde891" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>