<?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 Emin Laletovic on Medium]]></title>
        <description><![CDATA[Stories by Emin Laletovic on Medium]]></description>
        <link>https://medium.com/@elaletovic?source=rss-3247ea22dc68------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ir1OrmbmYJZ3SBhx8uIT0g.png</url>
            <title>Stories by Emin Laletovic on Medium</title>
            <link>https://medium.com/@elaletovic?source=rss-3247ea22dc68------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 13:33:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@elaletovic/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[When Kubernetes and Go don’t work well together]]></title>
            <link>https://medium.com/mop-developers/when-kubernetes-and-go-dont-work-well-together-54533bb6466a?source=rss-3247ea22dc68------2</link>
            <guid isPermaLink="false">https://medium.com/p/54533bb6466a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Emin Laletovic]]></dc:creator>
            <pubDate>Fri, 12 Apr 2024 08:15:56 GMT</pubDate>
            <atom:updated>2024-04-15T14:02:59.373Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Go is not aware of the limits set for its container, causing some issues not easy to track. This is a story about how I stumbled into one of them.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*cG6_1bYuVomyjGQGO6BKfg.png" /><figcaption>AI prompt: Gopher breaking a container</figcaption></figure><p>In this article, I will cover a specific issue encountered in one of our production environments, go over the root cause, and a potential resolution. The title hints at the underlying problem, but we will cover the details of what happened.</p><h3>What happened?</h3><p>I got a bug report that there is a 502 Bad Gateway error happening when one of our API service endpoints, in a specific production environment, gets called. The calls for the same API endpoint are successful in all other production environments, just not this one.</p><p>Started with checking the usual stuff. Error logs, nothing. Tried to reproduce it, the issue is still there, but there aren’t any error logs or any other logs, at all. I noticed that the Kubernetes pod container gets restarted each time I call the API service endpoint. The first thought that came to mind was that the service panicked and the container restarted, so there must be logs in the previous pod instance. Checked there, nada. Next, I added more info logs to see where the issue happened exactly. It pointed to the issue happening when the json.Marshal function call was being executed, but there was nothing odd in the code. It was time to dig a bit more.</p><p>I shifted my focus to the Kubernetes pod and how it behaves when the issue happens. While the new pod is starting, I notice that the old pod has the OOMKilled status. OOMKilled? But that’s out-of-memory status when the container inside the pod goes over the defined RAM limit. What the hell is this API endpoint response trying to return?? To be fair, we built this endpoint to retrieve the bulk data for our mobile app so it can work in the offline mode. Even so, I didn’t expect that there would be that much data because these are the resource limits for the API service container:</p><pre># part of the deployment file<br>- name: api<br>  image: gcr.io/xyz/api:989d83a73a9d1605ac601e3ef0fdef5711dcffe4<br>  imagePullPolicy: Always<br>  ports:<br>  - containerPort: 5500<br>  resources:<br>    limits:<br>      cpu: 200m<br>      memory: 400Mi<br>    requests:<br>      cpu: 100m<br>      memory: 200Mi</pre><p>The RAM limit for the API service container is 400 MB. I doubled the RAM limits to see how far this issue goes. The deployment was reconfigured and a new pod with the new container limits was deployed. I triggered the API endpoint again and it returned the response successfully. The size of the response is 66 MB.</p><p>Hmm, the API service container with RAM limits of 400 MB should have been able to handle the 66 MB response with ease. How did it go out of memory then? After reading through some documentation and articles about Go internals (see the references at the end), some hunches about Go’s garbage collector started to form.</p><h3>As Monk would say, here’s what happened…</h3><p>Two things are important to explain how the issue manifests.</p><p>First, the Go’s garbage collector. I won’t go into all the details on how Go’s garbage collector works. I linked some great articles at the end if you want to read more about the details. One important detail for the issue at hand is that Go’s GC expands the heap memory when needed. At each Go’s GC run, it determines if more memory needs to be allocated, and then allocates it.</p><p>Next, this is the part where we go back to the title of this article. When the Go program (as a single process) runs in a container in a Kubernetes pod, by default it doesn’t know the resource limits set for the container it is running in. For example, let’s assume that our container is running on a multi-core machine with 8 GB of RAM. Assuming the heap continually rises, the Go runtime will eventually try to allocate all available memory of those 8 GB, even if other containers are deployed on that same machine, running other processes.</p><p>Combining these facts, we get how the issue manifests. While executing the json.Marshal function, the Go’s GC sees there is a need for more heap memory, and allocates it. It does that repeatedly in several GC cycles. When the process in the container goes over the memory limit (400 MB), the container’s system kernel terminates the process, with an out-of-memory error (OOM).</p><h3>Hunches are fine, but show me the facts</h3><p>Let&#39;s check GC trace logs to get some data on what happened. You can check these logs by setting the environment variable GODEBUG=gctrace=1. There are a few ways to do it, I added it to my Dockerfile.</p><pre>#The last part of the multi-step build<br># Build minimal image<br>FROM alpine<br>COPY --from=0 /go/bin/api /go/bin/api<br>ENV GODEBUG gctrace=1<br># Expose port<br>EXPOSE 5500<br># Run<br>ENTRYPOINT [ &quot;/go/bin/api&quot; ]</pre><p>Looking at the logs below, there is one more thing to note. There is another environment variable, GOGC, that determines how much the allocated heap will grow before the next GC run. GOGC is set by default to 100, which means it will grow by 100%.</p><pre>{&quot;level&quot;:&quot;info&quot;,&quot;msg&quot;:&quot;GetBulkDmsFiles: done&quot;,&quot;time&quot;:&quot;2024-02-25T16:06:08Z&quot;}<br>{&quot;level&quot;:&quot;info&quot;,&quot;msg&quot;:&quot;marshal response&quot;,&quot;time&quot;:&quot;2024-02-25T16:06:08Z&quot;}<br>gc 14 @247.533s 0%: 0.073+195+0.040 ms clock, 0.14+0/10/97+0.080 ms cpu, 138-&gt;138-&gt;117 MB, 138 MB goal, 0 MB stacks, 0 MB globals, 2 P<br>gc 15 @248.448s 0%: 0.061+280+0.041 ms clock, 0.12+0/89/2.9+0.082 ms cpu, 309-&gt;309-&gt;260 MB, 234 MB goal, 0 MB stacks, 0 MB globals, 2 P</pre><p>From the logs, we can see that the heap grows with each GC run. Please note that the last entry has 260 MB, which is what the Go program was able to write before it got terminated. In the next GC run, the heap would grow over 500 MB, more than the 400 MB limit defined in the deployment file for the API service container.</p><h3>Is there a solution for this?</h3><p>Everyone’s favorite answer, it depends. Some will prefer to leave this as is, to have a container that fails fast, not to tinker with how the GC works, and to deal with the functionality itself. This API endpoint that returns bulk data could have been rewritten to stream the data back, rather than to send one big response.</p><p>However, if it bothers you that your Go program and Kubernetes are kind of out of sync, there is a way to tune it to work more smoothly. The GOMEMLIMIT environment variable, introduced in Go 1.19, can be used as a soft memory limit for the GC. The OOM can still happen, but the GC will run more aggressively when it reaches the limit and it will make sure to use all of the live heap rather than keep increasing the heap beyond the limit.</p><p>In the API service’s deployment YAML file, I’ve added this environment configuration:</p><pre>env:<br>  - name: GOMEMLIMIT<br>    valueFrom:<br>      resourceFieldRef:<br>        resource: limits.memory</pre><p>The GOMEMLIMIT is set to whatever is defined as a memory limit in the deployment YAML file. This way, whenever I change the memory limits, the GOMEMLIMIT will be changed accordingly.</p><blockquote>It would be better to be able to define something like “90% of the memory limits”, but there is still no good way to do this, other than maybe using requests.memory. This <a href="https://github.com/kubernetes/kubernetes/issues/91514">issue</a> is still open. The <a href="https://github.com/KimMachineGun/automemlimit">automemlimit</a> library does that (and more, with cgroups), but it has to be included in the code.</blockquote><p>When I call the same endpoint, it returns the response successfully. Here are the GC logs and what the memory looks like before and after the call.</p><pre>{&quot;level&quot;:&quot;info&quot;,&quot;msg&quot;:&quot;GetBulkDmsFiles: done&quot;,&quot;time&quot;:&quot;2024-02-25T16:31:01Z&quot;}<br>{&quot;level&quot;:&quot;info&quot;,&quot;msg&quot;:&quot;marshal response&quot;,&quot;time&quot;:&quot;2024-02-25T16:31:01Z&quot;}<br>gc 18 @92.420s 0%: 0.053+190+0.097 ms clock, 0.10+0/98/95+0.19 ms cpu, 115-&gt;115-&gt;93 MB, 125 MB goal, 0 MB stacks, 0 MB globals, 2 P<br>gc 19 @93.019s 0%: 0.066+102+0.035 ms clock, 0.13+0/4.0/89+0.071 ms cpu, 189-&gt;189-&gt;165 MB, 186 MB goal, 0 MB stacks, 0 MB globals, 2 P<br>{&quot;level&quot;:&quot;info&quot;,&quot;msg&quot;:&quot;marshal response done&quot;,&quot;time&quot;:&quot;2024-02-25T16:31:02Z&quot;}<br>gc 20 @93.821s 0%: 0.066+193+0.004 ms clock, 0.13+0/2.6/3.6+0.009 ms cpu, 359-&gt;359-&gt;197 MB, 330 MB goal, 0 MB stacks, 0 MB globals, 2 P<br>{&quot;level&quot;:&quot;info&quot;,&quot;msg&quot;:&quot;response writer write done&quot;,&quot;time&quot;:&quot;2024-02-25T16:31:10Z&quot;}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xRBEB8ltD7z0JiINBS-_4A.png" /><figcaption>API service memory dashboard</figcaption></figure><h3>Final thoughts</h3><p>The presented solution is no silver bullet. There are scenarios where failing fast with the default settings is preferable to squeezing all the juice from the heap before the process is terminated with the OOM error.</p><p>That being said, the presented solution might help with better resource utilization, especially when multiple services are deployed on the same machine.</p><p>There are great articles about this topic already out there. I found out about them kinda late, it would have saved me a lot of time (by not writing this one haha). You should read it to get even more familiar with the topic. I’ve included them in the references below.</p><p>Please let me know if there are similar and more elegant solutions to tune your Kubernetes resources and Go programs, I would like to hear about it!</p><h3>References</h3><ul><li>Ardan Labs article about tuning the CPU limits (I got the idea from there) — <a href="https://www.ardanlabs.com/blog/2024/02/kubernetes-cpu-limits-go.html">https://www.ardanlabs.com/blog/2024/02/kubernetes-cpu-limits-go.html</a></li><li>A cool article about GOMEMLIMIT that has way more details — <a href="https://weaviate.io/blog/gomemlimit-a-game-changer-for-high-memory-applications">https://weaviate.io/blog/gomemlimit-a-game-changer-for-high-memory-applications</a></li><li>Ardan Labs article about the same topic — <a href="https://www.ardanlabs.com/blog/2024/02/kubernetes-memory-limits-go.html">https://www.ardanlabs.com/blog/2024/02/kubernetes-memory-limits-go.html</a></li><li>The article on the same topic — <a href="https://billglover.me/2022/09/14/use-the-kubernetes-downwards-api-to-set-gomemlimit/">https://billglover.me/2022/09/14/use-the-kubernetes-downwards-api-to-set-gomemlimit/</a></li><li>A guide to the Go’s garbage collector — <a href="https://tip.golang.org/doc/gc-guide">https://tip.golang.org/doc/gc-guide</a></li></ul><p><strong>…</strong></p><p><em>Ministry of Programming is a supercharged remote-optimized venture builder specialized in building startups and new products💡 We were voted in the top 1000 fastest growing companies in Europe by Financial Times.</em></p><p><em>We offer product management, design, development, and investment services to support entrepreneurs and startups towards product success.</em></p><p><em>If you want to work with us on your startup feel free to contact us at — </em><a href="https://ministryofprogramming.com/contact/"><em>https://ministryofprogramming.com/contact/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54533bb6466a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mop-developers/when-kubernetes-and-go-dont-work-well-together-54533bb6466a">When Kubernetes and Go don’t work well together</a> was originally published in <a href="https://medium.com/mop-developers">Ministry of Programming — Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a graph from your event-stream with Go and ArangoDB]]></title>
            <link>https://medium.com/mop-developers/build-a-graph-from-your-event-stream-with-go-and-arangodb-d02b7e8d1a61?source=rss-3247ea22dc68------2</link>
            <guid isPermaLink="false">https://medium.com/p/d02b7e8d1a61</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[arangodb]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Emin Laletovic]]></dc:creator>
            <pubDate>Sun, 10 May 2020 04:26:39 GMT</pubDate>
            <atom:updated>2020-05-10T04:26:39.903Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Is this one of those “Amplitude vs Mixpanel” catfights? No, this is the “build-your-own vs use-existing-tools” everlasting struggle.</em></p><p>I exaggerated a bit with the intro. There will be no deep dives, no excruciating comparisons, no this versus that in this article. Not that kind of article. This is just a description and a walkthrough of a fun research project I did, with some conclusions that stemmed from it.</p><p>In this article, we will go through a possible need for analyzing your event stream, how to build a graph from your event stream, and describe a service that will do all of the work. Finally, we will review some conclusions that I made while working on this project. All of this will be observed from a standpoint of events that are generated by the user actions in an application or a system.</p><h4>The problem with events</h4><p>If your system is generating events that are stored or processed by some part of your system, there is a very good chance that a stream of some of those events could represent user behavior. There is a good chance that your event store contains, or will contain, the information you need on the behavior of your users.</p><p>The problem is that an event store, an event stream, or any type of series of events are really hard to analyze by just looking at them. Sure, you can write a function, one or many services, that will process events. You can even use already existing tools, frameworks, platforms like Amplitude or Mixpanel. All of the mentioned means are very good options if you know what you are looking for. User retention charts and diagrams are just a few steps away with some of the mentioned tools and platforms, but you will need to know which events to include in your charts and diagrams.</p><p>You can even generate the data from your event stream and store it in a relational database, but you will run into the same problem. You will have to know what you are looking for while writing a query. You can check out the ERD diagram, which shows you the relations between different tables, but it doesn’t provide the bird’s-eye view on how the actual data is linked.</p><p>Is there another way to do all of the above? Yes, we can build a graph. A graph will also provide a bird’s-eye view of all the data and how it’s all linked together. We won’t go into much detail on graphs in this article, but here is a definition of what a graph is.</p><blockquote>In discrete mathematics, a graph is defined as set of vertices and edges. In computing it is considered an abstract data type which is really good to represent connections or relations — unlike the tabular data structures of relational database systems, which are ironically very limited in expressing relations.<br> A good metaphor for graphs is to think of nodes as circles and edges as lines or arcs. The terms node and vertex are used interchangeably here. Usually vertices are connected by edges, making up a graph. Vertices don’t have to be connected, but they may also be connected with more than one other vertex via multiple edges. You may also find vertices connected to themselves. — taken from the ArangoDB crash course</blockquote><p>So, a vertex (or a node) is a fundamental unit of a graph. An edge is also a fundamental unit of a graph that is linking two vertices. From a relational database standpoint, a vertex is like a table row and an edge is a relation between table rows either from the same or different tables. With this structure, graphs are built for edge traversals and relationship searches between vertices.</p><h4>How to go from events to a graph?</h4><p>It’s quite simple. When designing a service or a function that does the actual conversion, you will have to keep in mind a couple of things. To describe the process, I will be using some of the events from the service I built. You can find a detailed description of the service <a href="https://github.com/elaletovic/events-to-graph">here</a>.</p><p>Before you start with building a service (or a function) that will convert the event data from your event stream or your event store to graph data, you will have to go over all of your events and sort them into two groups: creational events and relational events.</p><p>A<strong> creational event</strong> is a type of event that is a direct result of an action that created a new entity in your domain model, a direct result of some action that adds a new piece of data. For example, events like user_registered or item_created. Events like these will be converted into corresponding vertices when added to a graph. In addition to creating a vertex in the targeted graph, events that have a potential created_by link will have an additional side-effect of creating an edge between two vertices. An example of this case is item_created event. This should only be taken into consideration if a specific event is not generated when the link between an object and its creator is created. This is not covered in the <a href="https://github.com/elaletovic/events-to-graph">example service</a>, but it’s worth mentioning that side-effects like these need to be considered if they are not covered by separate events.</p><p>A<strong> relational event</strong> is a type of event that creates a relation between two entities. For example, events like item_viewed, item_purchased, item_delivered, etc. The events like these will be converted into edges that will either create a link between two vertices or link a vertex to itself.</p><p>That’s it! Now that you have sorted our events, it’s time to pick your tools, libraries, and graphs for building your conversion service or a function.</p><h4>Project overview</h4><p>There will be no deep dives in tools, libraries, programming languages, and available graph databases. Use whatever tools, libraries, programming languages you are comfortable with. To choose a graph database you want, there is an abundance of resources out there like <a href="https://www.g2.com/categories/graph-databases">comparisons</a> and <a href="https://db-engines.com/en/ranking/graph+dbms">rankings</a>. Just please check for compatibility between graphs and languages, drivers, libraries, etc.</p><p>In this section, we will go over my choices for this project. Go is an obvious one because I love Go and that’s that. I used <a href="https://watermill.io/">watermill</a> library in some of my work-related projects and it’s been a great experience. To be fair, there is a bit of learning curve behind it, but it provides a big variety of functionalities for event-driven scenarios. This time, I used it to create a little “random” event generator and to simulate a stream of incoming events. By using the watermill’s GoChannel structure both as a publisher and a subscriber, I was able to create a pipeline that generated events through multiple queues, which were then processed by corresponding handlers.</p><p>For a graph database, I choose <a href="https://www.arangodb.com/">ArangoDB</a>. It had everything I needed in a graph database. And more. It’s a multi-model database, fairly easy to set up, and well documented. It has an easy-to-learn query language (AQL), easy-to-use Go driver, cool web interface to work with, etc. Best of all, it’s a schema-free graph database, so it’s very flexible. You can store data on the edges as well, which is pretty cool. To be fair, this is nothing new as many existing graph databases have this feature.</p><p>Below you can take a peek at how the graph is created.</p><p>To access all of the code, please visit my <a href="https://github.com/elaletovic/events-to-graph">repo</a>. There is a docker-compose setup there that will initialize service and database containers, and run the service that will generate the events and convert them to graph data. Detailed steps to access the ArangoDB web interface and manage the graph data are described in the repo. When the service is finished, the graph should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3bqXDyNBAnwwo3NY-EG-6Q.png" /><figcaption>full graph loaded, without names of the edges</figcaption></figure><h4>Conclusion and a reality check</h4><p>Graphs provide a flexible way to analyze and query your data as they are built for searching. But, is it something that will disrupt the current scene of data analytics tools? Are we on the verge of a new build-your-own craze like it was with the Javascript frameworks not long ago?</p><p>The short answer is no. Not yet at least. Since most of the scenarios focus on user retention and basic product analytics, the best way to quickly set up your data analytics pipeline is to use platforms like Amplitude, Mixpanel, etc. They are easy to set up, have a lot of options and services to offer for analyzing your data and observing user behavior, and have great support when you get stuck.</p><p>However, graphs are slowly making it as an important contender in the database world. They certainly have their use and have widespread usage in analytics as well, but they might be a better fit for more mature products and projects. Taking this project showcase as an example, the setup doesn’t have a plug&amp;play flow as the mentioned platforms. There are some things to consider when trying to convert event data to graph data, like sorting out and mapping events. It’s much easier if you have an event store or a replayable event stream, but it does take a significant amount of time, which might not be suited for startups and projects in their early stages.</p><p>To conclude, converting your event stream data to graph data has a lot of potential. I had a lot of fun working on this project and learning about ArangoDB. This has been a showcase of one possible way of converting event data to graph data. I would appreciate it to hear from you on other ways to do it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d02b7e8d1a61" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mop-developers/build-a-graph-from-your-event-stream-with-go-and-arangodb-d02b7e8d1a61">Build a graph from your event-stream with Go and ArangoDB</a> was originally published in <a href="https://medium.com/mop-developers">Ministry of Programming — Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Performance improvement efforts — the dreaded side of software development (part 2)]]></title>
            <link>https://medium.com/mop-developers/performance-improvement-efforts-the-dreaded-side-of-software-development-part-2-44bd522a3fd5?source=rss-3247ea22dc68------2</link>
            <guid isPermaLink="false">https://medium.com/p/44bd522a3fd5</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Emin Laletovic]]></dc:creator>
            <pubDate>Thu, 07 Nov 2019 16:37:35 GMT</pubDate>
            <atom:updated>2019-11-07T16:37:35.276Z</atom:updated>
            <content:encoded><![CDATA[<h3>Performance improvement efforts — the dreaded side of software development (part 2)</h3><p><em>In the </em><a href="https://medium.com/mop-developers/performance-improvement-efforts-the-dreaded-side-of-software-development-4dfe2b41dd93"><em>first part</em></a><em> we went over the performance improvement effort 101, the factors to consider when planning such effort, as well as a devised checklist on what to consider when jumping in at the deep end of performance improvement waters. This part will focus on the real world example and how flexible the mentioned checklist might get.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NxtR0sqy0UbP7SuLUCrIWw.jpeg" /><figcaption>There, all fixed and patched up</figcaption></figure><p>The example is from a recent performance improvement effort that I have been involved in. I was tasked to improve performance for a functionality in a trading application that has been driving users crazy for some time.</p><p>In this part, we will cover:</p><ul><li>the problem and how the performance degradation occurred</li><li>the planning factors that were considered for this example</li><li>the checklist for phase 1 and show results</li><li>the checklist for phase 2 and show results</li></ul><p>So without further ado, let’s dive in.</p><h3><strong>The problem</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3KZZQMIAVVwrbZERF24cFA.jpeg" /><figcaption>Uhmm, it’s a natural phenomenon, I’m sure it will pass…</figcaption></figure><p>Sometimes it feels like we don’t know how a performance degradation occurred in the first place and how we got to that point in our apps life-cycle. However, that’s not really true. We have already talked about one of the reasons for performance degradation in the first part. Reasons might include the lack of development skills and experience, budget and time to produce quality solutions. Hacking up a solution to get to the market as quickly as possible, but later failing to take time to improve and scale properly. The list goes on and on, but for this example it was about the unfamiliarity with inner behaviour of the 3rd party component.</p><p>In this article, we will observe a charting functionality of currency pairs. Since we are building a trading app, one of the main features is to enable users to track how currency pairs (for example, EURUSD) have behaved over time. The charting library on the frontend side is able to show how currency pairs have behaved over observable periods of time, having an option to choose between several observable periods (periods of 1,5,15 minutes, etc.). These periods in our chart functionality are called ticks and they have their open, close, high and low-price values. The library is polling the data from our server every 0.5 second and you are able to go back in time as lazy loading is enabled as well.</p><p>So, how was it built in the first place?</p><p>We built a proxy server, that used a 3rd party library for communication with the trading data server (that was not controlled by us). So, when users polled for the charting data, we have just relayed those calls to the trading data server and served the response. This would have worked out well if the trading data server hadn’t been used for other things as well. The main reason we had performance degradations wasn’t even one of the reasons mentioned previously. We were unfamiliar with how trading data server worked behind the scene. It was built in a way that it would, while under a high load, decrease a priority for chart data requests. If you take this fact into consideration, factor in the frontend charting library’s polling mechanism and multiply it with tens of thousands of users using this functionality when the trading market is hot, you get a disastrous effect of polling calls lasting for 5-10, sometimes even 15 seconds each. To put it mildly, it was a slow, sluggish and a very frustrating experience for users.</p><h3><strong>The plan and planning factors</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMD9hDJJX-MG8HZU9CVxqA.jpeg" /><figcaption>…something corny like “If you fail to plan, you plan to fail!” :)</figcaption></figure><p>Let’s go over the planning factors first. By the time I got tasked with this endeavor, users have gotten used to charts behaving poorly and didn’t complain as much as before. Also, since I was the only one involved in this effort, I could assume this was not a red hot “Earth will be scorched unless you fix it” priority. That was not to say I had all the time in the world. I figured that I maybe had two months to get this done and show some results before I got hard-pressed about it. I didn’t have a tight budget, but I could not get flashy with it as well. Let’s just say that I had the option to choose the technologies and other resources as long as it looked fairly reasonable.</p><p>With this in mind, the initial plan was:</p><ul><li>Still use the proxy server, but as a secondary source of data. Save data in my own data stores optimized for reading (read stores). With just my services using the proxy server, it should not have the same performance issues, as the number of instances that are using the proxy server would be limited.</li><li>Choose Go for building services for serving and processing the charting data, Cassandra to build read models and store the charting data in them, Redis for caching.</li><li>Utilize all other services and components that already exist in the system.</li><li>Roll out as fast as I can with steady performance results, do further improvements in later iterations afterwards.</li></ul><h3><strong>Phase 1 — go over check list and results</strong></h3><p>To give you a taste of the journey this endeavor has taken me on, we will go over the checklist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QEe2Ts6H_h5HkMEk-Pm1Dg.jpeg" /><figcaption>See?? Almost a straight line!</figcaption></figure><p><strong>Time to plan</strong></p><p>About one fourth of the entire length of this performance improvement effort went into the planning and solution design phases. Almost half of that was spent on planning. That included the current solution investigations, research for potential technology usage and evaluation against the current skill set. The last one took the most time out of researching because it was important that, if I was about to use technology, framework and/or a library I previously had zero experience with, I would assess the learning curve to prevent the potential misuse of the same. I have already mentioned that I have considered Go and Cassandra. Although I’m confident that I can build pretty much anything with Go, that wasn’t the case for Cassandra. By evaluating the existing learning resources, I determined that I would be able to quickly learn the needed skills to design and build a proper solution.</p><p><strong>Time to design a proper solution</strong></p><p>So, I chose to go with Go and Cassandra. And I took my time designing the architecture. I spent most of the time designing the read models. I didn’t have a problem with writing to the read stores. As for reading from the read stores, I wanted to do it as quickly as possible, minimising the number of trips to the read stores. Also, I wanted to use the fact that time to retrieve an entire partition in Cassandra is almost constant because of the consistent hashing of partition keys. With this in mind, and with a proper management of the read stores, I would be able to have a solid base for any future improvements.</p><p><strong>Take measurable and comparable data</strong></p><p>Unfortunately, I didn’t do any profiling at the beginning of this improvement effort. All I had was the reports from users. Comparable data would have certainly come in handy later, both for comparisons and for reports. Comparable metrics were taken at the end of phase 1. To tell you the truth, I have just deemed this checklist item as very important during this performance improvement effort and during this phase.</p><p><strong>Build a solution that is able to scale easily</strong></p><p>This is where the almost constant time for read store partition reads comes into play. The solution was to separate each tick into a separate table, with partitions configured to suit that specific tick. Data retrieval was done by fetching data from one partition, two in the worst-case scenario (which happened maybe 20% of the time). This would set a solid foundation for any future improvements.</p><p><strong>Break down delivery to smaller deliverable chunks</strong></p><p>I have to say, when designing a solution like the one described above, I could have put a lot more effort into the delivery planning. I didn’t. Designing the read models aside, most of the effort was spent on writing the code for the services. The solution couldn’t really work without all of the services working properly, so I have easily dismissed delivering smaller chunks and went with one big push. Looking back now, I could have spent some more time breaking up the delivery of the solution. I would have been able to go with several deliveries, with 1–3 days between deliveries. It doesn’t look as much, but I would have started delivering and deploying to production at least a week before the entire functionality was pushed.</p><p><strong>Communicate, communicate, communicate</strong></p><p>Without the comparable data measured prior to starting this improvements effort, and without smaller deliverable chunks planned, there was really not that much information to put in the reports. All I was left with was to write the boring kind of reports, like “building services is at 30%” or “building read stores is at 45%”. Within the reports, I have also communicated future plans, ETA changes and roadblocks. Without having the measurable data and smaller deliverable chunks to make these reports more interesting, this kind of reports tend to be on the boring side. You can guess how excited the top brass is to read your long boring reports.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ywL-kVLzXCZX33-EGD9AyQ.png" /><figcaption>yes, yes, well done, kudos!</figcaption></figure><p>To sum up the checklist above, <em>the solution was delivered in two months, with immediate results. Users were happy. Or at least, they weren’t complaining</em>. With metrics below, of course.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*Q48Z6DgXyp72NUcCqB3NVA.png" /><figcaption>table histogram for 1-minute table</figcaption></figure><h3><strong>Phase 2 — trust the process and repeat the steps</strong></h3><p>The success of phase 1 was more than I planned for. The top brass were happy and the users were not complaining. It was reported that load time “felt” better during the busy hours. I hate the word “felt” in this context, but it was all I’ve had without any measurable data taken at the beginning of phase 1.</p><p>During the supporting stage of the phase 1, I have noticed some potential improvements, so I was keen to tackle them as soon as I had some time to spare. So, without further ado, let’s go over the checklist for phase 2.</p><p><strong>Time to plan</strong></p><p>Learning from the mistakes I made in the last phase, the main focus this time was breaking the work down into smaller deliverable chunks. I was doing these improvement efforts between other assignments, I did not have more than a couple of days to spare on this. So, the plan was to break the work down into chunks that could be worked on and tested in a day or two.</p><p><strong>Time to design a proper solution</strong></p><p>At the end of phase 1, I have looked into how the client-side charting library works in more detail. For every tick, when charts are loaded, there are two stages. The first one was loading a bigger chunk of data, for going back and forth through the timeline. The second stage is polling for a set of the current values, a much smaller chunk of data (last ten tick bars). This was hardly optimal, as we are retrieving the entire partition for those ten ticks and the current timestamp. As you can see from the table histogram above (taken at the end of phase 1), that’s about 24–35 KB of data pulled from the database just to take 10 tick bars. The new solution included having two tables for each time-frame; one for retrieving bulk data which would be used for the initial load and another one for polling that would have a much smaller partition.</p><p><strong>Take measurable and comparable data</strong></p><p>I wouldn’t make the same mistake twice. Before deploying the new improvements, I took the comparable data metrics of the current solution to compare it to the new one. The table histogram above is the result of phase 1. Below is the result of phase 2 improvements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*B763kTvxoaQsIKh-ZHRISQ.png" /><figcaption>table histogram for 1-minute table used for polling</figcaption></figure><p><strong>Build a solution that is able to scale easily</strong></p><p>As you can see from the table histogram above <em>Read latency</em> and <em>Partition size</em> numbers for the polling functionality were drastically reduced. The solution from phase 1 cleared the way for easy additions and minor tweaks to improve performance even further.</p><p><strong>Break down delivery to smaller deliverable chunks</strong></p><p>As the main focus of the planning effort for this phase, new solution was delivered in smaller chunks. Each of the deliverables contained changes for only one tick. The effort to code and deploy each deliverable was about a day or two.</p><p><strong>Communicate, communicate, communicate</strong></p><p>Since deliverables and effort to deliver them were smaller altogether, the need for constant updates was redundant. The reports simplified as well as it took just two days to go from starting the development work to production deployment.</p><h3><strong>Conclusion</strong></h3><p>Performance improvement efforts vary from five-minute fixes to refactoring efforts spanning several months. They could mean just plugging a leak somewhere in your code or they could mean having the entire architecture evaluated and refactored. Maybe you, or someone from your team noticed it, or your users were complaining. The point is, it varies from one case to another and you cannot have a bulletproof checklist to handle every case the same. That doesn’t mean that there should not be some general guidelines to follow. The list I used is something I’ve compiled over the years and, as you could clearly see, sometimes even I have omitted a guideline or two.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28mfKzfpUHTG7sh1DqcNeA.jpeg" /><figcaption>Mirror, mirror, on the wall, which guidelines should I use, if any at all??</figcaption></figure><p>Basically, it boils down to this:</p><ul><li>You need to give yourself enough time to investigate the issue and create a general plan around that investigation. Implementing fixes based on hunches and guesses can sometimes work or buy you some time, but they can also lead you down the “nothing to show for” rabbit hole.</li><li>After the investigation, the general plan should be developed into a detailed one, with considered priorities and implications. Sometimes it’s more important to show fast progress than to design a better solution. Sometimes it’s not.</li><li>Everyone needs information about progress during all phases of the improvement efforts, so communication is key. Damage control is as important as fixing the issue.</li></ul><p><em>I would like to hear what you think on this subject. Do you have your own guidelines or do you just wing it? Also, I would like to hear your stories about your performance improvement endeavors, especially the horror stories. Maybe someday there will be a TV show about the gnarliest performance improvement efforts, with Liam Neeson, Morgan Freeman or James Earl Jones as narrators ;).</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44bd522a3fd5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mop-developers/performance-improvement-efforts-the-dreaded-side-of-software-development-part-2-44bd522a3fd5">Performance improvement efforts — the dreaded side of software development (part 2)</a> was originally published in <a href="https://medium.com/mop-developers">Ministry of Programming — Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Performance improvement efforts — the dreaded side of software development]]></title>
            <link>https://medium.com/mop-developers/performance-improvement-efforts-the-dreaded-side-of-software-development-4dfe2b41dd93?source=rss-3247ea22dc68------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dfe2b41dd93</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[time-management]]></category>
            <dc:creator><![CDATA[Emin Laletovic]]></dc:creator>
            <pubDate>Thu, 19 Sep 2019 07:35:42 GMT</pubDate>
            <atom:updated>2019-09-19T08:11:43.314Z</atom:updated>
            <content:encoded><![CDATA[<h3>Performance improvement efforts — the dreaded side of software development</h3><p><em>This is so slow and sluggish! Users have reported slowness when they tried to retrieve the latest from the news feed! The app is experiencing delays with showing real-time data! Usually it’s OK, but the page starts lagging around noon, probably because that is when the most of the users are using it! We are losing money, orders take more time to process than usual! This worked perfectly before the last app updates!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ryHjdmGDsU_P-fLsxfqUw.jpeg" /><figcaption>Users are at your door!</figcaption></figure><p>If you are, or were at any point in your career, assigned to address comments like these, you’ve probably experienced the performance improvement hell week. Or month. Or maybe even a longer period of time. While these comments rarely provide measurable information that is useful for your future investigations, they are not to be ignored. Users, while they subjectively have their own preferences, will mostly provide objective insight about the performance characteristics of your app. That should always be taken into consideration.</p><p>What is this article about, anyway? Take a look at the following two scenarios.</p><p><em>Scenario 1</em>:</p><ul><li>You have reasonably enough time and budget to improve whatever you need to do.</li><li>You know exactly what you need to do and where the problem lies.</li><li>Client/owner is understanding, excited and eagerly and patiently waiting for the results.</li><li>Users are either not aware of it or are understanding about the process required to do this.</li><li>Everyone is super excited when it’s finally delivered and praises come from all corners of management and user realms.</li></ul><p><em>Scenario 2</em>:</p><ul><li>Not Scenario 1</li><li>You are pressed on time and budget because you (or someone else) built and spent money on something that is not working well enough.</li><li>You don’t even know where to start troubleshooting.</li><li>Client/owner is pressuring you to make the service/app/page work faster ASAP.</li><li>Users are not happy because the service/app/page is slow and they are threatening to tweet about it.</li><li>An occasional ”great work!” here and there comes your way after it gets delivered, but usually followed by the afterthought “it should have worked like this in the first place!”.</li></ul><p>Scenario 1 might look like a scenario for building new features, and it is, but it can happen for performance improvement efforts as well. These are called <strong>planned efforts for refactoring and performance improvements</strong>. They are not that rare and they can be seen in startup projects more often than not. Because, cutting corners is what startups often do (I wanted to say occasionally, but we all know that is not true), to get to the targeted market faster. That is okay, as long as you plan (and communicate) for refactoring, scaling and performance improvement efforts, as long as it is a part of your project roadmap, you should be able to address this through continuous delivery and improvement. If you don’t, you can easily fall within the scenario 2 boundaries.</p><p>However, this article is not about what happens in the boundaries of scenario 1. There are multiple articles out there about it. They get enough praise as it is. This is an article written based on personal experience gained by working on at least a dozen performance improvement efforts (not counting the planned ones) during my career as a software developer. This is an article about the boundaries of scenario 2, when the pressure is on, when the damage has already been done, when miracles are expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*yYxv2yK7JjD447EjvBzTig.jpeg" /><figcaption>I too once worked on new features</figcaption></figure><p>This is a two-part article that will focus on the following:</p><ul><li>Factors to consider when planning a performance improvement effort (part 1)</li><li>My performance improvement checklist, steps to consider following when doing performance improvements (part 1)</li><li>Real example of a performance improvement effort, the problem and the effort to resolve it (part 2)</li></ul><h3><strong>Planning factors for performance improvement effort</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPX0KhPP_WSkMyGA82H79w.jpeg" /><figcaption>Time is money and everything is a priority 1!</figcaption></figure><p>There are a lot of factors to take into consideration when planning a performance improvement effort. After all, what client/boss/product owner likes to hear that you will be including performance improvement tasks in your sprint and/or road map? To fix or refactor something that has already been built?</p><p>I’m not going through all possible planning factors here, but I will mention two of them and explain how most of the other factors closely or loosely relate to these two. And let’s be honest, most of the clients/bosses/product owners don’t care about the other factors.</p><p><strong>Expenses</strong></p><p>Whether it’s manpower, software, hardware or the other types of resources, it all translates to money. Hence, expenses. And a lot of other planning factors relate to this one. For example, one of the factors would be the new architectural design that should improve performance (either for a new app or a refactored old one). It’s tied to technologies that will be used to build the software components, skills coaching (if required), hardware and software resources needed, etc. All of this relates to expenses factor, because, in reality (which we, the developers, sometimes don’t take into consideration), most of the mentioned things cost money in one way or another. And that matters.</p><p><strong>Time to market</strong></p><p>Sometimes it’s not even the expenses that play a key factor in performance improvement planning. Sometimes performance issues need to be fixed ASAP, no matter the expenses, because the product is losing money. Or worse, losing users.</p><h3><strong>Performance improvement checklist</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egt-TrSrbLgViS6K0kGtkg.jpeg" /></figure><p>Over the years, mostly by reviewing my own bad experiences, as well as feeding off of pain and suffering of other colleagues, I have devised some sort of checklist-<em>ish</em> guidelines that I try to keep in mind when I’m involved in performance improvement efforts. They have helped me go through a couple of these efforts with less stress than usual. I’m not sure they will help in 100% of the cases, but for now, they help immensely. Also, it’s never a bad thing to have some sort of a checklist when doing things like these.</p><ul><li><strong>Take time to plan the performance improvement efforts</strong></li></ul><p>Even when the time to market factor is extremely important, it is very beneficial to plan out the effort before tackling the issues head on. This would include things like including people that built the low performing functionality in the first place, determining how many resources will you need for researching, investigating, providing the solution, etc. I am aware that at the sign of a big trouble the fight or flight instinct kicks in and you might want to start investigating or doing something immediately, but it’s more beneficial to take some time and plan out the effort.</p><ul><li><strong>Take time to design a proper solution</strong></li></ul><p>If the time to market factor is more important than the rest of the factors, there is not much you can do at this point. Plan it out, investigate, fix the issues as soon as possible, any way you know how, and then come back to this step. Sometimes performance issues are small, fixes are minor and around a solid code base, so it might be a waste of time to design a “better” solution. But, if the issue is straining a part of your architecture, then it’s better to invest time to design a proper solution so that not only you will fix the performance issue, but will have enough room to improve it gradually by planning performance improvements in your product road map. Couple of points below relate closely to this one, but I wanted to separate them.</p><ul><li><strong>If and when possible, take comparable metrics and diagnostic data prior to starting performance improvement efforts</strong></li></ul><p>This one is very useful and you should do it whenever possible. Although collecting measurable data is very beneficial for reports, bragging and writing articles about it, there is a much better reason to do it. The reason is that <strong>data sells</strong>. When you have measurable and comparable data, it is much easier to sell future performance improvement efforts and put them on the product roadmap.</p><ul><li><strong>Break down your performance improvement efforts into smaller deliverable chunks</strong></li></ul><p>This one is closely tied to the ones before, as smaller deliverable chunks of performance improvements, together with comparable metrics, can sell future deliverables to get you where you want to be with the performance of the targeted functionality. Believe me, you don’t want to be that guy that has spent weeks or even months improving the performance of the app/functionality with nothing to show for when called upon. And you will be called upon to show something or give a status update and probably answer the uneasy questions like “What’s taking so long?”, “Why are we spending so much money on this?”, etc. To avoid all of this, deliver as often as possible, with comparable statistics and metrics, if the conditions allow it.</p><ul><li><strong>It’s better to build a proper solution that is able to scale, even if the first iterations don’t bring much performance improvements, or any at all</strong></li></ul><p>This one might be a head-scratcher, but let me explain. Of course, when time to market factor is a high priority, this might not be applicable. But when it’s not, and when expenses factor allows it, you should try to design and build a proper solution. By “proper solution” I mean a solution that gives you enough potential to further improve performance on it and scale it as needed. With roll out in planned iterations and metrics data to back it up, you should not have much problems selling this to your supervisors. It certainly beats trying to improve the existing solution if that solution has limitations.</p><p>Consider the following example: A pretty large stored procedure (around thousands of lines of code) that includes going through a bunch of tables and a million of rows to get the needed data is performing poorly. Your first response might be to add indexes where they are needed to speed up things. And that might be a good solution to hot-fix the issue, but usually it’s not a long-term solution, as a million of rows over time can become two, five, ten million rows. If the time to market factor priority is high, this is fine, but plan for the long run. It is better to refactor the stored procedure or rethink your read models altogether.</p><ul><li><strong>Communicate your endeavours as much as possible</strong></li></ul><p>All your roadblocks, challenges, milestones, results, metrics, deployments, all of it. Everything should be transparent to your supervisors and rest of the team. And not just for your own sake. When you are facing challenges, roadblocks, the support team will have information from your report that they can use to calm down the users. Your metrics and deployment data is valuable to the marketing so they can update the users with the new development, because most of the users may stay faithful if they stay in the loop. The list of examples goes on and on. As a developer bordering on an introvert side, I hate to say this, but communication is the key. If there is a hard lesson that I’ve learned over the years, it’s that your solution is only as good as how well you communicated about it. Because, let’s face it, no one from the C-level management, no clients or product owners will go through your code to commend you on a job well done. To tell you the truth, I’m still somewhat bad at this, so that’s why it’s here, on this list. So, to sum it up, communicate your endeavours. And back them up with data.</p><h3><strong>Conclusion</strong></h3><p>Let’s sum everything up, for this first part.</p><ul><li>Do anything you can to get the performance improvement effort on your product roadmap</li><li>If the above is not possible, plan your performance improvement efforts, get needed metrics and communicate your efforts transparently.</li><li>After all the fuss has died down a bit, get performance improvement efforts on your product roadmap.</li></ul><p><em>In the next part, we will go through a real-world example, just to put some things into a perspective. And the perspective is, staying flexible while going through the performance improvement checklist.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dfe2b41dd93" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mop-developers/performance-improvement-efforts-the-dreaded-side-of-software-development-4dfe2b41dd93">Performance improvement efforts — the dreaded side of software development</a> was originally published in <a href="https://medium.com/mop-developers">Ministry of Programming — Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concurrency is not parallelism — excerpts from the marriage chronicles]]></title>
            <link>https://medium.com/mop-developers/concurrency-is-not-parallelism-excerpts-from-the-marriage-chronicles-412e55617e57?source=rss-3247ea22dc68------2</link>
            <guid isPermaLink="false">https://medium.com/p/412e55617e57</guid>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Emin Laletovic]]></dc:creator>
            <pubDate>Fri, 31 May 2019 13:59:20 GMT</pubDate>
            <atom:updated>2019-05-31T14:24:53.490Z</atom:updated>
            <content:encoded><![CDATA[<h3>Concurrency is not parallelism — excerpts from the marriage chronicles</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KW64xCxk8RBYJznZQavm2Q.jpeg" /></figure><p><em>What can he possibly have to say that hasn’t already been said on this topic, you wonder? Endless articles, lectures, papers, authors covering all the details, the highs and the lows, in all known formats and languages, including English, German, French, Italian, Chinese, Bosnian, Klingon, etc. Is there really anything new to say on this topic?</em></p><p>Well, not really. The materials have got so much better over the years it can be summed up in couple of sentences. Check out this excerpt from the Golang blog:</p><p><em>- “In programming, concurrency is the composition of independently executing processes, while parallelism is the simultaneous execution of (possibly related) computations. Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.”</em></p><p>And, a couple of conclusions:</p><ul><li>Concurrency is not parallelism.</li><li>Concurrency enables parallelism.</li><li>Concurrency makes parallelism easy.</li></ul><p>I could throw in a couple of “Hello, world” examples to further explain the subject in more detail, but I’m not going to. I would rather you went and checked out the <a href="https://blog.golang.org/concurrency-is-not-parallelism">Golang blog</a> and a great lecture by Rob Pike on the subject, or go find some prominent lecturer in your programming language of choosing that is addressing this topic.</p><p>Instead, this article will address my observation on why some people still use these terms interchangeably. And believe me, some still do, in spite of so many resources out there saying otherwise. Also, I will try to give some advice on how to tackle the understanding of the topic. At least, how I managed to get some grasp on this conundrum.</p><h3><strong>People will be people</strong></h3><p>First of all, a note to people who actually care about this topic. Don’t cringe every time you hear these terms being misused. A lot of programmers don’t care about it. There are tools, libraries and practices that abstract and encapsulate away the concurrency and parallelism, and some people just want to get through the task of implementing it to go and do what they actually enjoy. There is nothing we can do for these programmers, and that is that.</p><h3><strong>Try it out</strong></h3><p>Now, for the ones that actually want to understand these concepts and terms, there are few things you might want to try out. First thing, already hinted, is to actually try it out. It really makes a huge difference just reading about it versus reading about it and trying out the examples. Remember those examples I said I wouldn’t give you? Well, they are kinda important. They are not there just to fill up the space and make the article longer. These examples are there for authors as a help aid, but they are not there to help them. Authors can probably talk for days on about this subject, they don’t need additional help. The examples are there to help you with these concepts, they are there for you to try them out. To play with them and break them apart, all in quest for understanding the subject. There are very few people in the world that can get a firm grasp on this subject just from reading. For the rest of us, the examples that are provided are a welcomed help.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/0*HQifKYyj7bwxiBIH" /></figure><p>However, not all examples of concurrency and parallelism come in the form of code samples and excerpts. Although they are not the case of true parallelism, some examples can even be found in nature, mainly in the observations of human behavior. This is where the “marriage” part of the title comes in. By now, you probably wonder what that was about. It wasn’t my intention to leave you hanging, but there is something called story build-up.</p><h3><strong>I was thinking…</strong></h3><p>It was a quiet, rainy Sunday afternoon. I was watching TV. Right across me was my wife and she was playing a game on her iPad. All of a sudden, she started off with “I was thinking…”, the words every husband likes to hear. I don’t know about you, but in my experience, this is a start of some plan elaboration that, in 70% of the cases, includes me doing something. Also, this was my cue to stop watching TV and start listening.</p><p>I’m glad I did, because I noticed something that had always amazed me about my wife, that was an inspiration for this article. While laying out these future plan elaborations, she didn’t stop playing the game. This wasn’t some static game like solitaire or memory, this was a game with a character running and jumping around, a game that requires a good hand-eye coordination. On top of that, she was talking without any pause about a subject completely unrelated to the game. To add to this, she was looking at me from time to time (this will be important later in the article).</p><p>I appreciated this moment of parallelism occurrence. This, something I have always struggled with and could do on very rare occasions, came naturally to her. I consider myself a “concurrent” being, so parallelism comes with a great amount of focus and practice. For most of the time I can do things concurrently that look to be done in parallel, but really, they’re not. To say the least, I was amused and appreciative of this moment. This is how it looks like in a diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/0*2If3aEfffVOThVKd" /></figure><p>Let’s break it down. If we observe my wife as a process, playing the game and looking at me from time to time are tasks done concurrently (T1 and T3, respectively), because these tasks share eyes as a resource and cannot be done in parallel. Talking is another task (T2) that is working separately from the other two. Her ability to do these tasks separately is what is makes the tasks work in parallel. When you go back to that definition, <strong>parallelism is about doing lots of things at once</strong><em>,</em> you see that’s the case here. Well, two is not “lots of”, but it sure serves as a pretty good example.</p><p>She was right to look at me from time to time. As a mostly “concurrent” being, I run things concurrently, of course. So, while appreciating and thinking about the parallel nature of my wife, I actually pressed pause on listening to her. And, she picked up on that, because, apparently I was grinning like an idiot. For reference, I don’t consider grinning a separate task, the same as I don’t consider watching TV and nodding as separate tasks either. Involuntary actions are not separate tasks. Anyway, here’s how that looks like in a diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/0*QvTNVbHLkK5KedoN" /></figure><p>T1 is watching TV, T2 is listening to my wife. T3 is, well, not listening, but thinking about what I have witnessed. Let’s go back to the definition again: “<strong><em>Concurrency is about dealing with lots of things at once</em></strong>”. Here we have my attention as a shared resource and my inability to process information in parallel. The result is that tasks are executed concurrently, but not in parallel.</p><p>By the way, if you are wondering, that black line is an “Aaand you’re not even listening to me!” task interrupt. It brought me back to the listening task’s context.</p><p><em>The provided examples are strictly from the observing perspective. They are not measured results. I’m well aware that humans are not capable of achieving true parallelism, but it sure looks like that from the observing perspective.</em></p><h3><strong>Conclusion</strong></h3><p>All jokes and anecdotes aside, if you want to get a firm grasp on this topic, or any topic for that matter, my advice would be to try out the provided examples for yourself. Find as many as you can, run them, dissect them, break them apart. Don’t forget to ask questions. As you get better, you will have less trouble differentiating between concurrency and parallelism. You will even be able to find and appreciate the occurrences in everyday life.</p><p><em>Note: In most of the cases, I am a great listener. Also, my wife is aware of both my shortcomings and qualities. And yes, I do have qualities, you know.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*3X_oEY7fnppJeeQ_" /></figure><p><em>My wife is also a developer and she understands my “concurrent” nature all too well, so she approves of this article. However, she pointed out that plan inclusion percentages are not 95%. My bad. ❤</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=412e55617e57" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mop-developers/concurrency-is-not-parallelism-excerpts-from-the-marriage-chronicles-412e55617e57">Concurrency is not parallelism — excerpts from the marriage chronicles</a> was originally published in <a href="https://medium.com/mop-developers">Ministry of Programming — Technology</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>