<?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 Sushil Tripathi on Medium]]></title>
        <description><![CDATA[Stories by Sushil Tripathi on Medium]]></description>
        <link>https://medium.com/@sushiltripathi?source=rss-19602ccf2304------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Sushil Tripathi on Medium</title>
            <link>https://medium.com/@sushiltripathi?source=rss-19602ccf2304------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:15:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sushiltripathi/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[Why data structure and Algorithms are important?]]></title>
            <link>https://medium.com/@sushiltripathi/why-data-structure-and-algorithms-are-important-91f46809a4a4?source=rss-19602ccf2304------2</link>
            <guid isPermaLink="false">https://medium.com/p/91f46809a4a4</guid>
            <category><![CDATA[why-data-structures]]></category>
            <category><![CDATA[queuing-system]]></category>
            <dc:creator><![CDATA[Sushil Tripathi]]></dc:creator>
            <pubDate>Fri, 01 May 2020 08:33:20 GMT</pubDate>
            <atom:updated>2020-05-01T08:33:20.894Z</atom:updated>
            <content:encoded><![CDATA[<p>We all start with data structures and algorithm at our college. We learn to implement stacks, queues, linked lists, trees and what not. Our placement is mainly dependent on our in-depth knowledge about data structures and algorithm, but when we enter our work life we don’t get to implement any of such data structures. This can be really demotivating at times especially when we have spent years to learn things that we cannot apply at our day to day work.</p><h3><strong>Why is this the case?</strong></h3><p>Data structures and Algorithm are building blocks of any software stack. More often than not these are the first things that are implemented when we start working on any product/service. So unless you are one of the early engineers in product development it is very unlikely that you would get to implement any Data structures and Algorithm.</p><p>Even if we end up being at early stage of product development it is not necessary that we might get to implement any such data structures because all major languages used for development these days come with very rich set of library which solves our day to day requirement of Data structures and Algorithm. Moreover these are tested by millions of developers out there and less likely to have a bug so more reliable than we trying to implement them ourselves.</p><h3><strong>Why learn Data structures and algorithm?</strong></h3><p>I will try to cite some professional experiences where knowledge of data structure helped solve a problem.</p><p><strong>Problem 1</strong></p><p>We are creating a website which help users sell items somewhat similar to OLX, Quickr. Now since most of users are on mobile we want to be able to onboard a user using mobile numbers and communicate any update to the products they are selling via SMS. As of now there are two kinds of SMS’s one for OTP when users sign’s up and other when there is any update on ads he posted.</p><p>It is evident that we need a SMS gateway to be able to send SMS. We get subscription from some SMS gateway service providers. They give us a API which takes mobile number and SMS text as json input like show below</p><blockquote>{</blockquote><blockquote>“Phone”: “999999999”</blockquote><blockquote>“text”: “Hello World”</blockquote><blockquote>}</blockquote><p>This is easy we just need to call the API and send OTP to the user when he onboards and again call the same API when we need to send any updates on his/her ads.</p><p>But wait there is a problem here the subscription we have for SMS allows 10 concurrent requests only at a time (this is generally the case with any subscription we have will have some upper limit you can change 10 to 20 or to 50 but we will have a higher limit). So at a given time if we have 50 users onboarding and we make 50 requests to our SMS api most of them are going to fail as we are exceeding our threshold of 10.</p><p><strong><em>So how do we solve this problem?</em></strong></p><p>Most of us would already have guessed it. We need to queue those SMS requests and send only 10 at a time and only after we get a response to any of these 10 requests we pick the other from queue, this will make sure we never cross our threshold. I agree that we are not going implement the queue ourselves here because there are already lot of tried and tested queueing system out there(RabbitMQ is one such queue) and we are just going to integrate them to our system.</p><p>Now I want to ask a question, why did we choose queue in this case and why not stack or tree for that matter?</p><p>It is because you know how queue works and its unique property of First In First out(FIFO). We know if we push the SMS contents to the queue it will end up being at end of queue but when we fetch we are fetching it from front of queue. We can easily comprehend this fact because we have studied/practiced queue data structures well enough to know how it works.</p><p><strong>Problem 2</strong></p><p>While the queueing system described in Problem 1 worked great for few months it is slowing down. Now we see that delivery of OTP is delayed to onboarding users as a result users are dropping off and not completing the onboarding process. This is a serious problem as it is going to hamper the business.</p><p>Since we implemented this queueing system we are supposed to debug the cause for this delay. Upon debugging we realized that we are having lot of ads about selling items and there are frequent updates to the ads as a result we have many SMS’s in the queue related ads updates and since FIFO is the property of queue. OTP SMS are at the end will only be processed once all the SMS before it is processed.</p><p>Now the queue property which helped us in problem 1 is causing problems here.</p><p><strong><em>How do we solve it then?</em></strong></p><p>I have two solutions to this. Lets try to go through them one by one.</p><ol><li>We can separate queues for OTP and ads posts and we should process OTP queue first and only after it is empty we start processing SMS related to ads. This will work for now but lets say tomorrow we want add comments service through SMS, then we will have to add a new queue based on the priority of comments. So when management wants to add new SMS feature it will end up having developers to work as well. As they have to create queues and possibly change code to read from the queue in a given order. This is not a scalable approach because we will end of adding queues for every SMS types and we have dependency on developer.</li><li>We can implement a priority queue where each type of SMS have a given priority and whenever we pop from the queue we get SMS with highest priority. This is a pretty scalable solution as we don’t have to add queues for each message type and whenever management wants to introduce new type of message all they have to do is assign priority to their SMS and it will work.</li></ol><p><strong><em>I will repeat again what I said for problem 1</em></strong>. How did we come up with a priority queue based solutions? If we hadn’t studied/practiced priority queue’s we wouldn’t know of this solution. We can come up with this solution because we have used priority queues to solve similar problems in our practice.</p><p>Note: <em>There are better and more advanced way to solve this problem, but motive of this post is not to solve this queueing problem.</em></p><p>I will end up by giving a problem to think of and also analyze why did we chose the Data structures and Algorithm we will end up choosing and how the practice that we have done has helped in choosing it.</p><p>We have a website for the same product selling system we discussed above. Now you need to show a notification to the user whenever there is a comment to ads. Note that the notification should be in same order of time as it was posted at users end i.e. one posted before should show up first. Also note that time is the time at which it was posted at users end not the time you received. So if we have two comments (say 1 &amp; 2 where 1 was posted first and 2 was posted second) you receive a comment 2 first and then comment 1 because of some network weirdness now 1 should appear before 2 in UI. What kind of data structures will you use to represent this data in UI and what algorithm will you use to keep it in order.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91f46809a4a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Nodejs for Heroku]]></title>
            <link>https://medium.com/@sushiltripathi/creating-nodejs-for-heroku-5ddc066b1dc2?source=rss-19602ccf2304------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ddc066b1dc2</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[herokuapp]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Sushil Tripathi]]></dc:creator>
            <pubDate>Fri, 17 Apr 2020 14:26:03 GMT</pubDate>
            <atom:updated>2020-04-18T09:52:58.131Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploying Nodejs &amp; Postgres app to Heroku.</h3><p>In this blog post we will host a Nodejs app which talks to Postgres database and we will host it on <a href="https://www.heroku.com/">Heroku</a>. This tutorial assumes that you have already created a Nodejs app and are ready to deploy it to Heroku. In case you don’t know how to create a Node app refer Creating a Nodejs app.</p><p>To host your app to Heroku make sure you have a Heroku free account. If you don’t have one go to <a href="https://signup.heroku.com/">Heroku Signup</a> and signup to Heroku. Once you have signed up login to Heroku after you have successfully logged in you will redirected to <a href="https://dashboard.heroku.com/apps">Heroku dashboard</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D0ydGJRTQVvuMRCR7I8-GA.png" /></figure><p>Creating a Heroku App</p><ol><li>Click on “New” on top-right corner and click “<strong>Create new app</strong>” from drop down.</li><li>Type the name of your app all in small case and click “<strong>Create app”</strong>.</li><li>You will be redirected to your app deployment page. Congratulation you have created a Heroku app.</li><li>Now that your app is created. We need to add a Postgres database to our app. To do that Go to “<strong>Resources” </strong>section of your app by clicking on “<strong>Resources” </strong>and then “<strong>Find more add-ons”.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qVokcThY9OA7u_I7kyOZEw.png" /><figcaption>Adding addons to Heroku</figcaption></figure><p>5. You will redirected to <a href="https://elements.heroku.com/addons">Heroku addons</a> page. Search for Postgres and click on Heroku Postgres in search results and then “<strong>Install Heroku Postgres” </strong>on the new page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y05mGrK38LO_JlgwBuTi3w.png" /><figcaption>Heroku Postgres addon</figcaption></figure><p>6. It will ask you the app to which Postgres instance has to associate itself to type the name of app you created in step 2 and then “<strong>Provision add-on”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*qw4o_T4cR8iJA44BY4Ou_Q.png" /></figure><p>7. After this Postgres instance will show up in your app’s resource section(image below). If this shows up then you have successfully added Postgres to your Heroku app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*v2PA_cP22CzX0NzI-XWOHA.png" /><figcaption>Postgres provisioned for Heroku app</figcaption></figure><p>8. Now we have successfully created a Heroku app and added a Postgres database to it. We now need to deploy our Nodejs app to this Heroku app we just now created.</p><p>9. Heroku cli should be installed on your system containing Nodejs app to be able to deploy this app to Heroku server. If it is not installed follow <a href="https://devcenter.heroku.com/articles/heroku-cli">this post to install Heroku cli</a>.</p><p>10. I am assuming that we are using NPM module <a href="https://www.npmjs.com/package/pg"><strong>pg</strong></a> to connect to database in our Nodejs app. To connect to Postgres instance on Heroku server pass “process.env.DATABASE_URL” to Client instance.</p><blockquote><strong>const</strong> { Client } = require(‘pg’);</blockquote><blockquote><strong>const</strong> client = new Client(process.env.DATABASE_URL);</blockquote><blockquote>client.connect();</blockquote><blockquote>Note: Complete code sample can be found in <a href="https://github.com/tripsus/reference_code/tree/master/NodeJs/postgres_sendgrid_heroku_integration">Github</a>.</blockquote><p>11. DATABASE_URL is environment variable set by Heroku cli when you deploy your app to Heroku server. This is the recommended way of setting database credentials as per Heroku docs.</p><p>12. Open terminal and navigate to your Nodejs app direcotry. In your Nodejs project type “<em>heroku git:remote -a &lt;app_name&gt;</em>”. <em>app_name</em> is the app you created in step 2. This will set the git origin for your repo to Heroku git url of your app.</p><p>12. Now type “<em>git push heroku master</em>” and this will deploy your app to Heroku server and the logs will be shown in the console.</p><p>13. To tail your app logs in terminal you can type “<em>heroku logs — tail — &lt;app_name&gt;</em>”. This will show you Nodejs application logs in your terminal.</p><p>Hope this helps you deploying your Nodejs apps to Heroku server. Incase you face any issue. Please feel free to reach out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ddc066b1dc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>