<?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 Nick Kobychev on Medium]]></title>
        <description><![CDATA[Stories by Nick Kobychev on Medium]]></description>
        <link>https://medium.com/@nick-kobychev?source=rss-e60d424082e9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zv9FmDdIOjLWBpeorN8gnw.jpeg</url>
            <title>Stories by Nick Kobychev on Medium</title>
            <link>https://medium.com/@nick-kobychev?source=rss-e60d424082e9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 15:20:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nick-kobychev/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[Knowledge Silos OUT. Knowledge Multipliers IN — How To Become a Real 10x Engineer]]></title>
            <link>https://medium.com/similarweb-engineering/knowledge-silos-out-knowledge-multipliers-in-how-to-become-a-real-10x-engineer-a43ebd5cfdbb?source=rss-e60d424082e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a43ebd5cfdbb</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[leadership]]></category>
            <category><![CDATA[inspiration]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Nick Kobychev]]></dc:creator>
            <pubDate>Mon, 19 Sep 2022 09:32:49 GMT</pubDate>
            <atom:updated>2022-09-19T09:32:49.984Z</atom:updated>
            <content:encoded><![CDATA[<h3>Knowledge Silos OUT. Knowledge Multipliers IN — How To Become a Real 10x Engineer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dsVP5B5DdNzj40Ma" /><figcaption>Photo by <a href="https://unsplash.com/@wocintechchat?utm_source=medium&amp;utm_medium=referral">Christina @ wocintechchat.com</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Who are the Knowledge Silos?</h3><p>A topic I wanted to write on for a while is the idea of `Knowledge Silos` [KS]. <br>A knowledge silo is a highly skilled person or team in your organization that has information or skills that aren’t shared across the organization. This lack of sharing might be the result of many different things, for example:</p><ol><li>Some experienced engineers (KS) don’t want anyone else to mess with their precious code. They choose to take the easy way out whenever you ask them for help with a problem. They just solve it on their own and present you with a complete solution that is pretty sparse on details. But hey! What do you have to complain about? You have what you asked for — a solution.</li><li>Some KS just don’t have the time, they’re really busy! They know how the system works. Explaining it will take too long, and you know… you might not even get it, you’re pretty new to the company/language/framework/system/tech. Why waste both of yours time?</li><li>The worst type of KS are the ones who don’t share their knowledge and skills knowingly and intentionally. For them, it’s their insurance, and job security.<br>To them, If they are the only person who knows that one system like the back of their hand, it means they are not replaceable.<br><strong>They are wrong, everyone is replaceable.</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*LpinHv1zBC_BhvWRcyBAxA.gif" /></figure><h3>Why are Knowledge Silos so bad?</h3><p>Having knowledge silos in your organization creates bottlenecks during development and troubleshooting. It makes cross-team/department collaboration more difficult and creates a huge knowledge void when that KS leaves your organization.<br>That does not mean they are not replaceable. It just means everyone else will have to play catchup to close that gap, and they eventually will.</p><p>Unfortunately, every company has Knowledge Silos. What is even more unfortunate is that they are often the best and brightest individual contributors, the ones you would think of as <strong>10x engineers</strong>.<br>They are the people who have been in the company for a while. The people who built up the foundational infrastructure everyone uses now. They are the people who have been in the most critical design meetings, they know why things are as they are.</p><p>I would argue that KS are not really <strong>10x engineers</strong>, they are at most, <strong>2x engineers</strong>.<strong> </strong>No doubt, they do their job well, but they are also preventing other engineers from doing better by withholding knowledge. <strong>Whether they do it intentionally or not hardly matters.</strong></p><p>They are a bottleneck, a single point of failure.</p><p>On the other side of that same experienced and talented coin, you have the true <strong>10x engineers.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*pD-SlUZIWMbqCubmNaBBeg.gif" /></figure><h3>Knowledge Multipliers</h3><p>‘Knowledge Multipliers’ [KM] are those engineers who can be great individual contributors [IC] and perform well when the time calls for it. Perhaps they are not as “amazing” at working solo as KS are, but their strengths lie elsewhere.</p><p>Instead of hoarding knowledge, KMs share it.<br>When you ask them for help, you will not only get a solution, you will get a walkthrough. You will get an insight into their thought process for solving the problem. So that next time you encounter a similar problem, you’ll be able to tackle it on your own.<br>What they do best is empower the people around them.<br>You might think that by doing so they make themselves easily replaceable.</p><p>Sure! There will be little to no knowledge void if they leave/are replaced. But why would you replace someone so valuable?!</p><p>They might not be the best ICs, but by empowering others, they improve the productivity in your organization tenfold. KMs are <strong>10x engineers</strong> by the virtue of their work empowering others and not by their solo performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*aW7tE5X9j3bIwzBi4GfTLQ.gif" /></figure><h3>Why am I writing about this?</h3><p>When writing a post like this, the best I can do is try and convey the knowledge I gained during my career.</p><p>I have experienced the aftermath of a KS leaving an organization, the issues that surface, the systems that break, and the “hidden knowledge” that was guarded by this KS being slowly rediscovered by other people.</p><p>On the other hand, I had the pleasure to work with great KMs and I gained tremendous knowledge and experience while working alongside them. You can think of a KM as <strong>that</strong> one teacher in school/uni that you will never forget because they were just, oh so amazing at their job and inspired everyone in their class to do better.</p><p>Of course, like most things in life, this is not a binary, it’s a spectrum.<br><strong>I’m writing this post with the hopes it gets people to actively think about the concepts of KS and KM. I hope that by doing so, they will do their best to end up on the Knowledge Multiplier side of the spectrum.</strong></p><h3>How can you become a Knowledge Multiplier?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*67BjvuAoToPd4mjdJSbX-g.gif" /></figure><p>I can’t confidently say I am a Knowledge Multiplier, I do my best but I’m not perfect by any means.<br>From my experience, the best tip I have on becoming a Knowledge Multiplier is:</p><blockquote>Strive to be independent and empower others to be more independent.</blockquote><p>Let’s look at each part separately:<br>- <strong>“</strong><em>strive to be independent</em>”</p><h4><strong>The What</strong></h4><p>Being Independent doesn’t mean you’re the living embodiment of an anti-social software engineer. The “I don’t need anyone, I only work alone!” type.<br>What it means is that you <strong>can</strong> work alone, and you can troubleshoot problems without relying on others. Asking for help will most likely speed up the process, it is important to know when to do it. But sometimes, no one is available to help. You want to be able to work alone when needed.</p><h4><strong>The How</strong></h4><p>Be curious, ask questions, and don’t accept unexplained solutions as answers (when possible).<br>Dig deeper and try to understand how and why things work the way they do. Knowledge is power. Understanding leads to independence.</p><p>Another thing you can do, even though it might seem contradictory to the principle of independence, is <strong>networking</strong>. Networking is not only a thing reserved for conferences.<br>You can and should get to know people outside of your immediate circle of work colleagues.</p><p>Knowing people across your organization will help you avoid bottlenecks and help you find the right person to reach out to for help when the time comes.</p><p>- “<em>help others be more independent”</em></p><h4><strong>The What</strong></h4><p>You know it, I know it. It’s nice to feel needed.<br>But it’s important to remember that there are different types of “needed”.<br>We all heard the saying:<br><em>“If you give a man a fish, you feed him for a day. If you teach a man to fish, you feed him for a lifetime.”</em></p><p>You do not want to end up being just a “fish provider”.<br>If the only thing you do is solve other people’s problems, they will keep coming back with the same problems day after day.</p><p>Oh sure, you’ll be needed, but don’t you have your problems and tasks to deal with?</p><h4><strong>The How</strong></h4><p>Be the “person who teaches others to fish”. When helping others with issues they encounter, explain your thought process. When possible you should even walk them through the solution.</p><p>Not everyone is comfortable asking for these “extra” things. You should be willing to provide them unprompted.<br>That way you will empower others. They will gain knowledge and you will be rewarded with new and exciting problems when they ask for help. No more daily fish giveaways.</p><p>Another thing I found to be useful when trying to empower others is just <strong>being available</strong>.<br>I’m not talking about working overtime to solve other people’s problems. I’m talking about being responsive and willing to help.<br>Of course, you can’t be there all the time and be ready to help whenever someone needs you, you have your things to deal with. However, what you can do is let them know you’re there, even if you can’t help them at that exact moment.</p><p>You saw your slack notification asking for help, but you’re busy and want to avoid distractions?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*tXbhUycL8_sZmzx47jh2IQ.gif" /><figcaption>Picture credit: <a href="https://agora.co/a/team/images/slack%20notifications%202.gif">agora.co</a></figcaption></figure><p>Well, you already saw that notification so you’re already distracted. You might as well let them know you’ll get back to them at a later time.</p><p>And If you’re wondering “How’s me being available empowering others?”</p><p>The answer is pretty simple. People are more willing to try and tackle something unfamiliar on their own if they know there’s someone to help them if they get stuck, a safety net of sorts.</p><h3>Disclaimers</h3><ul><li><em>This post is solely based on observations I made during my career from Junior to Principal Engineer.</em></li><li><em>The statements I made in the post are in no way absolute truths and there are a ton of gray areas and variables to consider.</em></li><li><em>This is a farewell post in a way. I’m writing this during my last week out of 5.5 years at Similarweb. After some self-reflection, I decided to try and formalize a few of the things I learned during these fantastic years I spent working with incredible people.</em></li></ul><p>Let me know your thoughts about Knowledge Silos and Knowledge Multipliers!<br>What other techniques do you utilize to empower others and multiply knowledge in your teams and organizations?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*riN3DjrH0By908V_0y1HYQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a43ebd5cfdbb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/similarweb-engineering/knowledge-silos-out-knowledge-multipliers-in-how-to-become-a-real-10x-engineer-a43ebd5cfdbb">Knowledge Silos OUT. Knowledge Multipliers IN — How To Become a Real 10x Engineer</a> was originally published in <a href="https://medium.com/similarweb-engineering">Similarweb Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Engineering Made Simpler: How to Get Your ETLs to Production Faster]]></title>
            <link>https://medium.com/similarweb-engineering/data-engineering-made-simpler-how-to-get-your-etls-to-production-faster-1c26d5747024?source=rss-e60d424082e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c26d5747024</guid>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[etl]]></category>
            <dc:creator><![CDATA[Nick Kobychev]]></dc:creator>
            <pubDate>Sun, 10 Jul 2022 11:18:21 GMT</pubDate>
            <atom:updated>2022-07-10T11:18:21.207Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve landed up in this post, I can safely assume you’re working with Big Data.</p><p>And now I’ll guess a few more things. And if I’m right, you’ll read this post top to bottom and perhaps throw in a few claps.</p><p>Do we have a deal?</p><p>…</p><p>I’ll take that as a “Yes!”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*BNEArL70JI1KH7Bn" /></figure><p>You’re either:<br>- Diving head first into any available data and researching the heck out of it, trying to find something new, interesting and valuable<br>Or<br>- You’re a data engineer working on ETLs. You often need to run those ETLs partially, trying things out in order to assist the person who does the aforementioned research <a href="https://emojipedia.org/index-pointing-up/#:~:text=A%20single%20finger%20pointing%20upward,to%20Emoji%201.0%20in%202015.">☝️</a></p><p>Either way, I have no doubt that you know the pain of rewriting your research/POC code from a Jupiter/Databricks notebook into something that resembles the ETLs you run on your production system.</p><p>In this post I’ll cover the common pains we continually faced during those rewriting processes, and the techniques we used to overcome them at Similarweb.</p><h3>The (long) Life Story of an ETL</h3><p>It’s a new sprint, you have a new task, and as usual you start writing your ETL in a notebook.</p><p>Why wouldn’t you? It’s convenient, no setup required and you get quick results and stored state for every bit of code you run.</p><p>You get your imports in order, and set up your consts…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*23G3MFbwdEMUCSTK" /></figure><p>You read your inputs into Dataframes…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sur2aJVwYd4AUd0c" /></figure><p>Before you proceed, you decide to display the inputs to make sure all is as expected…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WhxuCKoIpbkPkfRw" /></figure><p>Wooh, all looks well.<br>You wiggle the data to the left, you wiggle the data to the right</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/0*HYxfsWeuJ8eJpQZD" /></figure><p>Do some crazy complex operations on it…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PycQEHbfCy6LXQI_" /></figure><p>Because you’re really careful, you display your perfect results and gaze lovingly at those rows 😍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UaAek73ri9F4VMRw" /></figure><p>At this point you write the results to your favorite <em>temp</em> path in some bucket somewhere. All that is left now is to <strong>rewrite this whole thing to look like a production ETL </strong>😒</p><p>Because of course, the notebook you used to research and develop it can’t be used for production purposes.</p><h3>Rewriting for production</h3><p>You obviously know what our production ETLs look like. This isn’t your first rodeo, and you have many ETLs under your belt.</p><p>But…</p><p>This morning the coffee machine decided to give in.<br>So you, being oh so under-caffeinated, decided to refresh your memory and take a look at an existing ETL.</p><p>It looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*VffHe0UYTDC3b4Si" /></figure><p>It receives a SparkSession, and a Dict <strong>ctx</strong> to hold all the parameters we want to pass into this Spark Job.</p><p>The code in your notebook seems like a simple ETL. So you begin by grabbing all the code from the notebook, and pasting it into a function with the same signature you’ve just seen.</p><p>The results looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/0*rx1lJhgMGpmj3mE9" /></figure><p>There are clearly a few modifications you need to make:</p><ol><li>This ETL you’re working on is supposed to be a daily one. Meaning that the paths can’t be consts, you need to change them to be configurable and get them from <em>ctx.</em></li><li>The <em>display</em> commands are nice during the development phase, but they aren’t needed in production — all you need to do is remove them.</li></ol><p>The changes you had to make couldn’t be simpler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*VSlmRcqeC23h9jKq" /></figure><p>Now the paths are passed in through the <em>ctx</em> and the <em>display </em>commands are gone.<br>You push your code, merge your branch, deploy the ETL to the production system and run it.</p><p>and…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/0*52js5Jf9S1DvPI_F" /><figcaption>The lack of caffeine finally got you to make a mistake!</figcaption></figure><p>How could you forget that the <em>complex_algorithms</em> package is not in the PYTHON_PATH in the production environment, but rather in the infamous <em>common.shared.utils </em>directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*Cc5qIYVwc_04F28d" /></figure><p>You fix the import and redeploy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*CXiGyBIu5eOFLJtU" /></figure><p>Finally! You did it, it’s working!</p><p>With another ETL in the books, a simple one, you reflect on the annoyances you tend to face when moving ETLs from dev to production (today’s case notwithstanding):</p><ul><li>You have to clear out a lot of code before you can run ETLs in production. Mainly debugging prints and temp variables you used to work with subsets of your data</li><li>Many consts need to be replaced with <em>ctx</em> usage</li><li>Commands always end up being pretty messy in the dev notebook. You keep rerunning different commands to work out a complex part of your algorithm, fix a data set or troubleshoot a transformation. Ending up with a notebook that is far from having all its commands in chronological order</li><li>Dependencies can be located in different places in each system</li></ul><p>There must be a better way, you think to yourself.<br>Well, you’re <strong>right</strong>. There is a better way.</p><h3>Mirroring Your Production Environment Locally</h3><p>If you approach your dev process differently, you can drastically reduce the number of changes you have to make. You can also solve the problems you will encounter when moving an ETL from the development phase to production.</p><p>One way you can speed up the dev to production transition process is by taking the place of the “scheduling” component in your production environment.</p><p>I have no doubt that you remember this diagram from your on-boarding at our company 😉. It shows how we run Spark jobs in our production system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z-N3Sg-ZH8fydaP4" /></figure><h4>But just in case you don’t remember it, let’s go over it again.</h4><ol><li>A custom Airflow operator, DatabricksSubmitOperator, sends all required parameters to run a Spark job over to our internal library that wraps the Databricks Job Api. (parameters like job name, execution date, input and output paths, etc.)</li><li>Using the received parameters, our internal library resolves the path of the egg/wheel file that contains our Spark job code.</li><li>The path to the egg/wheel file, along with all other parameters, are submitted to the Databricks Job API for execution.</li><li>The state of the job is monitored by our library and reported back to the operator.</li></ol><p>The scheduling component in this diagram is the <em>DatabricksSubmitOperator. </em>Using a simple script that you run locally on your machine, you can put yourself in the place of the operator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/0*q-Z-Mi2fCKsi7hjE" /></figure><p>This simple script, lets call it <em>db_submit.py</em>, can do everything the operator does, and more!</p><p>It receives all the same parameters and passes them on to the internal library, just like the operator. But in addition to that it can also take your local code, package it into an egg/wheel, and upload it to the S3 bucket containing all Spark job files.</p><p>No need to push the code to your remote repository, no need to create a merge request, no need to deploy it.</p><p><em>*security concerns were kept in mind, and access is limited to staging resources*</em></p><p>Running a Spark job that only exists on your machine is as simple as that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fDwbbm6PkC3wNgqL" /></figure><p>The path to the Python file containing the Spark job is <em>my_jobs.magic_job. </em>After that, pass in the other parameters required to run the job, like paths.</p><p>Let’s not forget the <em>-l (L) </em>flag, it’s there to let the script know that you want to run the <em>local</em> version of the job and not the one that is in production.</p><p>“If only it were this simple at my previous job” you think to yourself.</p><p>But especially during the development phase, you might find yourself wanting to troubleshoot a rebellious job that keeps misbehaving when running at scale.</p><p>Enter…</p><h3>Databricks Connect</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*RoH1GpoMVhFqRy8ZoqX95g.png" /></figure><p>What if I told you that using <a href="https://docs.databricks.com/dev-tools/databricks-connect.html">Databricks Connect</a>, a feature provided by Databricks, your local machine can become a driver in a Spark cluster running on Databricks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/0*ZI5a_WfoG9pRI774" /></figure><p>This gives you a powerful tool, a debugger. You can actually debug any code that runs on the driver. And if you’re tricky enough, you can even debug samples of code that usually run on executors, like UDFs.</p><p>Debugging the code that runs on your driver is as simple as debugging any other Python code you’ve ever debugged. Just place a breakpoint on your troublesome line and run with debugging.</p><p>But you’re working with Spark, and know that the heavy lifting is done on the executors. Unfortunately that code can’t really be debugged locally, unless we’re talking about UDFs and you’re being tricky 😉. (this also applies to custom functions used to map or filter RDDs)</p><p>You can take your Spark job…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FAY1Iadnsnhh-hgK" /></figure><p>and make a slight modification…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/0*7QR5OvJto2AHEqXa" /></figure><ol><li>Take a small sample of the data (line 17)</li><li>Iterate over the sample in a purely Pythonic manner (line 18)</li><li>Call the function you use as a UDF (line 19)</li></ol><p>This way you’ll be able to place breakpoints inside the function you registered as a UDF (line 10), and troubleshoot any weirdness that might be going on inside!</p><h3>What we gained</h3><p>With all these tools in our toolbox, we get:</p><h4>Faster POCs</h4><p>No need to go through the usual bureaucracy to get your code to production to run it at scale</p><h4>Faster custom runs</h4><p>Want to run a job with different input paths? Easy! Just change the input paths you pass to <em>db_submit.py</em></p><h4>Faster feedback loop</h4><p>When it’s faster and easier to get running, you’ll know if something goes wrong in no time!</p><h3>Extra Credit</h3><p>While the tools used are very specific to how we do it in Similarweb, the techniques we used to give our dev environment a similar feel to our production environment are very much transferable.</p><p>Our next step is to look into <a href="https://docs.databricks.com/dev-tools/dbx.html">dbx</a>, a new open source offering by Databricks, and see if it can simplify our development process even further. And if it does, I’ll see you in the next post 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c26d5747024" width="1" height="1" alt=""><hr><p><a href="https://medium.com/similarweb-engineering/data-engineering-made-simpler-how-to-get-your-etls-to-production-faster-1c26d5747024">Data Engineering Made Simpler: How to Get Your ETLs to Production Faster</a> was originally published in <a href="https://medium.com/similarweb-engineering">Similarweb Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The lazy intro to Go]]></title>
            <link>https://medium.com/similarweb-engineering/the-lazy-intro-to-go-68303323968d?source=rss-e60d424082e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/68303323968d</guid>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Nick Kobychev]]></dc:creator>
            <pubDate>Sun, 20 Feb 2022 13:06:34 GMT</pubDate>
            <atom:updated>2022-02-20T13:11:12.417Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Lazy hippo laying on the ground" src="https://cdn-images-1.medium.com/max/1024/0*GR00Q3-ny1EugVDN" /><figcaption>Photo by <a href="https://unsplash.com/@tmdpw?utm_source=medium&amp;utm_medium=referral">Tim De Pauw</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This post is a distillation of an “intro course” I conducted at Similarweb almost exactly 1 year ago. With one session a week for a month, I led a dozen engineers coming from different backgrounds and teams in the company through important topics with examples and resources that should lay the foundation for working with Go in their day to day.</p><p>The “lazy” part in the title is mostly about me deferring to external sources. I’ll use sources I value and refer to whenever I need a refresher instead of writing a lengthy post rehashing the original authors.</p><h4>What is this going to be about and who might benefit from reading this?</h4><p>In this post:<br><strong>I will</strong> <strong>not</strong> attempt to comprehensively cover everything there is to cover when starting with Go. Meaning this might not be the best guide for newcomers to the software development world.<br>What <strong>I will</strong> be doing is going through some foundational steps in starting with a new language, discussing language features and gotchas, linking to useful resources, asking and answering questions that were asked during the initial run of this course.</p><p>This post is mostly targeted towards people with some previous software engineering experience. As I said, this is not a comprehensive intro to the Go language.</p><p><em>*If you’re an experienced Go developer, you might still find some new information in this post, maybe a gotcha or two you weren’t familiar with. Although my previous post might be a better fit for you:<br></em><a href="https://medium.com/p/1dfe45fd6b6b"><em>Moving From NodeJs To Go — Doing More, Faster For Less</em></a></p><h4>Prepare you favourite IDE / text editor</h4><p>The 2 most common IDEs in our company are <a href="https://code.visualstudio.com/"><em>VS Code</em></a><em> </em>with <a href="https://code.visualstudio.com/docs/languages/go">this extension</a> or the right IDE for the job from <em>JetBrains. In this</em> case it’s <a href="https://www.jetbrains.com/go/"><em>Goland</em></a>.</p><p>Unfortunately there is no community version for this Goland. You can still try it for 30 days, use <a href="https://www.jetbrains.com/help/go/faq-about-goland.html#is-there-a-goland-community-edition">pre-release versions</a> or <a href="https://plugins.jetbrains.com/plugin/9568-go">this official plugin</a> if you happen to have an <em>IntelliJ IDEA Ultimate </em>license.</p><h4>Getting started</h4><p>The two most important links I can give to start your Go journey are the <a href="https://go.dev/doc/tutorial/getting-started">Tutorial</a>, which will help you set up the basic requirements to working with Go, and the <a href="https://go.dev/tour/welcome/1">Tour of Go</a> which is intended to make you familiar with the language and its features.</p><figure><img alt="meme of a hand holding a hamster with text saying “it’s dangerous to go alone, take this”" src="https://cdn-images-1.medium.com/max/311/1*jwzORu93lAxI4GW59c6zTw.png" /></figure><h4>Straight to work</h4><p><a href="https://gophercises.com/">Gophercises</a> are a free course that will get you building actual working code in no time!<br>After signing up we can start with <a href="https://courses.calhoun.io/lessons/les_goph_01">Exercise #1: Quiz Game</a>.</p><p>After watching <strong>Overview </strong>and <strong>Solution- Part 1 </strong>and following along I got these 2 questions from the participants.</p><p><strong>Q&amp;A #1<br></strong>Q: I’m a little confused on how to work with slices of slices. When passing a slice to a function it is passed by reference, not unlike pointers. When should I use pointers to slices if ever?<br>A: A short explanation can be found <a href="https://play.golang.org/p/xgHPlGy1Q_o">here</a>. Additionally I highly recommend you copy the code to your favourite editor to get code highlights and make it more readable. Another short and good read is <a href="https://medium.com/swlh/golang-tips-why-pointers-to-slices-are-useful-and-how-ignoring-them-can-lead-to-tricky-bugs-cac90f72e77b">this post</a>.</p><p>Q: When should I use a <em>pointer receiver </em>vs <em>value</em> <em>receiver </em>struct methods?<br>A: This answers the question thoroughly:<br><a href="https://stackoverflow.com/a/27775558">Value receiver vs. pointer receiver — Stack Overflow</a></p><p>Now we can get to <strong>Solution — Part 2 </strong><a href="https://courses.calhoun.io/lessons/les_goph_03">here</a> and finally get to some concurrency!</p><p>Same deal here, watch and follow along. Try to write some code without peeking, practice makes perfect!</p><figure><img alt="a gif of a person lifting bottles as if they are working on their biceps" src="https://cdn-images-1.medium.com/max/470/0*8KJOFWvpFYFEg6AI" /></figure><p>While you’re at it try to keep these questions in mind:</p><ul><li>Do I understand why reading from a channel blocks code execution?</li><li>Am I comfortable with Timers and Channels?</li><li>Do I understand how anonymous functions and closures work? <br>If you think you do, you should try and guess what will happen <a href="https://go.dev/play/p/vXawTT4zOSU">here</a>.</li></ul><p>If you answered “<strong>no</strong>” to any of these questions I strongly suggest you go over the concurrency part of the <a href="https://go.dev/tour/concurrency/1">Go Tour</a> again.</p><p><strong>Q&amp;A #2</strong></p><p>Q: How does <strong>select</strong> work and what’s the order of the case evaluation?<br>A: <a href="https://stackoverflow.com/a/47648910">This</a> stack overflow answer has a rather good explanation.</p><p>Q: How do <strong>channels </strong>work internally?<br><strong>This is optional knowledge, so feel free to skip this<br></strong>A: Go is a “lower level” language so expect some C-like code if you follow <a href="https://stackoverflow.com/a/19623095">this link</a>.</p><p>Q: Any idea why standard library slices and maps have different ways to access values and iterate through? This causes confusion and it’s not easy to remember.<br>A: I was unable to find any concrete explanation as to why it works like it does, but it seems to make sense, in my opinion.<br>Anyways, maybe this <a href="https://go.dev/play/p/oX0AKvTS-Dg">playground</a> should clear this up.</p><p>You can also read a more detailed explanation here:<br><a href="https://blog.golang.org/maps">https://blog.golang.org/maps</a><br><a href="https://blog.golang.org/slices-intro">https://blog.golang.org/slices-intro</a><br>If it’s still unclear, please comment and I’ll do my best to clear this up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*Gth3E26UOy5uSTAL" /></figure><h4>Structs and Interfaces</h4><p>Let’s start with a reading list, the following posts are a great resource when it comes to in depth information about structs and interfaces:</p><ul><li><a href="https://medium.com/rungo/structures-in-go-76377cc106a2">Structures in Go (structs). Unlike traditional Object Oriented… | by Uday Hiwarale | RunGo | Medium</a></li><li><a href="https://medium.com/rungo/interfaces-in-go-ab1601159b3a">Interfaces in Go. ☛ What is an interface? | by Uday Hiwarale | RunGo | Medium</a></li><li><a href="https://blog.logrocket.com/exploring-structs-and-interfaces-in-go/">Exploring structs and interfaces in Go — LogRocket Blog</a></li></ul><p><strong>Things to note about struct types:</strong></p><ul><li>Field names may be specified either implicitly with a variable or as embedded types without field names. In this case, the field must be specified as a type name T or as a pointer to a non-interface type name *T</li><li>Field names must be unique inside a struct type</li><li>A field or a method of an embedded type can be promoted</li><li>Promoted fields cannot be used as field names in the struct</li><li>A field declaration may be followed by an optional string literal tag</li><li>An exported struct field must begin with a capital letter</li><li>Apart from basic types, we can also have function types and interface types as struct fields</li></ul><p>More details about the struct type can be found <a href="https://go.dev/ref/spec#Struct_types">here</a> in the language specification.</p><p><strong>Things to note about interface types:</strong></p><ul><li>The zero value of an interface is nil</li><li>An empty interface contains zero methods. Note that all types implement the empty interface. This means that if you write a function that takes an empty interface{} value as a parameter, you can supply that function with any value</li><li>Interfaces generally belong in the package that uses values of the interface type and not the package that implements those values</li></ul><p>More details about the interface type can be found <a href="https://go.dev/ref/spec#Interface_types">here</a> in the language specification.</p><h4>Error handling</h4><p>A blog post from the official Go blog, I know it’s from 2011 but it’s still basically the way to go, with a few improvements that were added in later versions:<br><a href="https://blog.golang.org/error-handling-and-go">Error handling and Go — The Go Programming Language</a></p><p>Another more recent blog post is this one:<br><a href="https://blog.golang.org/go1.13-errors">Working with Errors in Go 1.13 — The Go Programming Language</a></p><h4>Panic</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*u-g9Mb84NPvwyg-g4uELSQ.gif" /><figcaption>at the disco</figcaption></figure><p>Another oldie, but it is a goodie!<br><a href="https://blog.golang.org/defer-panic-and-recover">Defer, Panic, and Recover — The Go Programming Language</a></p><p>Honestly I don’t have much to say about panics just because it’s rarely a case where you’ll use a panic and not just return an error.<br><a href="https://stackoverflow.com/questions/44504354/should-i-use-panic-or-return-error/44505268#44505268">This</a> pretty much covers it.</p><h4>Best practices</h4><p>A few simple ideas to always keep in mind are the <a href="https://go-proverbs.github.io/">Go Proverbs</a>!<br>If you consider them when working on your next project, you’ll be sure to improve your code quality tenfold.</p><p>I would love to hear from you in the comments if you find anything unclear/incorrect!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68303323968d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/similarweb-engineering/the-lazy-intro-to-go-68303323968d">The lazy intro to Go</a> was originally published in <a href="https://medium.com/similarweb-engineering">Similarweb Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving From NodeJs To Go — Doing More, Faster For Less]]></title>
            <link>https://medium.com/similarweb-engineering/moving-from-nodejs-to-go-doing-more-faster-for-less-1dfe45fd6b6b?source=rss-e60d424082e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dfe45fd6b6b</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[similarweb]]></category>
            <dc:creator><![CDATA[Nick Kobychev]]></dc:creator>
            <pubDate>Sun, 22 Aug 2021 14:58:18 GMT</pubDate>
            <atom:updated>2022-06-03T16:21:57.312Z</atom:updated>
            <content:encoded><![CDATA[<h3>Moving From NodeJs To Go — Doing More, Faster For Less</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TksPb3OZQ2eonGctC0XTlQ.jpeg" /></figure><h3>Motivation and Introduction</h3><p>As an engineer in the Data Factory group at SimilarWeb you quickly learn that providing our clients with accurate data and insights is our top priority. Doing so often requires processing GBs and even TBs of data in a short timeframe.</p><p>This is a challenge I enjoy taking on, and why I’m excited to tell you about the time when we optimized one of our most demanding services. By doing so we increased its processing speed <strong>x28</strong> and decreased resource usage by <strong>x10</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*jJ0KJNsTQihOT2Vs.gif" /></figure><h3>The Challenge</h3><p>Make ~150M calls to an external API to fetch the data and process it in order to have it ready for use by our data analysis team, all within a couple of days.</p><p>If you’re in any way familiar with big data processing you must be thinking <em>“Processing 150M results in a distributed way using Spark/MapReduce shouldn’t take too long. Nick, that’s not a challenge”. </em>I mean<em>… </em>you’re not wrong.</p><p>The challenge is fetching the data from this API as quickly as possible for it to be processed in time. Given the limitations we have with that API.</p><p><strong>1000 Requests/sec</strong></p><h3>What we started with</h3><p>Initially we wanted to verify the relevancy of the data to our needs.</p><p>To avoid committing a lot of engineering time to a task that might not pan out, we decided on using some of our existing code to make all these API calls, as a test run. We were able to use that code because it was already being used for continuous processing of similar looking data on a smaller scale.</p><p>Said existing code was a NodeJs service running in docker container (<em>node:10-slim </em>image), orchestrated by Nomad and given 256Mhz of CPU and 128Mb of memory.</p><p>In order to get to around 500 Requests/sec we deployed 700 containers, those services could process these requests at an astonishing rate of &gt;1 Request/sec per instance. <strong>Meaning 179,200Mhz (179.2Ghz) CPU and 89,600Mb (89.6Gb) memory is reserved for this process ALONE on our cluster! </strong>(that and we’re barely hitting the half mark of the allowed rate for this API)</p><p>Now. I’m willing to acknowledge this service is not optimized for speed, <em>or maybe at all</em>, but it worked great for our ongoing use case.</p><p>Some notes regarding the lack of optimization for the curious folks.</p><ul><li>Input messages were read from Amazon SQS one by one.</li><li>Output records were written to Kinesis Firehose one by one.</li><li>Barely any asynchronous code (remind me, why did we use Node here if we’re not utilizing its strengths?)</li></ul><figure><img alt="an animated slug trying to run but moving very slowly" src="https://cdn-images-1.medium.com/max/250/0*OzBmhRoF3I1mBksf.gif" /></figure><h3>Optimizing the NodeJs service</h3><p>Knowing I’m (not) a NodeJs expert, I started this adventure by putting my thinking cap on and getting my best rubber ducky to debug whatever code I might produce and started optimizing.</p><figure><img alt="Similarweb branded rubber duckies" src="https://cdn-images-1.medium.com/max/300/0*wF4kib32OwNoYyNc.jpg" /></figure><p>First things first, the simple fixes. Increasing the number of messages pulled from SQS at a time, from 1 to 10. I did it to save some time on the network overhead of each call. Batch puts to Kinesis Firehose were another easy fix that saves tons of time on network overhead, because in this case you can batch up to 500 messages at a time.</p><p>With the simple fixes out of the way I had to get some proper asynchronicity into this service. This is where my thinking cap came into play and I started looking into a way to process the 10 messages I was now getting on every pull from SQS.</p><p>In my search for an efficient way to work asynchronously I came across the workerpool package. And by looking at the documentation it seemed just perfect, I mean look at the features:</p><ul><li>Easy to use (<em>you love to hear it</em>)</li><li>Runs in the browser and on node.js (<em>NodeJs</em> <strong>✓</strong> )</li><li>Dynamically offload functions to a worker (<em>exactly what I’m looking for</em>)</li><li>Cancel running tasks (<em>great in case of a premature shutdown</em>)</li><li>Set a timeout on tasks (<em>good to put up boundaries</em>)</li><li>Handles crashed workers (<em>shit happens</em>)</li><li>Small: 5 kB minified and gzipped (<em>*chef’s kiss*</em>)</li></ul><p><a href="https://www.npmjs.com/package/workerpool">https://www.npmjs.com/package/workerpool</a></p><p>Told you. <strong>its perfect!</strong></p><p><em>*Foreshadowing warning*</em></p><blockquote><strong>In Node.js everything runs in parallel, except your code. What this means is that all I/O code that you write in Node.js is non-blocking, while (conversely) all non-I/O code that you write in Node.js is blocking.</strong></blockquote><p>Did I mention that I’m no NodeJs expert?</p><p>The problem I encountered with this package though, was a <em>DataCloneError</em> whenever I attempted to use functions from other files in the project. Basically those functions went unrecognized by the workers and could not be serialized.</p><p>NEXT!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*P1moROybmWga3yF2.jpg" /></figure><p>Why use a fancy package to do it for me when I can start the number of workers I need and reuse them?</p><h3>What I ended up doing</h3><p>In each instance I start, let’s say 5 worker threads (<a href="https://nodejs.org/api/worker_threads.html">https://nodejs.org/api/worker_threads.html</a>), each thread runs in a loop as long as there are messages to process. Each thread reads 10 messages and processes them asynchronously by offloading the processing to another function. The threads run said function asynchronously for each message and then block while waiting for them to finish. Meaning we now have 50 messages being processed asynchronously, <strong>up from 1!</strong></p><h3>One more thing</h3><p>If you read the foreshadowing warning a few paragraphs ago you might have guessed about the main problem with using NodeJs for this workload.</p><p>NodeJs is great for IO, which is what we have here, right?</p><ol><li>Get messages from SQS. IO</li><li>Getting the data from the external API. IO</li><li>Gzip compressing the data so it’s small enough to be sent over Kinesis Firehose, especially in batches. <strong>NOT IO</strong></li><li>Base64 encoding the data to be sure it’s of a valid format for transfer through Kinesis Firehose. <strong>NOT IO</strong></li><li>Sending the resulting data to Kinesis Firehose. IO</li></ol><p>Whelp… ⅖ steps are not IO and can only be optimized by horizontally scaling the service.</p><p>All my efforts were rewarded though. With just under 2 Requests/sec per instance processing time. <strong>2x faster than before. ~300 containers down from ~700.</strong></p><p>But…</p><p>Some wise words from a python core contributor Raymond Hettinger came to mind.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/0*tenzC2mg318PHjx1.jpg" /><figcaption><em>Fooled ya! No python will slither its way into this post :)</em></figcaption></figure><h3>Rewriting in Go</h3><p>Another language I’m familiar with and am actually more fluent in is <strong>Go</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/0*_ZIhNSmI--jz7K1S.jpg" /></figure><p>It’s a language with a great standard library, amazing community and most importantly for this specific case, Go can handle non IO tasks <strong>efficiently</strong>.</p><p>After you’re done reading you might want to check it out here:</p><p><a href="https://golang.org/">https://golang.org/</a></p><p>There’s a nice tour you can take in order to discover all the amazing features this language has. And when you’re done you can play around with Go right there in the playground, no installation or download required.</p><p>Back to business.</p><p>This service, just like our original service runs in a docker container (<em>golang:1.13.4-alpine </em>image), is orchestrated by Nomad and given 1000Mhz of CPU and 512Mb of memory.</p><h4>Some basic Go terminologies</h4><p><strong>Goroutine</strong> — <em>A goroutine is a lightweight thread managed by the Go runtime</em>. You can start a goroutine simply by using the go keyword. e.g. <em>go SomeFunction()</em> <a href="https://tour.golang.org/concurrency/1">https://tour.golang.org/concurrency/1</a></p><p><strong>Channels</strong> — Channels are a typed conduit through which you can send and receive values with the channel operator, &lt;- <em>By default, sends and receives block until the other side is ready. This allows goroutines to synchronize without explicit locks or condition variables</em>. This is the behavior of an <strong>Unbuffered</strong> Channel. <a href="https://tour.golang.org/concurrency/2">https://tour.golang.org/concurrency/2</a></p><p><strong><em>Buffered </em>Channels</strong> — This type of channel has an internal buffer of a predefined size, meaning messages can be put in it and be received in a later time. Or in other words, <em>sends to a buffered channel block only when the buffer is full. Receives block when the buffer is empty</em>. <a href="https://tour.golang.org/concurrency/3">https://tour.golang.org/concurrency/3</a></p><h4>Initial Design</h4><p>Using these basic built in features we can achieve greatness. Goroutines for concurrency, channels for synchronization and communication between goroutines.</p><p>Before we get to the design schematic please refer to the legend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*KZYcaTY5T3XIndAZ.jpg" /></figure><p>The initial design schematic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iq-ZhfVJBACdf9NK.jpg" /></figure><p>What we have here is a single goroutine reading messages from SQS, 10 at a time and putting them into <strong>A,</strong> an unbuffered channel. Listening to that channel is a single goroutine who’s job consists of parsing every message into something we can use and passing it on into <strong>B</strong>, another unbuffered channel. Reading from it are multiple goroutines that will process all incoming messages.</p><p>At this point any available goroutine will pull a message from <strong>B</strong>, process it and put the result into <strong>C</strong>, a buffered channel that has an internal buffer size matching the batch size we use when putting messages into Firehose. Due to message size constraints in this case I limited the batch size to 50.</p><p>On the other hand, if all message processing goroutines are busy processing messages, the parsing goroutine will block on send to <strong>B </strong>(no one is ready to receive from it), which in turn will lead to the message receiving goroutine to block on send to <strong>A</strong> for that same reason.</p><p>SQS message reading and message parsing goroutines will unblock as soon as any processing goroutine will be ready to receive a message from <strong>B.</strong></p><p>This redesign and rewrite resulted in a significant improvement over our initial NodeJs service. We got to ~700 Requests/sec (up from 500) with 25 instances (down from ~300). Or around <strong>28 Requests/sec per instance</strong></p><p>If you’re still following along, this translates to:</p><ul><li>More than x14 improvement in per instance processing speed.</li><li>Total allocation of 25Ghz (down from 179.2Ghz) CPU and 12.5Gb (Down from 89.6Gb) memory, that is more than x7 decrease in CPU and memory allocation compared to our original service.</li></ul><p>Now this is fast! And as a bonus to the performance boost we are saving some serious dough ($$$) with the reduction in resource allocation.</p><p>Finally! I was done and could move on to my next task for that iteration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*kmOM6lWD-PBGYs29.gif" /></figure><p>Or so I thought.</p><p>On second glance the way this service works reminded me of something I heard about a while back. <strong>The pipeline pattern</strong> in Go. <em>There’s no formal definition of a pipeline in Go; it’s just one of many kinds of concurrent programs. Informally, a pipeline is a series of stages connected by channels, where each stage is a group of goroutines running the same function. </em>(<a href="https://blog.golang.org/pipelines">https://blog.golang.org/pipelines</a>)</p><p>Sounds a lot like what is shown in the design schematic, but we’re not there yet, not exactly. We do have a series of stages connected by channels. But only one of our stages is a <strong>group </strong>of goroutines, other than that we have single goroutines doing the work.</p><h4>Pipeline pattern, the right way</h4><p>In addition to using groups of goroutines over single goroutines in most stages, I decided on switching to buffered channels. The reason I switched to buffered channels was because I wanted to save time on overhead for each stage.</p><p>For example: if all processing goroutines are busy, we used to have the parsing goroutine block and wait for someone to be ready to receive a message from it. Meaning the parsing work will only be done when someone is ready to process the message. Using a buffered channel we can “pre-parse” lots of messages even if no goroutine is available to process them at the moment. This way we won’t have to wait for the parsing to happen whenever a processing goroutine is ready for it because we already banked a bunch of parsed messages in the buffer.</p><p>The overhead is even worse when it comes to the goroutine reading messages from SQS, the network overhead is far larger than the overhead we experience when parsing.</p><p>The final design schematic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0bRRLCSrfWuwMeAq.jpg" /></figure><p>For the following explanation let’s define X=10.</p><p>As you can see, this schematic doesn’t look that different from the initial one.</p><ul><li>X goroutines are reading messages from SQS (each 10 at a time) and putting them into channel <strong>A</strong>, a buffered channel of size X*10.</li><li>X goroutines are parsing the messages from channel <strong>A</strong> before passing them on to channel <strong>B</strong>, a buffered channel of size X*10.</li><li>75 goroutines read the parsed messages and process them (75 is a number I got to by benchmarking performance for different values). The value is then put into channel <strong>C</strong>, a buffered channel of size 50 to match the batch size we use when putting messages into Firehose.</li><li>Only 2 goroutines are reading those results and putting them into Firehose in batches of 50. 2 goroutines are enough for the job because batch puts happen less frequently, once every 50 results.</li></ul><p>These simple optimizations resulted in even more improvements over our simpler Go service. We ended up with <strong>~840</strong> Requests/sec (up from ~700) with <strong>17</strong> instances (down from 25). Or around <strong>50 Requests/sec per instance.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*33vDCskLWFjL8lhx.gif" /></figure><h3>Conclusion</h3><p>Comparing our final version to the first version of the Go service we can see nearly x2 improvement in processing speed, or <strong>x28 compared to our original NodeJs service</strong>, and total allocation of 17Ghz (down from 25Ghz) CPU and 8.5Gb (Down from 12.5Gb) memory. That is more than a <strong>x10 decrease compared to our original NodeJs service</strong>.</p><p>The number of calls we need to make can vary from month to month, it might end up being 150, 160 or even 170 Million calls. But with our newfound speed we are able to go through the whole list in just over 2 days!</p><p>What this all demonstrates is that you should always strive to find and use the right tool for the job. Going with the easy solution would have ended up costing us at least 8 times more than what we ended up paying for the used resources in our final version.</p><p>Some key takeaways :</p><ul><li><em>NodeJs</em> is great for asynchronous IO operations but falls short when it comes to CPU intensive work.</li><li><em>Go</em> can handle both CPU intensive <strong>and </strong>concurrent workloads well.</li><li>Picking the right tool for the job is one of the most important decisions you will make in any project.</li><li>The pipeline pattern is a simple way you can dramatically speed up your services.</li></ul><h3>What’s next?</h3><p>There are further optimizations possible. Using the GOGC and GOMAXPROCS environment variables we can speed up each container even more. Optimizing the service using these environment variables will speed up each container but will require more allocated CPU/Memory.</p><p>For more information about these and other useful environment variables, check out Dave Cheney’s blog <a href="https://dave.cheney.net/tag/gogc">https://dave.cheney.net/tag/gogc</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dfe45fd6b6b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/similarweb-engineering/moving-from-nodejs-to-go-doing-more-faster-for-less-1dfe45fd6b6b">Moving From NodeJs To Go — Doing More, Faster For Less</a> was originally published in <a href="https://medium.com/similarweb-engineering">Similarweb Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>