<?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 Vivek Kaushal on Medium]]></title>
        <description><![CDATA[Stories by Vivek Kaushal on Medium]]></description>
        <link>https://medium.com/@vivek-kaushal?source=rss-b19fb3940a81------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JmKkj4-xWgaS-m-Kcw00iA.jpeg</url>
            <title>Stories by Vivek Kaushal on Medium</title>
            <link>https://medium.com/@vivek-kaushal?source=rss-b19fb3940a81------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 19:29:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vivek-kaushal/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[Blocked on code reviews? Let’s fix the process.]]></title>
            <link>https://vivek-kaushal.medium.com/blocked-on-code-reviews-lets-fix-the-process-b8fbbe3241a2?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8fbbe3241a2</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[pull-request]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Sat, 18 Feb 2023 14:10:28 GMT</pubDate>
            <atom:updated>2023-02-18T14:10:28.551Z</atom:updated>
            <content:encoded><![CDATA[<p>As an engineer at a growing startup, you’re moving fast and trying not to break things. Getting your code reviewed can be painful. You often have a very lean team of exceptional engineers, but they’re building the future along with you, and code reviews end up falling on the sidelines.</p><p>We faced this problem. We fixed it. Here’s what we did.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LNXNo4aKfu9Pkf8e" /><figcaption>Photo by <a href="https://unsplash.com/@alvarordesign?utm_source=medium&amp;utm_medium=referral">Alvaro Reyes</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Where do I ask for a review?</h3><h4>Pain</h4><blockquote>“As an engineer, my threads on what I have to review, and what I have put in review are all over the place”</blockquote><p>We are a remote-first team that uses Slack for communication. Requests for code reviews are often put in personal chats with other engineers or posted on common project-focused // team-focused channels. This creates a situation where conversations on code reviews are distributed across multiple slack channels and personal messages, and keeping track of what’s in review is difficult for both the engineer reviewing a pull request and for the engineer who’s blocked on a review to merge their changes.</p><h4>Solution</h4><p>We created a channel #backend-code-reviews on Slack. All requests for code reviews in the backend team are posted on this channel. The thread of any message is used for discussions on the changes.</p><h3>Who should review my code?</h3><h4>Pain</h4><blockquote>“As an engineer, I don’t always have a clear answer to ‘who should review my code?’ in such situations, who do I request?”</blockquote><p>This is a rare pain. In most situations, there is a clear code owner or project lead that can help with code reviews. But occasionally, you might make changes where pointing to someone as a default for code reviews is challenging.</p><h4>Solution</h4><p>We follow a policy of <em>“use your best judgment”,</em> empowered by GitHub’s reviewer suggestions — generated on the basis of file authors and modules’ owners. If there are no options (&lt;5% cases), fall back to the on-call engineer.</p><h3>How urgent is the code review?</h3><h4>Pain</h4><blockquote>“As a reviewer, I don’t know the priority of code that I need to review without having a discussion on its context. I often do not have time to discuss this context, and I end up incorrectly prioritizing what I need to review.”</blockquote><p>As a reviewer, unless I am closely involved with the project or I take out the time to getcontext from the person who needs the review, I often do not know how urgent a pull request is. This urgency can range from — “needs to be deployed immediately” to “can wait for weeks, it’s an optional improvement”.</p><h4>Solution</h4><p>We follow a process of denoting this priority by colors. We use four colors:</p><p>🔴 : Code needs to be deployed immediately.<br>🟠 : Code needs to be deployed withing 24 hours.<br>🟡 : Code needs to be deployed withing the next 5 days.<br>🟢 : The required deployment timeline is longer than 5 days.</p><h3>The end result</h3><p>Building on everything we covered, a post on #backend-code-reviews can look like this:</p><pre>@John Doe https://github.com/org/repo/&lt;pull-request&gt; 🟠<br>Adding an implementation to the report generator factory [one line description]<br>------<br>GitHub&#39;s Slack unfurl, which has comments and other information <br>on the pull request&#39;s context.<br>------<br>--&gt; threads --&gt; discussion on the pull request // reminders if required</pre><p>This simple approach has reduced our code review timelines significantly. Let me know what you think!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8fbbe3241a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What really is Golang’s context?]]></title>
            <link>https://vivek-kaushal.medium.com/what-really-is-golangs-context-b51874809f0f?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/b51874809f0f</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[golang-development]]></category>
            <category><![CDATA[golang-tutorial]]></category>
            <category><![CDATA[golang-tools]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Sun, 26 Jun 2022 12:49:06 GMT</pubDate>
            <atom:updated>2022-06-26T13:07:46.378Z</atom:updated>
            <content:encoded><![CDATA[<p>Google’s guidelines on Go specify that the first argument of a function in GoLang should be Go’s context.Context type. While the usage of context is fairly ubiquitous, I feel that most developers (including me) black-box the context argument in GoLang while starting out with development, and lack clarity about its usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*VamrqX0eIU-EmrLlXz2r_w.jpeg" /></figure><h3>What is context?</h3><p>context is a request-scoped variable that makes it easy to pass along request-specific values, environment, deadlines and cancellation signals as arguments to functions, without relying on parameters.</p><p>In GoLang, context is available through the <a href="https://pkg.go.dev/context">context package</a>. You may have come across context while reading Golang code, eg:</p><pre>import (<br>    &quot;context&quot;<br>)</pre><pre>func doSomething (<strong>ctx context.Context</strong>, param1 string) error {<br>  // this function does something<br>  return nil<br>}</pre><h3>What does it hold?</h3><p>context holds information about the request which triggered the current goroutine. This information may comprise of:</p><ul><li><strong>cancellation signals : </strong>cancellation signals about the request, populated by the parent where the goroutine to process the request is spawned and consumed by any function invoked to do the processing.</li><li><strong>response deadlines : </strong>the cutoff of response time for the request, beyond which an error is returned.</li><li><strong>request-scoped variables</strong> :variables shared across the scope of a request’s processing which may be helpful for the underlying functions.</li></ul><p>The interface for the context package’s Context type :</p><pre>type Context interface {<br>    // Done returns a channel that is closed when this Context is canceled<br>    // or times out.<br>    Done() &lt;-chan struct{}<br><br>    // Err indicates why this context was canceled, after the Done channel<br>    // is closed.<br>    Err() error<br><br>    // Deadline returns the time when this Context will be canceled, if any.<br>    Deadline() (deadline time.Time, ok bool)<br><br>    // Value returns the value associated with key or nil if none.<br>    Value(key interface{}) interface{}<br>}</pre><h3>How is it useful?</h3><p>In a nutshell, context helps make your code efficient in the following ways:</p><h4>When the Request is Cancelled</h4><p>You can leverage the context to check if the request has been cancelled. If yes, we can avoid the computational effort of following through with function execution, and the function can return early. A request may be cancelled for various reasons, including a cancellation from the parent or a concurrent error.</p><h4>When the Deadline is Too Strict</h4><p>If the deadline of a context if populated, functions can leverage it to understand if continuing with the execution is a smart idea. For example, suppose a function is responsible for writing to disc, and the operation takes 100ms, and the request is scheduled to timeout in 10ms. In that case, it makes more sense to return with an error early and save the computation resource and disc write bandwidth.</p><p>This excellent<a href="https://go.dev/blog/context"> 2014 blog</a> from Sameer Ajmani explains how context can be used to make your application more efficient.</p><h3>The Case Against Context</h3><p>An argument can be made that populating values in context with context.WithValue and reading them in child functions with context.Value(key) skirts the interface exposed by child functions. Though I would weigh in here with my opinion that this is an incorrect usage of context . Be careful with your choice values in context , variables with request-wide-scope should be a strict criterion.</p><p>That’s it! I hope you got some clarity into what happens inside context and how powerful it can be when used to it’s full potential. If you’d like to further discuss this, feel free to reach out! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b51874809f0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Talking About Clickbait at CogSci ’22]]></title>
            <link>https://vivek-kaushal.medium.com/talking-about-clickbait-at-cogsci-22-b4236e65347f?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4236e65347f</guid>
            <category><![CDATA[eyetracker]]></category>
            <category><![CDATA[clickbait]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[hci]]></category>
            <category><![CDATA[cognitive-science]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Sun, 29 May 2022 08:20:57 GMT</pubDate>
            <atom:updated>2022-05-29T08:20:57.352Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lB_OeQVIHlfHMHt1" /><figcaption>Photo by <a href="https://unsplash.com/@iamromankraft?utm_source=medium&amp;utm_medium=referral">Roman Kraft</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When I joined the Cognitive Sciences Lab at IIIT Hyderabad in early 2017, the north star of publication was the <a href="https://cognitivesciencesociety.org/cogsci-2022/">Annual Meeting of the Cognitive Sciences Society</a>. Today, I am happy to share with all of you, that our work on the impact of clickbait on readers’ visual attention has been accepted in CogSci’22.</p><h3>TLDR</h3><p>Building on our <a href="https://ieeexplore.ieee.org/document/9405359/">earlier work</a> on clickbait’s negative impact on news’ credibility, we wanted to explore clickbait’s impact on readers’ attention. Our primary motivation was to understand — <em>Do clickbait headlines create a significant difference in how readers read an article and what information they pay attention to?</em></p><p>Using an eye-tracker setup based experiment on 60 participants, we showed that the answer is — yes. Readers pay lesser attention to an article if it has a clickbait headline, their attention is mostly focussed on finding the “answer” to the question the clickbait headline raises, and readers’ attention diminishes beyond that.</p><p>I’ll share a link to paper once the conference proceedings are published.</p><h3>Impact</h3><p>Our work questions the prevalence of clickbait headlines, and raises doubts around news organisations’ motivation to use clickbait. Over the course of the last few years, our research has raised the following points:</p><ol><li>Clickbait headlines have a negative impact on the credibility of the information being consumed.</li><li>Clickbait headlines have a negative impact on readers’ visual attention on the news article.</li><li>Clickbait is a phenomenon that is language-agnostic. Mainstream Hindi news headlines have comparable clickbait penetration to English news. Although alarmingly, clickbait prevention and detection techniques for non-English languages are lagging far behind measures available for English.</li></ol><p>We hope to start a meaningful discussion on the usage of clickbait headlines, it’s pitfalls and the journalistic responsibility of news organisations to provide credible information to readers.</p><h3>In the News</h3><p>Our work was also featured in a Hindu Business article recently. Ironically, they used a clickbait headline.</p><p><a href="https://www.thehindubusinessline.com/info-tech/bad-news-for-websites-that-rely-on-clickbait-headlines/article65391707.ece">Why clickbait headlines do not &#39;catch&#39; the readers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4236e65347f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Google Sheets as a Source of Dynamic Data for your Static Website]]></title>
            <link>https://vivek-kaushal.medium.com/using-google-sheets-as-a-source-of-dynamic-data-for-your-static-website-d88577ec98db?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/d88577ec98db</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[website-development]]></category>
            <category><![CDATA[google-sheets]]></category>
            <category><![CDATA[static-websites]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Sat, 25 Dec 2021 15:21:21 GMT</pubDate>
            <atom:updated>2021-12-25T15:26:08.523Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sYYp0bY3VdMygUpSop9XSw.png" /></figure><p>Static websites are fantastic. You can host them for free, and they are a great segue into full-stack web development. Though when you’re building a static website, the absence of a DB is a hard constraint. What this means is that any information that you display on your site can have two sources:</p><ol><li>You can embed it in the website’s code itself</li><li>You can host it somewhere else and fetch it from a URL</li></ol><p>A common roadblock in this approach is data that is frequently updated. For example — a list of projects on your portfolio; or a list of members for an organization’s website. Typically, we embed this data in the website itself, and each update requires a re-deployment. Ideally, we want an easy-to-edit data source that a static website could fetch.</p><p>There is one. Google Sheets. And it’s trivially easy to get started.</p><h3>Create an API Key</h3><p>You’ll need to provide a way for your static website to get data from a Google Sheet. We’ll do this through a Google Cloud project. As a first step, <a href="https://support.google.com/googleapi/answer/6158862?hl=en">create an API key</a> with access to Google Sheets.</p><h3>Fetching Data</h3><p>Google Sheets throws the contents of a worksheet within a sheet as JSON at this URL:</p><pre>https://sheets.googleapis.com/v4/spreadsheets/&lt;sheet_id&gt;/values/&lt;worksheet_name&gt;/?key=&lt;api_key&gt;</pre><ul><li>sheet_id : You can extract this from the URL of your Google Sheet.</li></ul><pre>https://docs.google.com/spreadsheets/d/&lt;sheet_id&gt;/edit#gid=0</pre><ul><li>worksheet_name : It’s the name of the worksheet inside your Google Sheet that you want to fetch. Note that this method can only fetch one worksheet from a Google Sheet at a time. The default is Sheet1</li><li>api_key : We created this in the previous step. Extract it from the Google Cloud project.</li></ul><p>You can use this snippet :</p><pre>const sheetLink = &quot;https://sheets.googleapis.com/v4/spreadsheets/&lt;sheet_id&gt;/values/&lt;worksheet_name&gt;/?key=&lt;api_key&gt;&quot;</pre><pre>const data = await  fetch(sheetLink)<br>.then((<em>response</em>)=&gt; {return <em>response</em>.json()});</pre><p>A JSON like the given sample is returned when you fetch a sheet. You can iterate over the values field to populate data on your website.</p><pre>{<br>  &quot;range&quot;: &quot;Sheet1!A1:Y999&quot;,<br>  &quot;majorDimension&quot;: &quot;ROWS&quot;,<br>  &quot;values&quot;: [<br>          [<br>           &quot;value in row1, col1&quot;,<br>           &quot;value in row1,col2&quot;<br>          ],<br>          [<br>           &quot;value in row2, col1&quot;<br>          ]<br>  ]<br>}</pre><p>And that’s it! Any changes you make to the sheet will reflect instantly on your website. Now you can add/edit content on your static website from any device that can access Google Sheets — including your phone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d88577ec98db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generating Recommendations in a Real World Job Market]]></title>
            <link>https://vivek-kaushal.medium.com/generating-recommendations-in-a-real-world-job-market-f6f93f58d3d8?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6f93f58d3d8</guid>
            <category><![CDATA[hiring]]></category>
            <category><![CDATA[recommendation-system]]></category>
            <category><![CDATA[system-design-project]]></category>
            <category><![CDATA[software-engineer]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Mon, 04 Oct 2021 07:42:52 GMT</pubDate>
            <atom:updated>2021-10-04T07:43:45.541Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6JRXDmR5KT3z6nzv" /><figcaption>Photo by <a href="https://unsplash.com/@clemono?utm_source=medium&amp;utm_medium=referral">Clem Onojeghuo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When you’re a job board catering to employers and job-seekers, the recommendations you generate on both ends become critical differentiators for your product. An employer wants the best candidates for job posts, and candidates want the most relevant jobs, where they have a great shot of selection. This blog is an outline of a solution for such real life scenarios, even with limited data. The target is to build a scalable recommendation system, which evolves as the volume of available data grows and is capable of flexibly adapting to changes and additions.</p><h3>Available Data</h3><p>For job posts by employers, let’s assume that we have the following data available:</p><ul><li>The category and sub-category of the job post (e.g., Driver-&gt;Limo Driver)</li><li>Title, description and other metadata for the job post</li><li>Other quantified criteria (years of experience, salary, visa status etc.)</li><li>Employer’s record — number of hires, number of shortlists, types of candidates hired, etc.</li></ul><p>While for every candidate, we have the following data on hand:</p><ul><li>Candidate profile (including years of experience, visa status, etc.)</li><li>Skillset (category and sub-category of skillset selected)</li><li>Candidate’s qualifications (licenses held, educational qualifications)</li><li>Resume (PDF/image/DOC)</li><li>Platform interactions (jobs applied to, jobs shortlisted for, etc.)</li></ul><h3>Levels of Matching</h3><p>“The best way to use machine learning is not to use it at all.” Heuristics and rule-based matching often generate much better results, especially when data is scarce, not taking anything away from the ground-breaking solutions that clever ML usage can create when conditions are suitable. This approach has been penned down with an open mind.</p><p>The first step is to isolate the different levels for predicting matches. This can be better understood as:</p><ol><li>Hard qualifications (Qualifications that a candidate <em>must</em> have)</li><li>Soft qualifications (Qualifications that a candidate should <em>ideally</em> have)</li><li>Passive attributes (Data collected passively from candidate interactions)</li></ol><p>Let’s understand this better through an example. Suppose a Limo hire agency based out of Delhi is looking for drivers with 3–5 years of experience, who are willing to work on weekends on some suggested pay range. The agency does not sponsor visas, so candidates must already have the required work permits.</p><p>In this scenario, our hard qualifications would be — relevant driving license, and visa. Candidates that do not meet these requirements will not be considered.</p><p>A soft qualification in this scenario would be — candidate’s chosen skillset. If they have created their profile as a “Limo Driver,” they’ll be ranked higher. Failing which, they’d be ranked lower but not omitted from recommendations. Another example is the distance from the agency’s offices/work location. A candidate closer to the work location will be more relevant for the job than someone based in a different city.</p><p>An example of a passive attribute here is the number of limo driver jobs that a candidate has been shortlisted for earlier. This data isn’t directly collected from candidates but can be used to generate better recommendations. A candidate that gets shortlisted more often for a job profile is likely to be a better candidate for it.</p><h3>Hard Qualifications</h3><p>Hard qualifications are easy to implement. A Boolean expression filter on your database will do the job. For example, if the requirement is for a medical support staff at a local clinic, having the relevant training and certification is a must. Only candidates who have uploaded proof of the required certification need to be considered.</p><p>A challenge here is the verification of the authenticity of such documents. A machine learning based approach can be a life savior, e.g., a multi-class classification model trained on a large labelled dataset of official certification can come in handy. Such a system can be augmented by manual verifiers who weigh in to handle edge cases. This will only grow more robust and accurate with time.</p><h3>Soft Qualifications</h3><h4>For Quantifiable Attributes</h4><p>Implementing soft qualifications for quantifiable attributes is relatively simple. It needs a set of variables to match— with defined desired quantities, and a set of ranges from which matches need to be sorted. For example, a set of variables can be — salary, distance, and years of experience. Each with a set target (Rs.15000/- per month for salary, 0 km for distance and 5 years as experience). Then profiles can be sorted using a weighted combination of these parameters, e.g., 10% preference to salary match, 60% to distance match, 30% to experience. The weights will be multiplied with a closeness measure (e.g., absolute difference, etc.) and added to generate the final score. Candidates that have the highest final score after this weighted match will rank highest.</p><p>The interesting bit here is that the weights themselves can be adaptable. Let’s say, if a specific employer values experience more than anything else, and is willing to pay for relocation, then the weights can be automatically tweaked— provided that this information is captured through employer-facing forms or other interactions.</p><p>More so, the weights can also be passively machine learnt over-time form the hiring and shortlisting behavior of an employer and auto-updated. If an employer frequently hires candidates that have very different expected salaries than the job post, maybe the employer is flexible on salaries and it shouldn’t be a major contributing factor for their recommendations.</p><h4>For Non-Quantifiable Attributes</h4><p>Matching soft qualifications for non-quantifiable attributes is somewhat trickier. Understanding how a “Cab Driver” is more relevant than a “Garbage Truck Driver” for our “Limo Driver” profile is not that straightforward, when they both have the required license. This is intuitive for humans, as we understand that being a cab driver entails many of the same tasks that being a Limo driver will entail. To transfer this understanding to an automated system, there are two smart approaches:</p><ol><li>Semantic Matching</li><li>Manual Categorization</li></ol><p>Its important to understand that the specific problem we are trying to solve here, is breaking down an abstract human understanding into structured comparisons that can be automated. This, in general, is a good heuristic for identifying good machine learning problems.</p><p>Semantic matching implies finding words that have similar meanings. E.g., “Chef” and “Cook” will have a high semantic match. You can find more details on how to implement a basic sematic matching algorithm <a href="https://towardsdatascience.com/deep-learning-for-semantic-text-matching-d4df6c2cf4c5">here</a>.</p><p>While semantic matching is useful, it’s also a good idea to seed your matches with some inherent knowledge that you possess. For example, you can imagine a graph with different job categories linked to each other through weighted edges, where you’ve seeded the weights with your own understanding of how closely a job category related to another. This creates a nice base upon which other algorithms can evolve. Though it’s clearly a tedious process, and not essential, if you don’t have a such a categorization on hand.</p><h3>Richness Through Passive Data</h3><p>Now that we’ve dealt with hard and soft qualifications, we have a skeletal recommendation system which would work just fine. But to add some spark to it, we can tap into the vast volumes of data that you’ll be collecting as a job board so that you’re recommendation system evolves over time, getting smarter with each new interaction that happens on your platform. In this section, we’ll explore some avenues where passive data can add richness to recommendations.</p><h4>Non-Quantifiable Soft Attribute Match using History</h4><p>A great way of understanding how abstract non-quantifiable terms are related to each other is to evaluate their relationship using the interaction data collected from platform users. For example, if a lot of Cab Drivers are frequently shortlisted for Limo Driver profiles, then there is a high probability that the two profiles are closely related. Relations derived from such interactions can enrich recommendations over time and make them more dynamic.</p><h4>Candidate Facing Recommendations</h4><p>What’s an ideal job to show to a candidate? There are two answers to this questions.</p><ol><li>Jobs that the candidate would like to see and apply to</li><li>Jobs that the candidate has the best shot of being shortlisted and selected for</li></ol><p>Now its likely that these two sets have a strong intersection, but that’s not a necessity. I believe that the best approach is a weighted combination of these two goals. I ran a Twitter poll for this, which is attached below. In either case, the relation can be learnt based on interaction data accumulated from other similar candidates and their application/selection history. Similar candidates are likely to get selected for similar jobs.</p><h3>Vivek Kaushal 🚀 on Twitter: &quot;You&#39;re creating a job board app. Which jobs will you recommend to candidates?A. Jobs they&#39;ll like to apply toB. Jobs they have the best chance of being selected for / Twitter&quot;</h3><p>You&#39;re creating a job board app. Which jobs will you recommend to candidates?A. Jobs they&#39;ll like to apply toB. Jobs they have the best chance of being selected for</p><p>This post is a rough approach for creating a recommendation system for a job-board in non-ideal real-world conditions. Parts of this post have been developed into real systems that are currently deployed and serving thousands of users daily. But this post is more of a superset of the approach I’ve deployed earlier, and paints what a more complete system should look like. Feel free to reach out for help. :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6f93f58d3d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ultimate Rust Crash Course — Short Notes]]></title>
            <link>https://vivek-kaushal.medium.com/ultimate-rust-crash-course-short-notes-cbd85dccb873?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbd85dccb873</guid>
            <category><![CDATA[course]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[rust-programming-language]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Mon, 16 Aug 2021 06:52:19 GMT</pubDate>
            <atom:updated>2021-08-16T06:52:19.542Z</atom:updated>
            <content:encoded><![CDATA[<h3>Ultimate Rust Crash Course — Short Notes</h3><p><em>This post is a compilation of short notes from the </em><a href="https://www.udemy.com/course/ultimate-rust-crash-course/"><em>Ultimate Rust Crash Course</em></a><em> available on Udemy. Taught by Nathan Stocks, the course is pretty exhaustive considering that it’s only 3 hours of teaching material. I’ll recommend it to anyone who wants to get started in Rust quickly.</em></p><h3>Introduction and Quick Start</h3><ul><li>Rust ensures memory safety <em>(unlike C/C++)</em>, concurrency and speed.</li><li>Rust has a package manager named cargo. It is also the build system, doc generator and testing tool.</li><li>Variables are by default immutable.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*x3UzezlJtVA4q0M8QlFTVA.png" /></figure><ul><li>Functions defined using fn keyword. Don’t need to be chronologically arranged. Macros are special functions that end with an ‘!’.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*aVIwLnDcem5JMkAw7cgzjg.png" /></figure><ul><li>All functions are private by default. Add pub before fn to make a function public and available to external code files.</li><li>Quick start hello world app:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*pZ9PX2-mNFeB28b3T0Y6uQ.png" /></figure><h3>Basics and Datatypes</h3><h4>Modules and Library</h4><ul><li>main.rs and lib.rs are special files in root of the project. While main→ fn main() {} is the starting point of code execution, public functions in the lib file are available by default in the project as imports.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*6imbKgOKxPrcs7Urkn4Ygg.png" /></figure><ul><li>Standard library : std:: -- requirement --</li></ul><h4>Scalar Types</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*HKiq0RPhcCmuyF8aWDVzKA.png" /></figure><ul><li>Digits can be separated by any number of ‘_’ underscores, which are ignored in parsing. This is to enhance the readability. 10000 = 10_000</li><li>Strings are UTF-8, characters are not — hence, strings do not use characters. Hence, characters are fairly useless.</li></ul><h4>Compound Types</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*aaM4oGmSOls0x4gg6Fo8Aw.png" /></figure><ul><li>Tuples are not accessed with square brackets, as in other languages to emphasize that they need not be of the same data type.</li><li>Maximum size of a tuple is 12 — above this tuples have limited functionality.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*gua0w2svEYNeRjAOZIqHJA.png" /></figure><ul><li>Arrays are limited to 32 elements in size. Beyond this they lose functionality.</li></ul><h4>String</h4><ul><li>There are 6 types of strings in Rust. 2 are commonly used.</li><li>str is called a string slice. Commonly used as &amp;str — borrowed string slice.</li><li>A literal is always a borrowed string slice.</li><li>String is another type of string — this can be modified, unlike str.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*c1k1r20lwuJGi9tHmmwSzQ.png" /></figure><ul><li>internally, str is made up of a pointer and length. String is made up of a pointer, length and capacity.</li><li>Both str and String are valid UTF-8.</li><li><strong>Strings can’t be referenced by position.</strong> This is to accommodate non-English languages, and to ensure constant speed of access for non-English graphemes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*krp1MWjyZTO8nvMd_6WWng.png" /></figure><h3>Control Flow</h3><pre>// IF ELSE  </pre><pre>let x = if y == 5 {&quot;five&quot;} else if y == 4 {&quot;four&quot;} else {&quot;other&quot;}; </pre><pre>// if else can be used like the ternary operator in Rust, using the shortcur block function</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*XdmShRFK-sdhzxl7w_lt5w.png" /></figure><ul><li>loops have to be named starting with a single apostrophe. Eg. &#39;this</li><li>when for loops are written with 2 dots : 1..100 — start is inclusive, end is exclusive, when written with 2 dots and an equal size : 1..=100 — start and end are both inclusive</li></ul><h3>Ownership, References and Borrowing</h3><h4>Ownership</h4><ul><li>Each value has an owner</li><li>There is only one owner for a value — <em>stack to heap pointer allows only one reference</em></li><li>Value gets dropped if owner is out of scope 2</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*YBoBSqxHaXH9k7sEXpQTww.png" /></figure><ul><li>the term copy is used when only stack data is being copied. When both stack and heap data are copied the term clone is used. Clone is a deep copy. No leaks or dangling pointers are possible in rust.</li></ul><h4>References and Borrowing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*14_BFPwzIevQSKjjAOIXLw.png" /></figure><ul><li>reference default to immutable, even if values being referenced are mutable. To pass a mutable reference to a mutable value, use &amp;mut variable.</li><li>the ‘.’ method on a reference automatically dereferences down to the actual value. You don’t have to worry if a variable is a reference or a value.</li><li>You can either have <strong><em>one mutable reference</em></strong>, or <strong><em>any number of immutable references</em></strong> to a variable.</li></ul><h3>Deeper Concepts</h3><h4>Structs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*KbvbeH0XgiIwKXw3NQYJHA.png" /></figure><ul><li>all values of a struct need to be instantiated for struct declaration.</li><li>Rust doesn’t have Struct inheritance.</li></ul><h4>Traits</h4><ul><li>Similar to interfaces in other languages.</li><li>Traits define required behavior. <em>Functions and methods that a struct must implement to have the trait.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/1*aDi2IH2dGMlqDEPGmmzHXQ.png" /></figure><ul><li>The behavior implemented here by the trait could have directly been an associated function for the Sample trait. But we use traits because when a trait is defined, we can write generic functions which accept any value that implements the trait.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*EETM-eR0KteVIVH2-UbZkg.png" /></figure><ul><li>Copy is a special trait. If a type implements Copy, it will be copied, instead of being moved, in move situations.</li><li>Simple types like integers, boolean and floats implement copy.</li><li>If a type uses Heap, it cannot implement Copy.</li><li>Traits can inherit from other traits.</li><li>Traits can have default behavior as well.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*XGeGIyuvqM5W2RPf4HGqmw.png" /></figure><ul><li>Fields can’t be defined as part of traits. Traits can only be methods. The work around is to define setter and getter methods.</li></ul><h4>Collections</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*rAJVa4el09LjXqXWjJ1NYA.png" /></figure><ul><li>if index is out of bounds in vector, rust throws an error, doesn’t return garbage values.</li><li>there are a ton of methods for vectors for sorting, searching, slicing etc.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*V6_a9E0a7OUT5sYQwrZiiA.png" /></figure><ul><li>other collections include vecDeque — similar to queue etc.</li></ul><h4>Enums</h4><ul><li>enums in Rust can comprise of complex items of different datatypes.</li><li>when matching enums, the match must be exhaustive.</li><li>a single underscore can be used to match default.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*XH3km1yKWT-Nsu1XpOI2dA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*2vH4cBhC9sSv7Q1LMzNwug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*HKAwGtGScSZ_Sel1cQBFFA.png" /></figure><h4>Closures</h4><ul><li>A closure is an anonymous function that can borrow or capture some data from the scope it is nested in.</li><li>Closure need not have any arguments or return values.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*3LwIMgGUnTYUIk905OXMOg.png" /></figure><ul><li>by default, closure borrows values, so their are restrictions on how you can use closures with threads, as the thread from which a closure is borrowing value might end before it is called from another thread. Hence, closure also allows us to move values.</li><li>To avoid the consumption of passed values to a closure, use references.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*k6JHbCJwWy8d_GeldAMnvg.png" /></figure><h4>Threads</h4><ul><li>Threading is portable in rust. Platform independent.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*Hr4gBGDE3eoIQ_jT_fzgNQ.png" /></figure><ul><li>Threading is heavy, for lighter work that just needs an asynchronous approach, use async await</li><li>Rust provides asynchronous channels for communications between threads, these can be declared and used as follows. Sourced from <a href="https://doc.rust-lang.org/rust-by-example/std_misc/channels.html">rust docs</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*SzDGr_PIXAmCPklQzZYUOg.png" /></figure><p>Feel free to reach out to me to discuss any doubts that you might have. You can reach me through my website — <a href="https://vivekkaushal.com/">vivekkaushal.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbd85dccb873" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Notification Service using AWS, Twilio, Docker and Node.js]]></title>
            <link>https://aws.plainenglish.io/creating-a-scalable-and-reliable-notification-service-using-aws-twilio-docker-and-nodejs-4ed863fa9e6?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ed863fa9e6</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[sqs]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Fri, 30 Jul 2021 12:22:05 GMT</pubDate>
            <atom:updated>2021-08-01T14:01:17.528Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to Create a Scalable, Reliable Notification Service using AWS, Twilio, Docker and Node.js</h4><p>Staying in touch with your users is paramount, especially as a startup. But the complexities of setting up a scalable notification service that can handle increasingly large volumes of automated notifications delivered on multiple platforms can be overwhelming. Facing this exact situation while working at <a href="https://skillbee.com/"><em>Skillbee</em></a>, I created a viable solution.</p><p>This blog post is to ensure that you do not have to start from scratch. You can find the code, with a quick-start README <a href="https://github.com/kaushalvivek/notification-microservice">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6z9X8KcU8rA9QiY8" /><figcaption>Photo by <a href="https://unsplash.com/@brett_jordan?utm_source=medium&amp;utm_medium=referral">Brett Jordan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Requirements</h3><p>Our system needed the following capabilities:</p><ul><li>Handle communication on email, SMS, WhatsApp and Android notification</li><li>Personalize notifications for the target user</li><li>Have in-built failure-tolerance and redundancy to ensure message delivery</li><li>Have priority channels to deliver urgent communication</li><li>Do all of this at scale — our required throughput was around a million notification a day, at the time</li></ul><p>I designed a micro-service based approach that had components which communicated with each other to get work done. The components were:</p><ol><li><strong>API Service: </strong>This service exposed REST endpoints which can be hit by our backend/admin-tools to trigger notifications</li><li><strong>Queueing Service: </strong>When a notification was triggered, the API service vetted the request and upon verification, sent this request to the queueing service for consumption and delivery</li><li><strong>Consumption Service: </strong>This service constantly listened to the queueing service and when a notification was found, it consumed the notification from the queue, and processed it based on metadata.</li><li><strong>Delivery Service: </strong>This was called by the consumption service and was responsible for the final delivery of the notification to the target users.</li></ol><h3>API Service</h3><p>The API service exposed different endpoints for all modes of notifications — that communicating services could hit with POST requests. The body of the POST request had information about the message and targets, while the endpoint being hit decided the mode of notification. Note that the body could contain multiple messages, and each message could have multiple targets.</p><p>For example, here’s a sample request body for an email notification sent to the endpoint <em>host:PORT/api/v1/notify/email. </em>Refer to the linked GitHub repository for more examples.</p><pre>{<br>    &quot;data&quot;:[<br>        {<br>            &quot;content&quot;:{<br>                &quot;subject&quot; : &quot;Sample Email&#39;s Subject&quot;,<br>                &quot;html&quot; : &quot;&lt;p&gt; Sample email&#39;s body&lt;/p&gt;&quot;<br>            },<br>            &quot;targets&quot;:[<br>                &quot;email1@foo.bar&quot;,<br>                &quot;email2@boo.bar&quot;<br>            ]<br>        }<br>         {<br>            &quot;content&quot;:{<br>                &quot;subject&quot; : &quot;Sample Email 2&#39;s Subject&quot;,<br>                &quot;html&quot; : &quot;&lt;p&gt; Sample email 2&#39;s body&lt;/p&gt;&quot;<br>            },<br>            &quot;targets&quot;:[<br>                &quot;email3@foo.bar&quot;<br>            ]<br>        }<br>    ]<br>}</pre><h3>Queueing Service</h3><p>I used Amazon’s Simple Queuing Service (SQS) as the queueing service for our notification system. SQS stored all vetted requests sent by the API service and exposed them for consumption. You can refer to my <a href="https://aws.plainenglish.io/setting-up-aws-sqs-for-queuing-and-consumption-from-nodejs-960042c04bd9"><strong>post</strong></a><strong> </strong>on setting up SQS for queueing and consumption from NodeJS to help setup SQS for your notification service. More information on this is also available in the quick start README of the shared repository.</p><h3>Consumption Service</h3><p>The consumption service continuously polled SQS queues and consumed messages . It then processed them based on their intended target and channel, tapping into delivery services. You can refer to the repository for the code and instructions on setting up the consumption service and connecting it to SQS. I wrote the consumption service in NodeJS and used the AWS-SQS SDK for polling and consumption of SQS queues.</p><h3>Delivery Service</h3><p>I used <em>Twilio</em> as the primary delivery service for SMS and WhatsApp communication. <em>SendGrid</em> — which is owned by Twilio as well — was used as the primary email delivery service. Phone notifications were delivered using Google’s Firebase service. Notably, there is no vendor locking in this notification service, and new delivery services can be easily plugged in/removed. Additionally, logic-based redundancies can also be built in, in the event that a delivery service is down.</p><p>Feel free to get in touch with me if you need any further help setting your notification service up. This post, coupled with <a href="https://github.com/kaushalvivek/notification-microservice">the repository</a> will hopefully make this easier for you. Thank you for reading!</p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ed863fa9e6" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/creating-a-scalable-and-reliable-notification-service-using-aws-twilio-docker-and-nodejs-4ed863fa9e6">Create a Notification Service using AWS, Twilio, Docker and Node.js</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a MERN Web-App to Heroku]]></title>
            <link>https://vivek-kaushal.medium.com/deploying-a-mern-web-app-to-heroku-b12c74c8b3c4?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/b12c74c8b3c4</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[mern]]></category>
            <category><![CDATA[mern-stack]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Tue, 15 Jun 2021 10:31:37 GMT</pubDate>
            <atom:updated>2021-06-15T10:31:37.591Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fFQYl5gn1N8aqz6H.jpg" /></figure><p>This post builds upon the guide to developing projects in MERN stack that I posted a while back, you can find it <a href="https://kaushalvivek.github.io/2020-04-11-mern/">here</a>.</p><p>Heroku probably has the best free-tier service out there for hosting MERN stack web applications. Though it requires certain non-intuitive settings before you can go about deploying your app. This article will guide you through the process of deploying your web-app on Heroku.</p><ul><li>We would be deploying the server and the frontend on the same deployment instance.</li><li>The database being used here is MongoDB Atlas.</li><li>This deployment uses npm instead of yarn for deployment.</li></ul><h3>Step 1 — App Directory Structure</h3><p>Your app comprises of a client (the React app) and a server, the structure should be as follows for deployment on Heroku:</p><pre>/project_root<br> |_ index.js (your server file)<br> |_ models<br> | |_ model1.js<br> | …<br> |_ routes<br> | |_ route1.js<br> | …<br> |_ package.json<br> |_ package-lock.json<br> |_ client (react app root)<br> |<br> … react app files</pre><h3>Step 2 — Add Handler for Client Build</h3><p>Add the following code to your <em>index.js (server)</em> file. This tells the server to look for a build of the react app.</p><pre>if (process.env.NODE_ENV === ‘production’ || process.env.NODE_ENV === ‘staging’) {<br> app.use(express.static(‘client/build’));<br> app.get(‘*’, (req, res) =&gt; {<br> res.sendFile(path.join(__dirname + ‘/client/build/index.html’));<br> });<br>}</pre><h3>Step 3 — Add Scripts to package.json (server)</h3><p>Add the following to your server’s <em>package.json</em>. If a <em>“script”</em> key is already present, add <em>“start”</em> and <em>“heroku-postbuild”</em> to it.</p><pre>“scripts”: {<br> “start”: “node index.js”,<br> “heroku-postbuild”: “cd client &amp;&amp; npm install &amp;&amp; npm run build”<br> },</pre><h3>Step 4 — Procfile</h3><p>Add a <em>Procfile</em> to your server root folder. Use the following commands in your terminal to do so:</p><pre>echo “web: node index.js” &gt; Procfile</pre><h3>Step 5 — Creating a path for API</h3><p>We are using the same URL for our API calls and for serving our app, hence, we’ll create a sub-path specifically for APIs. This path needs to be properly defined in both our server file (<em>index.js</em>) and our <em>axios</em> API calls.</p><p>While defining routes, add a parent sub-path (<em>/api</em>)to all routes. Make the following changes to your server file <em>index.js</em>:</p><p>Do this:</p><pre>const usersRouter = require(‘./routes/user’);<br>app.use(‘/api/users’, usersRouter);</pre><pre>const friendsRouter = require(‘./routes/friend’);<br>app.use(‘/api/friends’, friendsRouter);</pre><p>Instead of:</p><pre>const usersRouter = require(‘./routes/user’);<br>app.use(‘/users’, usersRouter);</pre><pre>const friendsRouter = require(‘./routes/friend’);<br>app.use(‘/friends’, friendsRouter);</pre><p>const friendsRouter = require(‘./routes/friend’);<br>app.use(‘/friends’, friendsRouter);</p><p>This needs to be done for all the routes in your application.</p><p>When calling the API using <em>axios</em> from your react app, ensure that the API is call is directed to the correct route. Don’t define the full path or the server port, that is handled automatically in Heroku. For example, calling the <em>/api/friends</em> route defined about, well call:</p><pre>componentDidMount() {<br> axios.get(‘/api/friends/’)<br> .then(response =&gt; {<br> <em>// do stuff</em><br> });<br>}</pre><h3>Step 6 — Server Port and Proxy</h3><p>We saw how we need not mention the server port in Heroku, as that is handled by the platform. We need to get this port and use it to serve our API. This is done by simply using the port defined in the environment. Add the following to the top of your server <em>index.js</em>:</p><pre>const port = process.env.PORT || 5000;</pre><p>Now that we’ve defined the port, we need to add a proxy to our client’s <em>package.json</em> file, so that when axios tries to reach our server in a local deployment it can reach our server. Add the following to the bottom of your <em>package.json</em> file in your <strong>client</strong> folder. <strong>NOT</strong> the one in your <strong>project_root</strong>. This is ignored by Heroku, but is used by your local deployment.</p><pre>“proxy”: “http://localhost:5000&quot;</pre><h3>Step 7 — Client Build</h3><p>Build your react app by running the following in your <em>client</em> folder:</p><pre>npm run build</pre><p>You can also use yarn to do the same:</p><pre>yarn build</pre><h3>Step 8 — MongoDB Atlas URI and Access Settings</h3><p>Make sure that your MongoDB Atlas URI is correctly configured in your server <em>index.js</em>. Also ensure that your MongoDB Atlas is setup such that it would accept access requests from your server’s IP <em>(recommended to whitelisting access to all IPs for a Heroku deployment)</em>. You can find more information on how to do this here:</p><ul><li><a href="https://www.youtube.com/watch?v=leNNivaQbDY">Video on how to whitelist all IPs <em>(recommended setting for Heroku deployment)</em></a></li><li><a href="https://stackoverflow.com/questions/42159175/connecting-heroku-app-to-atlas-mongodb-cloud-service">More information on Heroku and MongoDB Atlas integration</a></li><li><a href="https://docs.mongodb.com/manual/reference/connection-string/">More information on MongoDB Connection String</a></li></ul><p>You can check my guide to creating a MERN project <a href="https://kaushalvivek.github.io/2020-04-11-mern/">here</a>, for more information on how to setup your MongoDB URI in your server <em>index.js</em>.</p><h3>Step 9 — Pushing to GitHub</h3><p>We’d be using GitHub to deploy our code. Push your code, in the existing directory structure, to GitHub. Create a new repository in GitHub and copy the <strong><em>remote_repo_URL</em></strong>. Then execute the following commands in your <em>project_root</em> folder.</p><pre>git init<br><em># start a git project</em><br>echo node_modules &gt; .gitignore<br>echo client/node_modules &gt; .gitignore<br><em># add node_modules to git ignore</em><br>git add .<br><em># add files to push to repository</em><br>git commit -m “First Commit”<br><em># create your first commit</em><br>git remote add origin remote_repo_url<br><em># copy remote_repo_url from the target GitHub Project</em><br>git push -u origin master<br><em># push your code to the chosen GitHub Project</em></pre><h3>Step 10 — Connecting Heroku to GitHub</h3><ul><li>Go to <a href="https://dashboard.heroku.com/apps">heroku.com</a></li><li>Create a new app, choose an app name. Your app url would be <em>name.herokuapp.com</em></li><li>Choose <em>Connect to GitHub</em> as the deployment method</li><li>If your GitHub account isn’t connected to Heroku, do so</li><li>Search for, and choose the project repository we created in the previous step</li><li>Enable automatic deployments and select the deployment branch</li><li>Click on <strong>Deploy Branch</strong></li></ul><p>And that’s it! You’re done. Your app would now be deployed. If you face errors, you can debug them using Heroku’s logs. Feel free to reach out to me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b12c74c8b3c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guide to Deploying a Flask app on Heroku]]></title>
            <link>https://vivek-kaushal.medium.com/guide-to-deploying-a-flask-app-on-heroku-1c64ca9a1ce2?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c64ca9a1ce2</guid>
            <category><![CDATA[python-flask]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Tue, 15 Jun 2021 10:31:14 GMT</pubDate>
            <atom:updated>2021-06-15T10:31:14.439Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sa0A8R6opPwA7G-U.jpeg" /></figure><p>Heroku is a popular application deployment platform with a functional free tier of services, and Flask is populalar application development micro-framework in Python. The Heroku-Flask environment is one of the quickest ways to deploy a small application for testing, yet sadly, I did not find a single tutorial that covered all aspects of the deployment process without leaving room for a whole bunch of errors.</p><p>Hence, this guide.</p><p>Note that this is not a guide to Flask and Flask based development and is focused specifically on deployment of your flask application. There are excellent resources online for learning development Flask, which would get you started in a day, so refer to that if you need to get going in Flask, before learning to deploy your projects online — here.</p><h3>Setup Environment and Git</h3><p>Your deployment requires a root folder, we’ll let it be : flask-deployment. Create this folder, cd into it and install flask and gunicorn in a new virtual environment:</p><pre>mkdir flask-deployment<br>cd flask-deployment<br>pipenv install flask gunicorn</pre><p>Run the following in root (flask-deployment) to setup git:</p><pre>git init<br>git add .<br>git commit -m “Initial Commit”</pre><h3>Setup Heroku</h3><p>You need to have heroku-cli installed on your system, and have a Heroku account configured to proceed with this step. If you don’t have these requirements fulfilled, do the following first:</p><ul><li><a href="https://signup.heroku.com/">Sign Up for Heroku</a></li><li><a href="https://devcenter.heroku.com/articles/heroku-cli">Install heroku-cli</a></li></ul><p>Once you’re done with these installations and sign-up, run the following commands to setup Heroku in the created folder flask-deployment:</p><p><em>Code to login and create a new app</em></p><pre>heroku login<br>heroku create my-first-app</pre><p><em>Code to push initial commit to heroku</em></p><pre>git push heroku master</pre><p>Once you’re done with this, move forward to working on your app.</p><h3>The App</h3><p>Inside this folder, create an app folder which would contain all files related to your Flask application. For more information on how to create a Flask application, refer to the tutorial <a href="https://medium.com/bhavaniravi/build-your-1st-python-web-app-with-flask-b039d11f101c">here.</a></p><h3>Nomenclature</h3><p>Ensure the following specification in your flask app, for the sake of nomenclature used in this guide:</p><ul><li>your application is inside the app folder, i.e., it’s path is flask-deployment/app/main.py</li><li>your app is named main.py</li><li>your app is named app, as in app = Flask(<strong>name</strong>) — default naming.</li></ul><h3>Additional Files</h3><p>Now that you’ve created your app and tested it locally for functionality (refer to Flask tutorial for any help), let’s move on to deployment.</p><p>Create the following files in the root folder (flask-deployment):</p><h3>wsgi.py</h3><p>Create a wsgi.py file with the following content:</p><pre>from app.main import app</pre><pre>if __name__ == “__main__”:<br> app.run()</pre><p><strong>NOTE:</strong> <em>Ensure that the nomenclature specified earlier is followed.</em></p><h3>runtime.txt</h3><p>Create a runtime.txt file with your Python version. For me, as of now, its 3.7.5:</p><pre>python-3.7.5</pre><h3>Procfile</h3><p>By far the easiest file to mess up, and hardest to debug, your Procfile should contain the following, <em>(given that you’ve followed the nomenclature mentioned)</em>:</p><pre>web: gunicorn wsgi:app</pre><h3>requirements.txt</h3><p>Once you’re done with development on your app and have included all necessary modules, generate a requirements file using:</p><pre>pip freeze &gt; requirements.txt</pre><p><strong>NOTE:</strong> <em>Ensure that this requirement file also contains gunicorn, if it doesn’t, add gunicorn to the last line of requirements.txt manually.</em></p><h3>Deployment and Managing Dynos</h3><p>Run the following code blocks to deploy this project:</p><h3>Pushing code files to Heroku</h3><pre>git add .<br>git commit -m “Code files”<br>git push heroku master</pre><h3>Ensuring that a web dyno is running for deployment:</h3><pre>heroku ps:scale web=1</pre><p>Additionally, you can check if your app is working correctly by running the following in your project’s root folder:</p><p>heroku local web</p><h3>Tip on Database</h3><p>Do not use an sqlite3 database <em>(commonly used for basic Flask applications)</em> with Heroku deployment. Heroku does not support sqlite3 due to the manner in which sqlite accesses memory. Use POSTGRES instead.</p><p>And that’s it!</p><p>Your application will be live on Heroku after this. If you face any issues or have any doubts, feel free to reach out to me at <a href="/service/mailto:vivek.kaushal@outlook.com">vivek.kaushal@outlook.com</a>.</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c64ca9a1ce2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying an MLFlow Remote Server with Docker, S3 and SQL]]></title>
            <link>https://vivek-kaushal.medium.com/deploying-an-mlflow-remote-server-with-docker-s3-and-sql-4d46329c2b44?source=rss-b19fb3940a81------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d46329c2b44</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[mlflow]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Vivek Kaushal]]></dc:creator>
            <pubDate>Mon, 14 Jun 2021 06:58:13 GMT</pubDate>
            <atom:updated>2021-06-14T06:58:13.576Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*aJgp8RKO6hUXLG7R.png" /></figure><p><a href="https://mlflow.org/">MLFlow</a> is an open-source platform for managing your machine learning lifecycle. You can either run MLFlow locally on your system, or host an <a href="https://www.mlflow.org/docs/latest/tracking.html">MLFlow Tracking server</a>, which allows for mutiple people to log models and store them remotely in a model repository for quick deployment/reuse.</p><p>In this article, I’ll tell you how to deploy MLFlow on a remote server using <a href="https://www.docker.com/">Docker</a>, an S3 storage container of your choice <a href="https://min.io/"><em>Minio</em></a><em> or </em><a href="https://github.com/ceph/"><em>Ceph</em></a> and SQL <a href="https://www.sqlite.org/index.html"><em>SQLite</em></a><em> or </em><a href="https://www.mysql.com/"><em>MySQL</em></a>.</p><h3>Setting up the Server</h3><ul><li>Login to your remote server. It should have docker installed. For docker installation, check their <a href="https://docs.docker.com/get-started/">official guide</a>.</li><li>Create a new folder for your Mlflow server</li></ul><pre>mkdir mlflow-server<br>cd mlflow-server</pre><ul><li>Open a new terminal on your server, go to your <em>mlflow-server</em> directory and create a virtual environment for MLFlow installation</li></ul><pre>python3 -m venv env<br>source env/bin/activate</pre><ul><li>Install necessary packages:</li></ul><pre> pip3 install mlflow</pre><h3>Setting up the Backend Store</h3><p>MLFlow model parameters and run stats are all stored in a backend store which you can specify. By default, MLFlow uses the filesystem, but that is not an ideal setup for a remote tracking server. Here, I’ll tell you how to set it up using either SQLite3 or MySQL — whichever you may prefer. I would recommend using MySQL in a production environment.</p><h4>Using SQLite3</h4><ul><li>Install sqlite3</li></ul><pre>sudo apt install sqlite3</pre><ul><li>Setup an SQLite database for your MLFlow server’s <em>backend-uri</em>. Make sure that this file is in your <em>mlflow-server</em> folder.</li></ul><pre>sqlite3 store.db<br><em># press cntrl+D to exit sqlite </em><br><em># nothing else needs to be done</em></pre><ul><li>Note that yuor <em>backend-store-uri</em> would now be — sqlite:///store.db.</li></ul><h4>Using MySQL</h4><ul><li><a href="https://linuxize.com/post/how-to-install-mysql-on-ubuntu-18-04/">Install mySQL</a></li><li>Install PyMySQL in your python envirionment which has MLFlow.</li></ul><pre>pip3 install pymysql</pre><ul><li>Sign in to you mysql shell and create a new database for MLFlow. Also create a new user/use an existing user and assign access to the MLFLow database.</li></ul><pre>CREATE USER ‘mlflow-user’ IDENTIFIED BY ‘password’;<br>CREATE DATABASE ‘mlflowruns’;<br>GRANT ALL PRIVILEGES ON mlflowruns.* TO ‘mlflow-user’;</pre><ul><li>Note that your <em>backend-store-uri</em> would now be — mysql+pymysql://&#39;mlflow-user&#39;:&#39;password&#39;@localhost:3306/mlflowruns</li></ul><h3>Setting up the Artifact Store</h3><p>The artifact store is where your model’s files are stored. This includes your environment and other files that you can use to recreate and deploy your model instantly. By default your model’s artifacts are also stored on the filesystem in a fodler named <em>mlruns</em>, but when deploying a remote tracking server this is not an option as your client needs to have read and write permissions to the artifact — which is not possible for a filesystem path storage. Here, we’ll use S3 buckets to store model artifacts — the two options which we’ll look at are Minio and Ceph. Minio is comparatively lightweight, though Ceph is much more powerful and easier to start with, thanks to <a href="https://github.com/ceph/cn">Ceph Nano</a>.</p><h4>Using Minio</h4><ul><li>Get Minio’s latest docker image</li></ul><pre>sudo docker pull minio/minio</pre><ul><li>Run a Minio server and bind it to a server port that is exposed. The Minio server needs to run on a port that is exposed so that a remote client can upload model artifacts to it. Minio will serve as your <em>default artifact root</em>. You can run the following command. Note that you need to fill in an exposed port for minio, and any access/secret key pair of your choice.</li></ul><pre>docker run -p &lt;exposed_port_for_minio&gt;:9000 — name minio1 \<br>-e MINIO_ACCESS_KEY=&lt;your_access_key_id&gt; \<br>-e MINIO_SECRET_KEY=&lt;your_secret_key&gt; \<br>-v /mnt/data:/data \<br>-v /mnt/config:/root/.minio \<br>minio/minio server /data</pre><ul><li>Install necessary packages in your created environment.</li></ul><pre>pip3 install minio<br>pip3 install boto3</pre><ul><li>Setup local environment variables:</li></ul><pre>export MLFLOW_S3_ENDPOINT_URL=http://127.0.0.1:&lt;exposed_port_for_minio&gt;<br>export AWS_ACCESS_KEY_ID=&lt;your_access_key_id&gt;<br>export AWS_SECRET_ACCESS_KEY=&lt;your_secret_key&gt;</pre><ul><li>Create a Minio bucket — in your <em>mlflow-server</em> folder, run the following:</li></ul><pre>wget <a href="https://gist.githubusercontent.com/kaushalvivek/9f1905e25a28526dfeaaecf80ef5c361/raw/3bbb30954d8ee7144fe2ec183b78999518226040/create_bucket.py">https://gist.githubusercontent.com/kaushalvivek/9f1905e25a28526dfeaaecf80ef5c361/raw/3bbb30954d8ee7144fe2ec183b78999518226040/create_bucket.py</a><br>python3 create_bucket.py<br>rm create_bucket.py</pre><ul><li>Note that your <em>default-artifact-root</em> should now be <strong>s3://mlflow/artifacts</strong></li></ul><h4>Using Ceph</h4><ul><li>Install ceph nano locally. Based on which OS you are using, run the command listed <a href="https://github.com/ceph/cn#installation">here</a>.</li><li>Create a Ceph nano cluster</li></ul><pre>./cn cluster start -d /tmp mlflow-cluster -f huge</pre><ul><li>Note down the <em>ceph endpoint URL, AWS access key id and AWS secret key</em> that the cluster auto-generates and prints to shell.</li><li>Cretae an S3 bucket</li></ul><pre>./cn s3 mb mlflow-cluster mlflow-buc</pre><ul><li>Setup local environment variables:</li></ul><pre>export MLFLOW_S3_ENDPOINT_URL=http://127.0.0.1:&lt;ceph-endpoint-url&gt;<br>export AWS_ACCESS_KEY_ID=&lt;your_access_key_id&gt;<br>export AWS_SECRET_ACCESS_KEY=&lt;your_secret_key&gt;</pre><ul><li>Note that your <em>default-artifact-root</em> should now be <strong>s3://mlflow-buc</strong></li></ul><h3>Starting the Server</h3><ul><li>Start the MLFlow server — run the following from you <em>mlflow-server</em> folder. You need to enter an exposed port that would be the MLFlow Server’s port, for UI and logging. <strong>This port needs to be different from your Artifacts endpoint port</strong>.</li></ul><pre>mlflow server -p &lt;exposed_port_for_mlflow&gt; \<br> — host 0.0.0.0 \<br> — backend-store-uri &lt;enter_backend_store_uri&gt; \<br> — default-artifact-root &lt;enter_deafult_artifact_root&gt;</pre><ul><li>And that’s it! your server is up and running. Note that while you’re specifying the endpoint URL, do not use <em>localhost</em>. Stick to <a href="http://127.0.0.1/"><em>http://127.0.0.1</em></a> with the <em>http</em>. Ceph is specific about the endpoint URL.</li></ul><h3>Setting up the Client</h3><ul><li>On your local system, create a new folder where you’ll work with mlflow and create a local virtual environment</li></ul><pre>mkdir mlflow-work<br>cd mlflow-work</pre><pre>python3 -m venv env<br>source env/bin/activate</pre><pre>pip3 install mlflow</pre><ul><li>Setting up local environment variables — you need to setup your environment for accessing MLFlow’s remote tracking server and logging data to your remote minio artifact server</li></ul><pre>export MLFLOW_TRACKING_URI=http://&lt;remote_server_ip&gt;:&lt;exposed_port_for_mlflow&gt;<br>export MLFLOW_S3_ENDPOINT_URL=http://&lt;remote_server_ip&gt;:&lt;exposed_port_for_artifact_root&gt;</pre><pre>export AWS_ACCESS_KEY_ID=&lt;enter_aws_access_key_id&gt;<br>export AWS_SECRET_ACCESS_KEY=&lt;enter_aws_secret_access_key&gt;</pre><ul><li>And you’re all set! You can download example code from <a href="https://github.com/mlflow/mlflow/tree/master/examples">MLFlow examples</a>, and start executing them directly in your <em>mlflow-work</em> directory. For more information about MLFlow checkout <a href="https://www.mlflow.org/docs/latest/quickstart.html">MLFlow Documentation</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d46329c2b44" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>