<?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 Nuno Marinho on Medium]]></title>
        <description><![CDATA[Stories by Nuno Marinho on Medium]]></description>
        <link>https://medium.com/@nuno_6939?source=rss-ad910a0210e8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Po6Mr3VGvHfGan9nNfehFQ.jpeg</url>
            <title>Stories by Nuno Marinho on Medium</title>
            <link>https://medium.com/@nuno_6939?source=rss-ad910a0210e8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:48:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nuno_6939/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[Remote work at Coletiv]]></title>
            <link>https://medium.com/@nuno_6939/remote-work-at-coletiv-7b507cc404c9?source=rss-ad910a0210e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b507cc404c9</guid>
            <category><![CDATA[remote-working]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[company-culture]]></category>
            <category><![CDATA[remote]]></category>
            <dc:creator><![CDATA[Nuno Marinho]]></dc:creator>
            <pubDate>Tue, 22 Dec 2020 09:33:28 GMT</pubDate>
            <atom:updated>2020-12-22T09:33:28.801Z</atom:updated>
            <content:encoded><![CDATA[<h3>Remote Work at Coletiv</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nasXvRJGxyYnori2r_J_mg.jpeg" /><figcaption>Remote Work at Coletiv</figcaption></figure><p>Even though it was not the norm until recently, remote work is not something new to IT workers. Most of us have done it at one time or another, and some of us even have it as a full-time “perk”, allowing us to work from anywhere.</p><p>The pandemic changed the paradigm — most IT companies, including our own, have shifted to an almost full-time “remote-friendly” environment. Even though we were already remote-friendly at Coletiv, we only practiced it partially, so this was a whole new boat for us.</p><blockquote>We’re an IT company, we are used to it, it’s going to be fine…</blockquote><p>Yeah, we said this… 😅 And so many others have said it too. “Supposedly”, for IT companies this would be an easy task. However, we found over time that this is not completely true — what was previously a benefit or perk, started raising some issues which were hard to tackle and showed we were definitely not as prepared as we thought we were.</p><p>Don’t get me wrong though… Remote work has some great benefits, and the pandemic has made it so that even outside IT, some other more traditional areas are finally opening up to this modern concept — <strong>taken in just the right measure, and in the correct setting, it can be a great tool to help us balance our daily lives.</strong></p><p>The problem lies exactly in achieving the balance, and through our many ordeals we found ourselves raising a question:</p><blockquote><em>Is there a formula to make remote work successful?</em></blockquote><p>Our problems are not only our own, so we hope our experience and attempts at finding this formula, whether or not they were successful, can help others on their paths.</p><h3>Our struggles</h3><p>We found ourselves exposed to other types of problems for the entire company, such as knowledge sharing or lack of identity of the company itself. In response to these types of problems, we adopted different strategies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YTZVBujWGX3gSVI7Vc7VAw.jpeg" /><figcaption>Exposing daily doubts</figcaption></figure><ul><li>At the beginning of the confinement, we would just interact with our peers to expose daily doubts about what we were working on. We went through this phase because we adopted remote work a little earlier than most companies in the field.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eorZ3mXu8gTufL5FZaMPnQ.jpeg" /><figcaption>Daily syncs in the morning</figcaption></figure><ul><li>Due to the lack of interaction felt between collaborators, we started doing daily voice calls at 9 AM with the purpose of syncing everyone with what we did the day before and what we would do in the present day. With this, two problems emerged: oblige the morning workers to stop their focus to attend the meet (and vice versa) and the monotony of the meetings caused disinterest among people who do not share the same project on a daily basis.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99W-Ip9aKZkotLlp9aiTQQ.jpeg" /><figcaption>Open hour after lunch</figcaption></figure><ul><li>In an attempt to fix these problems, those meets were replaced by open hours Wednesdays and Fridays after lunch, where we would debate various topics like social problems, things we found on the stack we are working on, projects presentation, games, team building, cryptocurrency, etc. To keep the sync with the topics that were previously discussed in the morning meeting we created a dedicated place where everyone writes what was done yesterday and what we will do today.</li></ul><p>The last strategy is what we currently use and until today we didn’t find any issues with it. Collaborators keep the engagement on the company (in the best way they can) and actively participate in the open hour.</p><blockquote>In conclusion, we have been adapting remote work to our individual and collective needs but we are not sure if this is the formula for success and we do not even know if there is a formula for success. Either way, how did you, the reader, kept alive the social engagement in your squad? And, if any of the solutions that didn’t worked on our company worked in yours, how did you managed to do it?</blockquote><h3>Thank you for reading!</h3><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialized in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b507cc404c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Reflection on Coletiv’s Culture and What Keeps Me Here]]></title>
            <link>https://medium.com/@nuno_6939/a-reflection-on-coletivs-culture-and-what-keeps-me-here-de505e8cc56b?source=rss-ad910a0210e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/de505e8cc56b</guid>
            <category><![CDATA[experience]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[work-life-balance]]></category>
            <category><![CDATA[opinion]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Nuno Marinho]]></dc:creator>
            <pubDate>Wed, 09 Sep 2020 08:31:01 GMT</pubDate>
            <atom:updated>2020-09-09T08:31:01.177Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vFjGRTSNpxSi218gQIJ-Mg.png" /><figcaption>A Reflection on Coletiv’s Culture and What Keeps Me Here</figcaption></figure><p>Throughout my career, I have worked in several companies. From consultancy based businesses to product companies, from small and medium-sized companies to big corporations. In each of them, I only stayed for a maximum of 2 years, and after this time, I always felt I needed a change. But not now! So, I started thinking: <strong>what is keeping me here?</strong></p><p>Let’s first start analyzing what led to my discomfort in previous companies I have worked for and later down the road to the switch.</p><h3>Biggest reasons that led me to leave my previous companies</h3><h4>Salary</h4><p>Many people say: “Money isn’t everything in life” and they are right. But although money isn’t everything, it plays a very important role in our current society. Everyone has bills to pay (e.g.: mortgage, rent, food, transportation) and objectives to fulfill (e.g.: buy a house, have a comfortable retirement time, travel), good luck doing all this without money…<br>Another related point that made me change was not the fact that I felt I should be earning more, but the fact that I always had to beg about salary raises. <strong>I think that salary raises should be given as an acknowledgment of your good work and contribution to the company and not a fight you need to put up.</strong></p><h4>Work / Project</h4><blockquote>The word engineer is derived from the Latin words <em>ingeniare</em> (“to create, generate, contrive, devise”) and <em>ingenium </em>(“cleverness”).</blockquote><p>I am an engineer by heart! I didn’t study 15+ years to be doing the same exact thing over and over again or to just be hot fixing problems directly on a database day in day out. <br><strong>I want to be challenged with a problem and brainstorm, idealize, and create solutions with the whole team. Solutions that not only solve the problem at hand but that are also maintainable in the long run.</strong><br>Every company has it’s own set of projects that don’t require much creativity or that are exclusively on maintenance mode and that’s fine. For me, the problem is when every working day is spent on doing the same thing (e.g.: directly correcting data on a production database) over and over again. That doesn’t feed my hunger for product creation, doesn’t stimulate my brain, and in the long run won’t make me a better engineer.</p><h4>People</h4><p>The people you are surrounded by is really important. They are the ones with whom you will be spending a big part of your waking hours. <br>Let’s do some simple math: if you sleep 8 hours per day and spend 8 hours in the office, this means that 50% of your waking time is spent with your co-workers. If you just add up “dead time” (e.g.: commute time), this means that you spend more time with your co-workers than with anyone else, even your wife! (I am not counting the weekends here).<br>Have you ever asked yourself: “are my co-workers the kind of people I want to hang out the majority of my time with?”<br>The answer to this question is very important not only in terms of happiness but as well in terms of career evolution. If you are in a constant fight with your co-workers if you can’t bond with them if you can’t properly talk/discuss ideas, football, politics, or whatever topic you are interested in, you will be spending a big part of your life unhappy. <br>Also, it is very important to me that I can learn something from them and vice-versa. I want to learn and evolve, <strong>not being able to learn something new from or with my co-workers is a big red flag that usually leads me to search for new opportunities. Evolution is the only constant in our lives.</strong></p><h4>Company purpose / objective</h4><p>We are living in a capitalist world. But this doesn’t mean that all we should care about is money. Don’t get me wrong, as I said before we all have bills to pay and dreams to fulfill that depend on money. <br><strong>A company is basically a group of people that root for the same ideals, and I want to work for a company that aligns with my moral compass.</strong></p><h4>Needed a change</h4><p>There have been times where all the previous points weren’t a problem, but I needed a change. As simple as that.</p><h3>What keeps me at Coletiv?</h3><p>Besides all the problems pointed out before not being a problem, there are a couple of points that I would like to add that are very important for my decision to stay here.</p><h4><strong>Our opinion is important</strong></h4><p>I feel that my opinion matters. This may happen because we are small. In any case, I feel that my ideas are taken into account and that I can contribute to the direction the company takes.</p><h4>Openness</h4><p>Not only our opinion is important but also the company is very open. We all know everything that is happening at any certain point and even the profits are known to us. Actually a percentage of the profit is distributed with everyone, which makes me feel that my contributions have an impact not only on our clients but as well on the company and ultimately in my financial health 🤑.</p><h4><strong>Intellectual freedom / Investment time</strong></h4><p>Another very valuable thing at Coletiv <strong>is intellectual freedom.</strong> The company never placed any restrictions on me. Actually is the very opposite of that, I am pushed to learn new technologies and take training courses. We now have Fridays to try on new ideas or simply do personal improvement (e.g.: try a new technology).</p><h4><strong>Boss is an employee as we all are</strong></h4><p>The relationship I have here with the so-called “boss” is different than I have ever felt before. I feel he is just a regular employee like us that has a different set of responsibilities. <br>The company also understands that personal problems affect your professional life, as such it tries to understand all of our personal and professional problems. This makes me feel that I am more than simply a cogwheel. It raises the employee-employer relationship to another level of trust and this will always weigh when leaving this or any other company.</p><h3>What can we do better?</h3><p>Not everything is great and we also have our own set of problems, which I will try to explain next.</p><h4>Lack of career plans</h4><p>I like to know where my professional career can/should lead me and I think that a proper career plan can help with that. Since my early days here, that there have been discussions around having a proper career plan, but so far that task keeps being postponed 😢.</p><h4>Improve the efficiency of our Investment time</h4><p>We do take Friday afternoon to invest in ourselves and the company, but the process and the outcomes are still lacking. I mean, we do take the time but it should be better prepared so that we have more visible outcomes, for example, visible contributions to the open-source community. In a sense, we should treat it like any other project we have and plan accordingly.</p><h4>Taking too long until we have products of our own</h4><p>Our objective, in the long run, is to also have products of our own, but like the career plans, these keep being postponed 😢.</p><p>This is a very opinionated article and I know this might not resonate with you, but feel free to comment your opinions below, I am really happy to discuss different points of view 😃</p><h3>Thank you for reading!</h3><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialized in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de505e8cc56b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elixir — Sort Lists by Date]]></title>
            <link>https://medium.com/@nuno_6939/elixir-sort-lists-by-date-60dc9dc471a3?source=rss-ad910a0210e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/60dc9dc471a3</guid>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[elixirlang]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Nuno Marinho]]></dc:creator>
            <pubDate>Mon, 20 Apr 2020 07:31:01 GMT</pubDate>
            <atom:updated>2020-04-20T07:31:01.039Z</atom:updated>
            <content:encoded><![CDATA[<h3>Elixir — Sort Lists by Date</h3><p>Currently, if you need to use <a href="https://hexdocs.pm/elixir/Enum.html#sort/1">Enum.sort</a> on your <a href="https://elixir-lang.org/">Elixir</a> project and want to sort lists by date, you may experience problems depending on the Elixir version you are using.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FXYeSwpNm4U2-jbb5ekCUw.png" /><figcaption>Elixir — Sort Lists by Date</figcaption></figure><p>Recently, while working on a project at <a href="https://coletiv.com/">Coletiv</a>, I needed to sort a list containing structs by their creation date.</p><pre>iex(2)&gt; items<br>[<br>  %{id: 2, inserted_at: ~D[2019-01-01]},<br>  %{id: 1, inserted_at: ~D[2018-01-31]}, <br>  %{id: 3, inserted_at: ~D[2020-03-01]}<br>]</pre><h4>First Try</h4><p>My first approach was to use the <a href="https://hexdocs.pm/elixir/Enum.html#sort/1">Enum.sort</a> function and compare the struct’s inserted date property:</p><pre>[…]|&gt; Enum.sort(&amp;(&amp;1.inserted_at &gt; &amp;2.inserted_at))</pre><p>After some tests, I found that the sorting was not working. Why? It was supposed to be an easy fix 🤔</p><p>Let’s go to <a href="https://hexdocs.pm/iex/IEx.html">IEx</a> to do some tests.</p><pre>Erlang/OTP 21 [erts-10.0.8] [source] [64-bit]<br><br><strong>Interactive Elixir (1.7.3)</strong> - press Ctrl+C to exit (type h() ENTER for help)<br>iex(1)&gt; dates = [~D[2018-01-31],~D[2019-02-01],~D[2020-03-01]]<br>[~D[2018-01-31], ~D[2019-02-01], ~D[2020-03-01]]<br>iex(2)&gt; dates |&gt; <strong>Enum.sort()</strong><br>[~D[2019-02-01], ~D[2020-03-01], ~D[2018-01-31]]<br>iex(3)&gt; dates |&gt; <strong>Enum.sort(&amp; &amp;1 &gt; &amp;2)</strong><br>[~D[2018-01-31], ~D[2020-03-01], ~D[2019-02-01]]<br>iex(4)&gt; dates |&gt; <strong>Enum.sort(&amp; &amp;1 &lt; &amp;2)</strong><br>[~D[2019-02-01], ~D[2020-03-01], ~D[2018-01-31]]</pre><p>Strange…</p><h4>Second Try</h4><p>After some investigation, I found this <a href="https://medium.com/@steven.cole.elliott/sorting-dates-in-elixir-59592a0c33a5">article</a> and the possible problem <a href="https://hexdocs.pm/elixir/master/operators.html">here</a>.</p><blockquote>The collection types are compared using the following rules:</blockquote><blockquote>* Tuples are compared by size, then element by element.</blockquote><blockquote>* Maps are compared by size, then by keys in ascending term order, then by values in key order. In the specific case of maps’ key ordering, integers are always considered to be less than floats.</blockquote><blockquote>* Lists are compared element by element.</blockquote><blockquote>* Bitstrings are compared byte by byte, incomplete bytes are compared bit by bit.</blockquote><p>Considering that a date is a struct, it’s normal that the order was wrong. So the possible solution is:</p><pre>iex(5)&gt; dates |&gt; <strong>Enum.sort_by(fn d -&gt; {d.year, d.month, d.day} end)</strong><br>[~D[2018-01-31], ~D[2019-02-01], ~D[2020-03-01]]</pre><p>For previous versions of elixir (like <strong>elixir v1.7.3</strong>), this is the solution. A little rudimentary but it works.</p><h4>Third Try</h4><p>In <strong>elixir v1.10</strong>, <a href="https://github.com/josevalim">Jose Valim</a> and his team introduce improvements to sort-based APIs in Enum, as you can see <a href="https://github.com/elixir-lang/elixir/blob/v1.10/CHANGELOG.md#improvements-to-sort-based-apis-in-enum">here</a>.</p><p>Let’s go to <a href="https://hexdocs.pm/iex/IEx.html">IEx</a> again to do some tests…</p><pre>Erlang/OTP 21 [erts-10.0.8] [source] [64-bit]<br><br><strong>Interactive Elixir (1.10.1)</strong> - press Ctrl+C to exit (type h() ENTER for help)<br>iex(1)&gt; dates = [~D[2018-01-31],~D[2019-02-01],~D[2020-03-01]]<br>[~D[2018-01-31], ~D[2019-02-01], ~D[2020-03-01]]<br>iex(2)&gt; dates |&gt; <strong>Enum.sort()</strong><br>[~D[2019-02-01], ~D[2020-03-01], ~D[2018-01-31]]<br>iex(3)&gt; dates |&gt; <strong>Enum.sort(&amp;(Date.compare(&amp;1, &amp;2) != :lt))</strong><br>[~D[2020-03-01], ~D[2019-02-01], ~D[2018-01-31]]<br>iex(4)&gt; dates |&gt; <strong>Enum.sort(Date) </strong>                         <br>[~D[2018-01-31], ~D[2019-02-01], ~D[2020-03-01]]<br>iex(5)&gt; dates |&gt; <strong>Enum.sort({:desc, Date})</strong><br>[~D[2020-03-01], ~D[2019-02-01], ~D[2018-01-31]]<br>iex(6)&gt; dates |&gt; <strong>Enum.sort({:asc, Date}) </strong><br>[~D[2018-01-31], ~D[2019-02-01], ~D[2020-03-01]]</pre><p>Voilá 🎉 The improvements to sort-based API’s in Enum made sorting by date a much beautiful and clean solution.</p><h3>Lesson learned</h3><p>In Elixir, as well as in programming in general, the quick solutions don’t always have the expected result and we have to carefully test each solution to make sure it behaves as expected.</p><h3>Thank you for reading!</h3><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialized in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60dc9dc471a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use AWS Cloud​Formation to setup the infrastructure for a static website]]></title>
            <link>https://medium.com/@nuno_6939/how-to-use-aws-cloud-formation-to-setup-the-infrastructure-for-a-static-website-2635efae8c0e?source=rss-ad910a0210e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2635efae8c0e</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Nuno Marinho]]></dc:creator>
            <pubDate>Tue, 18 Feb 2020 09:31:02 GMT</pubDate>
            <atom:updated>2020-02-18T09:31:02.793Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NmyRrT39HfeoFTqgMIPKAg.png" /><figcaption>How to use AWS Cloud​Formation to setup the infrastructure for a static website</figcaption></figure><p>Being a software engineer by heart I am a big fan of automating any recurring manual task.<br><strong>Every time we would develop a static website I would need to manually setup the whole infrastructure for it to work properly. This was a very repetitive and tedious task that we wanted to automatize. <br>In this article, you will find our approach using </strong><a href="https://aws.amazon.com/cloudformation/"><strong>AWS CloudFormation</strong></a><strong>.</strong></p><p>Our usual infrastructure architecture is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*1Rc1QfGKyywMfRwHNRvf9g.png" /><figcaption>Static website hosting with S3 and CloudFront</figcaption></figure><p><a href="https://docs.aws.amazon.com/s3/">S3Bucket</a> — Hosts the deployed code</p><p><a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-policy.html">ReadPolicy</a> &amp; <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-cloudfrontoriginaccessidentity.html">CloudFrontOriginAccessIdentity</a>— Grants read rights to requests to the <a href="https://aws.amazon.com/s3/">S3Bucket</a> requests coming from Cloudfront</p><p><a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-distribution.html">CloudFrontDistribution</a> — Handles requests to the website and retrieves the requested page from the S3Bucket</p><p><a href="https://aws.amazon.com/iam/">PublishUser</a> &amp; <a href="https://aws.amazon.com/iam/">PublishCredentials</a> — <a href="https://docs.aws.amazon.com/iam/">IAM</a> user with Access Keys to enable our continuous integration tools to deploy the newly created code of the website to the S3Bucket</p><p>The first time I got acquainted with AWS CloudFormation was in an AWS training program. <br>At the beginning of each of the practical exercises, the environment was loaded by running a stack on CloudFormation through a YAML file. I was mindblown 🤯. I immediately thought that this would allow me to automate the creation of the whole infrastructure for static website hosting. <br>Another very interesting feature is that every resource created via the CloudFormation stack is erased when the stack itself is deleted. This is very useful to rollback the creation of resources when we detect mistakes, saving us precious time and money.</p><h4>CloudFormation syntax</h4><p>As a piece of advice, before starting to set up a stack in CloudFormation, try to think of and draft the needed resources by yourself. You should then be prepared to jump into the CloudFormation designer.<br><a href="https://gist.github.com/marinho10/ffdbf13587497c781d99adc4e3954079">The yaml</a> has 3 main sections <strong>parameters, resources, and outputs:</strong></p><p><a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html"><strong>Parameters</strong></a><strong><br></strong>Parameters allow you to ask for inputs before running the stack. <br>In the following example, we create an input parameter that will define the bucket name when creating the S3 resource.</p><pre>BucketName:    <br>  Type: String<br>  Default: &quot;a-proper-bucket-name&quot;</pre><p><a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html"><strong>Resources</strong></a><strong><br></strong>This is where you instantiate the actual services.<br>In this example, we create an S3Bucket configured as a static website. Please note how we define the BucketName by using a reference to the parameter / input defined earlier.</p><pre>S3Bucket:    <br>  Type: &quot;AWS::S3::Bucket&quot;<br>  Properties:      <br>    BucketName: !Ref BucketName<br>    WebsiteConfiguration:<br>      ErrorDocument: &quot;index.html&quot;        <br>      IndexDocument: &quot;index.html&quot;</pre><p><a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html"><strong>Outputs</strong></a><strong><br></strong>The outputs allow you to print useful values from the created resources.<br>In this example, we create an output to display the S3Bucket website url.</p><pre>BucketUrl:    <br>  Description: &quot;S3 Bucket Url&quot;    <br>  Value: !GetAtt &quot;S3Bucket.WebsiteURL&quot;</pre><h4>Complete example</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbb7815710df282ed165d1d3267b48ec/href">https://medium.com/media/dbb7815710df282ed165d1d3267b48ec/href</a></iframe><h4>Execution</h4><p>Now it’s time to benefit from the blueprint created.</p><p>First, you need to create a stack, fill in the inputs required by the parameters and then execute it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6lyZbaVRVVg0HiSBz6dLQ.png" /></figure><p>You can now grab a ☕️ as the execution might take some time until it’s complete. You can check the status of the creation at any time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EIO2yqaxyvq-SBw7qtHR1Q.png" /></figure><p><strong>⚠️ Please keep in mind that when you delete the stack you also remove all the resources created. This is useful for testing but you might make the mistake (like we did) of deleting the stack after all the resources are created.</strong></p><h3>Useful links</h3><ul><li><a href="https://docs.aws.amazon.com/cloudformation/">https://docs.aws.amazon.com/cloudformation/</a></li><li><a href="https://forestry.io/blog/automate-your-static-hosting-environment-with-aws-cloudformation/">https://forestry.io/blog/automate-your-static-hosting-environment-with-aws-cloudformation/</a></li></ul><h3>Thank you for reading!</h3><p>I hope this article helps you save time when creating your static website hosting infrastructure!</p><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialized in Elixir, Web, and App (iOS &amp; Android) development. But we do all kinds of stuff. We take care of UX/UI design, software development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2635efae8c0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GenServers Memory Issues]]></title>
            <link>https://medium.com/@nuno_6939/genservers-memory-issues-ef42cc42e3e9?source=rss-ad910a0210e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef42cc42e3e9</guid>
            <category><![CDATA[memory-improvement]]></category>
            <category><![CDATA[processors]]></category>
            <category><![CDATA[genserver]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[memory-issues]]></category>
            <dc:creator><![CDATA[Nuno Marinho]]></dc:creator>
            <pubDate>Thu, 11 Jul 2019 09:30:12 GMT</pubDate>
            <atom:updated>2019-07-11T09:30:12.417Z</atom:updated>
            <content:encoded><![CDATA[<h3>Elixir GenServer Memory Issues</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lQ-MHrNo-svKu1_tISHr9g.png" /></figure><p>One of the abstractions <a href="https://elixir-lang.org/">Elixir</a> provides around processes is the <a href="https://elixir-lang.org/getting-started/mix-otp/genserver.html">GenServer</a> module. A <a href="https://elixir-lang.org/getting-started/mix-otp/genserver.html">GenServer</a> is a process like any other Elixir process and it can be used to keep state, execute code asynchronously and so on.</p><p>Recently, while using <a href="https://elixir-lang.org/">Elixir</a> <a href="https://elixir-lang.org/getting-started/processes.html">processes</a> (specifically <a href="https://elixir-lang.org/getting-started/mix-otp/genserver.html">GenServer</a>), I found myself facing an issue that often occurs in other programming languages: the dreaded <a href="https://en.wikipedia.org/wiki/Memory_leak">memory leaks</a>.</p><h3><strong>Use Case/Problem</strong></h3><p>Basically, I have an application that when started initializes multiple <a href="https://elixir-lang.org/getting-started/mix-otp/genserver.html">GenServers</a> in parallel that makes multiple calls to externals API’s. <strong>The processes execute work every 5 minutes and have short-lived data.</strong></p><p>Initially, I did not found problems but with the increase in the number of processes, I’ve checked that each process has unnecessarily data stored in the memory after the first run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y0lD4iAW19KRP_3Ar41QXw.png" /></figure><h3>Solution 1 — use fullsweep_after on GenServer.start_link</h3><p>After some investigation, I found some links that talk about memory usage in the<a href="https://elixir-lang.org/getting-started/mix-otp/genserver.html">GenServer</a>. And I found this <a href="https://elixirforum.com/t/extremely-high-memory-usage-in-genservers/4035/23">paragraph</a> by <a href="https://twitter.com/sasajuric">Sasa Juric</a>:</p><blockquote>One option is to set the <em>fullsweep_after</em> flag of the problematic process to zero or a very small value. I think that <em>GenServer.start_link(callback_module, spawn_opt: [fullsweep_after: desired_value])</em> should do the job. For more explanation, look for <em>fullsweep_after</em> in <a href="http://erlang.org/doc/man/erlang.html">docs for the :erlang module</a></blockquote><p>And this information about BIF (Built-In Functions) in <a href="http://erlang.org/doc/man/erlang.html">docs for the :erlang module</a>:</p><blockquote>{fullsweep_after, Number}</blockquote><blockquote>Useful only for performance tuning. Do not use this option unless you know that there is a problem with execution times or memory consumption, and ensure that the option improves matters.</blockquote><blockquote>The Erlang runtime system uses a generational garbage collection scheme, using an “old heap” for data that has survived at least one garbage collection. When there is no more room on the old heap, a fullsweep garbage collection is done.</blockquote><blockquote>Option fullsweep_after makes it possible to specify the maximum number of generational collections before forcing a fullsweep, even if there is room on the old heap. Setting the number to zero disables the general collection algorithm, that is, all live data is copied at every garbage collection.</blockquote><blockquote>A few cases when it can be useful to change fullsweep_after:</blockquote><blockquote>If binaries that are no longer used are to be thrown away as soon as possible. (Set Number to zero.)</blockquote><blockquote>A process that mostly have short-lived data is fullsweeped seldom or never, that is, the old heap contains mostly garbage. To ensure a fullsweep occasionally, set Number to a suitable value, such as 10 or 20.</blockquote><blockquote>In embedded systems with a limited amount of RAM and no virtual memory, you might want to preserve memory by setting Number to zero. (The value can be set globally, see <a href="http://erlang.org/doc/man/erlang.html#system_flag-2">erlang:system_flag/2</a>.)</blockquote><h3>Solution 2— use :hibernate on the Genserver</h3><p>Investigating a little more, I found another <a href="https://hexdocs.pm/elixir/GenServer.html#c:handle_call/3">paragraph</a> in the docs for <a href="https://elixir-lang.org/getting-started/mix-otp/genserver.html">GenServer</a>:</p><blockquote>Returning {:reply, reply, new_state, :hibernate} is similar to {:reply, reply, new_state} except the process is hibernated and will continue the loop once a message is in its message queue. If a message is already in the message queue this will be immediately. Hibernating a <a href="https://hexdocs.pm/elixir/GenServer.html#content">GenServer</a> causes garbage collection and leaves a continuous heap that minimises the memory used by the process. <br>…<br>Once you know which processes are causing the problem, a simple fix could be to hibernate the process after every message. This is done by including :hibernate in the result tuple of handle_* callbacks (e.g. {:noreply, next_state, :hibernate}). This will reduce the throughput of the process, but can do wonders for your memory usage.</blockquote><p>After reading this information, I decided to experiment with different solutions and compare the results.</p><h3>Test 1: Test with the default fullsweep_after value (65535)</h3><p>In the initial test, I changed nothing from my previous code in order to obtain the current status of memory consumption. The screenshots have a red bubble around the total memory usage and the process memory usage, which are the values we are going to compare/focus between tests.</p><pre>...</pre><pre>def start_link(state) do<br>  GenServer.start_link(<br>    __MODULE__, <br>    state,<br>    name: handle_string_to_atom(&quot;proj_#{state.project_id}&quot;)<br>  )<br>end</pre><pre>...</pre><ul><li>After all the processes have started:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SzOoxJtEezFY8FkIOgIV2A.png" /></figure><ul><li>After all the processes have started and 5 of them had started executing their work:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94FuaR0DTTIw_7EY9JqUoQ.png" /></figure><ul><li>After all the processes have started and 5 of them had executed their work:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_g7ffCpCIbhNqHkez5PCWg.png" /></figure><h3>Test 2: Test with fullsweep_after with a value of 0</h3><p>In this test, I force the GenServer to execute the Garbage Collection after every cycle.</p><pre>...<br>def start_link(state) do<br>  GenServer.start_link(<br>    __MODULE__, <br>    state,<br>    name: handle_string_to_atom(&quot;proj_#{state.project_id}&quot;),<br>    spawn_opt: [fullsweep_after: 0]<br>  )<br>end<br>...</pre><ul><li>After all the processes have started:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OK7qrGsrtLQTg6J2Ul2Ng.png" /></figure><ul><li>After all the processes have started and 5 of them had started executing their work:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0vlafOzC3zA76OJOYcW9Iw.png" /></figure><ul><li>After all the processes have started and 5 of them had executed their work once:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NC1sZQeLblD3zS7a0Z4A0g.png" /></figure><h3>Test 3: Test with :hibernate process</h3><p>In this test, I force the GenServer to hibernate after every execution.</p><pre>...<br>def handle_*(event, state) do<br>  ...<br>  {:noreply, state, :hibernate}<br>end<br>...</pre><ul><li>After all the processes have started:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m8eL6J-vldKw65aJmNRMGQ.png" /></figure><ul><li>After all the processes have started and 5 of them had started executing their work:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OHz1H6MsLbingdkCeM4_cw.png" /></figure><ul><li>After all the processes have started and 5 of them had executed their work once:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LpgXXjOJBjHzWbE9wKIvdg.png" /></figure><h3>Lesson learned</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cl7Cb5f0jBWCRB61yjZSqw.png" /></figure><p><strong>This is not a replacement for efficient code and that should be used thoughtfully. <br>Another important thing is when I force the GenServer to execute the Garbage Collection after every cycle, the CPU usage is increased drastically, so you need to be careful with these changes. <br>For my case, the best solution was to hibernate the process after the execution, but you should test and analyse what is the best solution for your problem.</strong></p><h3>Useful links</h3><ul><li><a href="https://coletiv.com/blog/elixir-crash-dumps-tools-tips/">Coletiv Blog — Quick tips &amp; tools for analysing Erlang/Elixir crash dumps</a></li><li><a href="https://elixirforum.com/t/extremely-high-memory-usage-in-genservers/4035/31">Elixir Forum — Extremely high memory usage in GenServers</a></li><li><a href="https://stackoverflow.com/questions/52297140/memory-leaks-from-genserver-processes">Stackoverflow — Memory leaks from GenServer processes</a></li><li><a href="https://www.erlang-solutions.com/blog/erlang-19-0-garbage-collector.html">Erlang Solutions — 19.0 Garbage Collector</a></li><li><a href="https://hamidreza-s.github.io/erlang%20garbage%20collection%20memory%20layout%20soft%20realtime/2015/08/24/erlang-garbage-collection-details-and-why-it-matters.html">Hamidreza Soleimani’s Blog — Erlang Garbage Collection Details and Why It Matters</a></li><li><a href="https://hexdocs.pm/elixir/GenServer.html#c:handle_call/3">HexDocs — Genserver:handle_call</a></li></ul><h3>Thank you for reading!</h3><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialised in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef42cc42e3e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From 0 to DynamicSupervisor — Handling Processes in Elixir]]></title>
            <link>https://medium.com/@nuno_6939/from-0-to-dynamicsupervisor-handling-processes-in-elixir-b8df0da0e2fc?source=rss-ad910a0210e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8df0da0e2fc</guid>
            <category><![CDATA[process]]></category>
            <category><![CDATA[dynamicsupervisor]]></category>
            <category><![CDATA[erlang]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Nuno Marinho]]></dc:creator>
            <pubDate>Fri, 29 Mar 2019 08:01:00 GMT</pubDate>
            <atom:updated>2019-03-29T08:01:00.851Z</atom:updated>
            <content:encoded><![CDATA[<h3>From 0 to DynamicSupervisor — Handling Processes in Elixir</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*mm_EwbxrigxFd0xEsFkpuA.png" /><figcaption>Source: <a href="https://ferd.ca/the-zen-of-erlang.html">https://ferd.ca/the-zen-of-erlang.html</a></figcaption></figure><p>I started my software development career as a Java developer and it had been my language of choice until December of 2016, which was the time when I decided to join <a href="https://coletiv.com/">Coletiv</a> and started coding in <a href="https://elixir-lang.org/">Elixir</a> 😀.</p><p>With <a href="https://www.devglan.com/spring-boot/spring-boot-async-task-executor">Java it’s possible to use processes and parallelize</a> them but it isn’t common and it’s always a struggle. One of the use cases I used processes for was when I had to process a big amount of data in a reduced timeframe, but as a rule of thumb, I avoided them as much as I could.</p><p>With Elixir I found another world that, <a href="https://twitter.com/wbruce/status/1101043694273101825">citing Bruce Williams</a>, doesn’t treat concurrency and process management like afterthoughts or advanced features.</p><p>A few months ago Elixir was updated to version 1.6 which introduced the <a href="https://github.com/elixir-lang/elixir/blob/v1.6/CHANGELOG.md#dynamic-supervisor">DynamicSupervisor</a>.</p><h4>DynamicSupervisor in my way</h4><p>In one of my current projects, <em>users</em> have <em>tasks</em> assigned to them and the backend has to notify the user about the status of their tasks every 5 minutes.<br>In terms of database structure, I have users and they have tasks assigned to them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*XRzOAhkn33_qlCwc_e3LkQ.png" /><figcaption>Database structure</figcaption></figure><p>When it comes to the erlang/elixir process structure we decided to have a <a href="https://elixir-lang.org/getting-started/mix-otp/genserver.html"><em>GenServer</em></a><em> (Task worker) </em>for each active task, whose responsibility is to constantly update the users about their tasks status. <br>On top of these processes, there is a <em>DynamicSupervisor </em>responsible for supervising and working as an interface to communicate with the child processes.<br>In terms of process lifetime it goes like this:</p><ul><li>When the application starts all the <em>Task workers</em> are started, one by one, for each active task.</li><li>When a user adds a new task, a new <em>Task worker</em> is started.</li><li>When a user completes a task the respective <em>Task worker</em> is killed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*NNGHg2lV-xPuYNYehhktYA.png" /><figcaption>Elixir process tree</figcaption></figure><h4>DynamicSupervisor Code</h4><p>The <em>TaskSupervisor</em> is a <em>DynamicSupervisor</em> and we just need to initialise it (<em>start_link/1</em> &amp; <em>init/1</em>) and define the functions to start (<em>start_task_worker/1</em>) and finish (<em>terminate_task_worker/2</em>) the workers related to them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f7eba7e14a25e4f9d2ee65e3c093e19/href">https://medium.com/media/1f7eba7e14a25e4f9d2ee65e3c093e19/href</a></iframe><h4>TaskWorker Code</h4><p>The <em>TaskWorker</em> is a <em>GenServer</em> that verifies every 5 minutes if the task is active and notifies the user that the task is still open. When a task is finished the related <em>Task worker</em> dies. <br>One important thing is the restart strategy for the <em>GenServer, </em>we are using the :transient strategy so that if the <em>Task worker is </em>abnormally terminated (e.g. crashes for some unexpected reason) it is immediately respawned by the <em>DynamicSupervisor. </em>If the <em>Task worker</em> is normally terminated (e.g. when the task is finished) it is not respawned.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee8ce7d473f8c4820c4393ac6dfb126e/href">https://medium.com/media/ee8ce7d473f8c4820c4393ac6dfb126e/href</a></iframe><h4>StarterWorker Code</h4><p>In order to start all the workers when the application starts we created a <em>StarterWorker </em>whose single responsibility is to start all <em>Task workers.</em> One <em>Task worker</em> per active <em>Task</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63765221106cfa009dcce820cf3b242e/href">https://medium.com/media/63765221106cfa009dcce820cf3b242e/href</a></iframe><h4>Lesson learned</h4><p>Like me, when you start with Elixir you might be afraid of using processes because of the experience you had with previous languages, instead, give it a try and you will be surprised how quick and easy it is to work with them.</p><p>There are a few great links you should check when trying processes:</p><ul><li><a href="https://elixir-lang.org/getting-started/mix-otp/dynamic-supervisor.html">Elixir Lang — Dynamic Supervisors</a></li><li><a href="https://ferd.ca/the-zen-of-erlang.html">The Zen of Erlang</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*cG0X9pBkn377u8aUwF9naQ.png" /></figure><h4>Thank you for reading!</h4><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialised in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8df0da0e2fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Many to many relationships with Ecto]]></title>
            <link>https://medium.com/@nuno_6939/ecto-elixir-many-to-many-relationships-66403933f8c1?source=rss-ad910a0210e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/66403933f8c1</guid>
            <category><![CDATA[ecto]]></category>
            <category><![CDATA[many-to-many]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Nuno Marinho]]></dc:creator>
            <pubDate>Tue, 12 Feb 2019 07:01:01 GMT</pubDate>
            <atom:updated>2020-02-07T10:08:39.743Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gv54lHDJ4aGtwOPGP2GzBQ.png" /><figcaption>Elixir with Ecto</figcaption></figure><p>A <a href="https://www.ucl.ac.uk/news/2017/feb/humans-are-hard-wired-follow-path-least-resistance">University of College London study</a> discovered something we all knew: humans are lazy. Meaning that most of the times, when we have a problem we take the easiest way to solve it. But it doesn’t mean we are solving the problem right away.</p><p>You might ask yourself, what does this have to do with <a href="https://elixir-lang.org/">Elixir</a> and <a href="https://hexdocs.pm/ecto/Ecto.html">Ecto</a>? Well, at <a href="https://coletiv.com/"><strong>Coletiv</strong></a> we have been working on a project where a user can manage multiple projects and a project can be managed by multiple users, this is a trivial case known as <a href="https://en.wikipedia.org/wiki/Many-to-many_(data_model)">many to many</a>.</p><p>In terms of database diagram/structure, I created both <em>user</em> and <em>project</em> tables, plus the so-called <em>Many to Many table (user_project)</em>, as the diagram below illustrates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*SxZH0zkYvTsqKeR1G77uDQ.png" /><figcaption>Database with many_to_many table — user_project</figcaption></figure><p><strong>First implementation — Scaffolding all<br></strong>At first, I thought the easiest way to solve the problem was to scaffold each table and manually create a method that directly managed the projects from a user in the <em>user_project</em> table. <br>It worked perfectly fine, the unit tests proved the solution worked just fine!</p><p><strong>Step 1<br></strong>Create a migration that adds <em>user_project</em> table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00a96a19a6369cdfb060e3e435893ed6/href">https://medium.com/media/00a96a19a6369cdfb060e3e435893ed6/href</a></iframe><p><strong>Step 2<br></strong>Create module <em>UserProject</em> with schema and <a href="https://hexdocs.pm/ecto/Ecto.Changeset.html"><em>changeset</em></a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3a711854dfd3924b5a034b25f3f2ea8/href">https://medium.com/media/f3a711854dfd3924b5a034b25f3f2ea8/href</a></iframe><p><strong>Step 3<br></strong>Create a context function that updates the projects a user has access to. This naive solution deleted all current projects and inserted the list of projects passed as a parameter. This means that if, for example, we were adding a new project to the user and keeping all the old ones, we would still have to delete the old ones and re-add them again with the new list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbebbb9569a8208d6913c99c1fa498e8/href">https://medium.com/media/dbebbb9569a8208d6913c99c1fa498e8/href</a></iframe><h4>The right way — Use Ecto powers</h4><p>One of the things we don’t facilitate at <a href="https://coletiv.com/"><strong>Coletiv</strong></a> is pull requests and code reviews. As soon as I did a pull request with these changes, my fellow colleagues immediately refused to merge the pull request and asked: “Shouldn’t Ecto manage the link between users and projects for you?”. This kept me thinking for a while 🤔.</p><p>I decided to get back to the drawing board and started reading the Ecto documentation again until I found the <a href="https://hexdocs.pm/ecto/Ecto.Changeset.html#put_assoc/4">put_assoc/4</a> function that did just what I was looking for: manage <a href="https://hexdocs.pm/ecto/Ecto.Schema.html#t:many_to_many/1">many_to_many</a> associations. But it didn’t work straight away.</p><blockquote><strong>Warning: When you use many_to_many and put_assoc/4 you should be aware of the preloads, you need to ensure that the many_to_many relationship data is loaded so that it is updated. And don’t forget to use the on_replace option when declaring the relationship on your model. It took me a while to figure out why the relationship was not being updated, kudos for </strong><a href="https://medium.com/u/7bf125c5b541"><strong>David Magalhães</strong></a><strong> for the help.</strong></blockquote><p>If you are still confused, please check the steps below:</p><p><strong>Step 1<br></strong>Create a migration that adds <em>user_project</em> table.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00a96a19a6369cdfb060e3e435893ed6/href">https://medium.com/media/00a96a19a6369cdfb060e3e435893ed6/href</a></iframe><p><strong>Step 2<br></strong>Add many_to_many relations in <em>Project</em> and <em>User</em> module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a57252088900061fbf14dea9c5fd6ad/href">https://medium.com/media/7a57252088900061fbf14dea9c5fd6ad/href</a></iframe><p><strong>Step 3.</strong> Add new changeset to user module for editing projects (adding the <a href="https://hexdocs.pm/ecto/Ecto.Changeset.html#put_assoc/4">put_assoc/4</a>)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ab438aa5187660d5c050c3eee587b40/href">https://medium.com/media/1ab438aa5187660d5c050c3eee587b40/href</a></iframe><p><strong>Step 4<br></strong>Create a function that makes use of the <em>changeset</em> to update the projects of a user.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fc3c6bc293d99959da4c39d217783a7/href">https://medium.com/media/4fc3c6bc293d99959da4c39d217783a7/href</a></iframe><h4>Lesson learned</h4><p>In short, the lesson to take from here is to not always go for the easiest solution as it might not be the best in the long term. And <strong>always take time to learn, evolve and experiment new ways of doing things so that you don’t get stuck with outdated techniques.</strong></p><h4>Thank you for reading!</h4><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialised in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66403933f8c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to automate your Elixir project’s deployment into AWS]]></title>
            <link>https://medium.com/@nuno_6939/how-to-automate-your-elixir-projects-deployment-into-aws-9ecbbafb403d?source=rss-ad910a0210e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ecbbafb403d</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Nuno Marinho]]></dc:creator>
            <pubDate>Mon, 26 Nov 2018 09:48:35 GMT</pubDate>
            <atom:updated>2019-02-18T08:53:48.201Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T9uPaIV6hVFFI8uGKGDpXg.png" /></figure><p><strong>This is the first article of a 2-part series</strong>, where we explain in full how to automate your Elixir project’s deployment. The technologies used are <a href="https://aws.amazon.com/"><strong>AWS</strong></a><strong>,</strong> to host your project, and <a href="https://circleci.com/"><strong>CircleCI</strong></a><strong>, </strong>to automate the testing and deployment of the application.</p><p><a href="https://medium.com/coletiv-stories/elixir-phoenix-project-deployment-steps-and-automation-with-circle-ci-d719d8ab79f1">Part II — How to automate the deployment of your Elixir project with CircleCI</a></p><h3>AWS Configuration</h3><p>A basic <a href="https://aws.amazon.com/">AWS</a> configuration for your application should consist of various interconnected services, of which <a href="https://aws.amazon.com/ec2/">EC2</a> is the most important, as it will host your project and you will be interacting with it quite a lot.</p><p>Additionally, we use <a href="https://aws.amazon.com/rds/">RDS</a> for the database and <a href="https://aws.amazon.com/route53/">Route 53</a> for the domain management, along with some other minor useful tools. This tutorial is divided into various sequential steps that explain how to fully configure these services, so that you can have a fully working infrastructure you can deploy your code to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AhMOKmpG6x7gfbIABj0ZHQ.png" /><figcaption>AWS Configuration — General view</figcaption></figure><p>If you have troubles finding the services we will be configuring, you can search and access them in the services tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oQtn0neqlxYokrZb3fpHwg.png" /></figure><h3><strong>A) EC2</strong></h3><p>We will configure 2 instances one for staging and another for production environment.</p><p><strong>1. Create Staging Instance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yjde_f1MaWJhPiqxHM6slw.png" /><figcaption>EC2 configuration</figcaption></figure><p>Please keep in mind that some services might not be available in certain regions, for our example we are going to use North Virginia.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZPclvwBmL_yGVsyL-ezzgQ.png" /></figure><p>In this example we are going to use a free tier image of ubuntu 16.0.4 (AMI) with a <a href="https://aws.amazon.com/ec2/instance-types/t2/">t2.micro</a> instance composed of 1GB of RAM and 20GB of disk (EBS volume). For your own project feel free to adjust these values to match the project needs. Another important thing is the <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html">regions and availability zones</a> and each AWS service may or may not be available for that area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ivdc3ln8zJxC643qWrhvbA.png" /><figcaption>Step 1–Choose AMI</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mkQXzDmjcuetSDW6XUvtIA.png" /><figcaption>Step 2 — Choose Instance Type</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WU7NE5QysfgT0PSEZMQh-Q.png" /><figcaption>Step 3 — Configure Instance</figcaption></figure><p>Please do not forget to check the “Protect against accidental termination”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WoRzjiKWztAo3CRuYmS11g.png" /><figcaption>Step 4 — Add Storage</figcaption></figure><p>The last step consists on adding tags to our EC2 instance. This step is not crucial to the configuration and the only purpose of the tags is to identify our instance inside the AWS services, so feel free to add your own tags.</p><p><strong>2. Configure the Security Group</strong></p><p>The security group is one of the most crucial configurations, as it defines exactly who can access the machine. In our case, we define the SSH, HTTP and HTTPS protocols.<br>SSH, because we want to be able to access the machine and interact with it via terminal so that we can configure it.<br>HTTP and HTTPS so that our project can be accessed when deployed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*055aySNjHokAzi9bNK7bFw.png" /><figcaption>Step 6 — Configure Security Group</figcaption></figure><p><strong><em>Warning:</em></strong><em> Rules with a source of 0.0.0.0/0 allow all IP addresses to access your instance. We recommend setting the security group rules to allow access from known IP addresses only.</em></p><p><strong>3. Create a new Key Pair (for external access to instance)</strong></p><p>At the end of the EC2 instance creation process, it is necessary to create a key pair (save the key pair in your machine, so you can configure your SSH access locally).</p><h3>B) <a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-eips.html">Elastic IP</a></h3><p>Create one Elastic IP address associated to the EC2 instance created. The Elastic IP is needed because if, for example, we shutdown this instance and create another one with other characteristics, we simply reassociate the Elastic IP created to the new instance and everything works well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*e8NUcctu-LhtoKXf5aRjug.png" /><figcaption>Step 1 — Elastic IP</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hq_2HiHQEqnTmxAEZoxDig.png" /><figcaption>Step 2 — Associate Elastic IP with instance</figcaption></figure><h3>C) Configure the EC2 Machine</h3><p><strong>1. Configure SSH Access</strong></p><pre>###recommended put key-pair.pem in ~/.ssh folder<br>chmod 400 key-pair.pem </pre><pre>###replace 111.11.111 with the Elastic IP generated<br>ssh -i key-pair.pem ubuntu@111.11.111</pre><p><strong>2. Install the tools needed in the EC2 instance</strong></p><p>Access the machine and install the necessary software.</p><ul><li><a href="https://elixir-lang.org/install.html#unix-and-unix-like">Elixir/Erlang</a></li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-16-04">Git</a></li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04">Node</a></li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04">Nginx</a></li><li><a href="https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04">Postgres</a> (not the full installation, just the client version of it in the same version as the one in RDS)</li></ul><p><strong>3. Install </strong><a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-let-s-encrypt-with-nginx-server-blocks-on-ubuntu-16-04"><strong>Certbot</strong></a></p><p>You need to install <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-let-s-encrypt-with-nginx-server-blocks-on-ubuntu-16-04"><em>Certbot</em></a> and then generate an SSL certificate for the domain that your machine will correspond to. <strong>Important: Sometimes you need to run step “E) Route 53” first.</strong></p><pre># Please replace example.com by your domain<br>sudo certbot --nginx -d example.com -d <a href="http://www.example.com```/">www.example.com</a><br>sudo certbot renew --dry-run</pre><p>Next, follow steps 3 and 4 of this <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-let-s-encrypt-with-nginx-server-blocks-on-ubuntu-16-04">tutorial</a>.</p><p><strong><em>Warning:</em></strong><em> Certboot is rate limit.</em></p><p><strong>4. Configure Nginx</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*-sHOutV4te0HEKUS8W_zkA.png" /></figure><p>Next, you need to configure Nginx to use the certificate you just created for this domain. Navigate to the folder <em>/etc/nginx/sites-available</em>, where you can find the <em>default</em> Nginx file, which looks like the one that follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c301b4b408c7ff66c76405eece50cfd9/href">https://medium.com/media/c301b4b408c7ff66c76405eece50cfd9/href</a></iframe><p><strong><em>Warning:</em></strong><em> please replace &lt;server_name&gt; by the previously generated server_name.</em></p><p><strong>5. Last settings on the instance</strong></p><p>Finally, you need to create the <em>&lt;project-name&gt;</em> folder in <em>/opt</em>. After that we have to pass the control to the user ubuntu.</p><pre>sudo mkdir <em>&lt;project-name&gt;<br></em>sudo chown -R ubuntu:ubuntu <em>&lt;project-name&gt;</em>/</pre><p><strong>6. Create an Image based on the created instance and Create a Production Instance</strong></p><p>You can skip this step if you just need to setup a single environment. In our projects we usually start with a staging and a production environment. The staging environment contains all the code done so far and is used to test the latest features before they go into production. The production environment is the one used by the real users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*Ku3nZb235L-HCfgofQkWyg.png" /><figcaption>Step 1 — Create an Image based on the created instance</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kja2uu4ojMHKcromsnMLdg.png" /><figcaption>Step 2 — Create image</figcaption></figure><p>Create an image (EC2 — AMI) based on the previously created instance (staging instance). Then create the production instance from the image (so we have the two instances created and configured — production and staging). <strong>Don’t forget:</strong> save the key pair in your machine to configure your SSH access locally.</p><p>For the production instance it is<strong> necessary to repeat the following steps</strong>:</p><ul><li><strong>B) Elastic IP (production instance)</strong></li><li><strong>C) 1. Configure SSH access (production instance)</strong></li><li><strong>C) 1. Configure SSH access (production instance)</strong></li><li><strong>C) 3. Install Certbot (production instance)</strong></li></ul><h3>D) RDS</h3><p>The example we show you here uses a relational database. In this case, we use Postgres.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*uxxDYwY-rc_jLBh-MFeexA.png" /><figcaption>EC2 and RDS configurations</figcaption></figure><p><strong>1. Create 2 DB Instances (production and staging)</strong></p><ul><li><strong>Careful</strong> with the options chosen like: engine version, allocated store and enable deletion protection.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MAGUNhqFdYJI-IHhx6mSkQ.png" /><figcaption>Step 1 — Select engine</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0Fe_F1sd-miVoNPB431Bw.png" /><figcaption>Step 2 — Instance specifications</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3uZKvnlhd-k6OXTq3fQBw.png" /><figcaption>Step 3- Settings</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bYskEM01pIBstX0hCL6L1w.png" /><figcaption>Step 4 — Network &amp; Security</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Giclq0Cj0sXF1LzmCgU-_Q.png" /><figcaption>Step 5 — Database options</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOmHESDufF8jtXBmcZJisA.png" /><figcaption>Step 6 — Backup</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmOY9PMI7jgHAM8WfReT2g.png" /><figcaption>Step 7 — Maintenance</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O6oCgDbCckdtc4XbDBaIcA.png" /><figcaption>Step 8 — Deletion protection</figcaption></figure><p><strong>2. Configure the Security Group to allow EC2 to connect to the RDS</strong></p><p>Basically you have to add the instance security group to the RDS security group in order to allow EC2 to connect to the RDS instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nYIzKRN2EEKHjTOk5KkENg.png" /><figcaption>Allow EC2 to connect to the RDS instance</figcaption></figure><h3>E) Route 53</h3><p>To route the domains and subdomains to the previously created machines we used Route 53.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*-olM9zQSBxYDZEgj31Fj8g.png" /><figcaption>Route 53 — example</figcaption></figure><p><strong>1. Create a Hosted Zone with a Domain Name</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*TojTnlAbDg3RaHoB9KOEsA.png" /><figcaption>Step 1 — Create a hosted zone</figcaption></figure><p><strong>2. Create Aliases</strong></p><ul><li><strong>Create one alias record set for staging EC2 machine’s elastic IP</strong></li><li><strong>Create one alias record set for production EC2 machine’s elastic IP</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*QJ0eZZ0bxdFfR9T04hUSCw.png" /><figcaption>Step 2— Create a record set</figcaption></figure><p>You now have a fully functioning AWS setup (routing, database, server instance) ready to receive and host an elixir based server. In the next part of the tutorial we are going to configure <a href="https://medium.com/coletiv-stories/elixir-phoenix-project-deployment-steps-and-automation-with-circle-ci-d719d8ab79f1">CircleCI to automatically deploy</a> your project into the AWS setup we just created.</p><h4>Thank you for reading!</h4><p>Thank you so much for reading and if you enjoyed this article make sure to hit that 👏👏 button. It means a lot to us! Also<strong> don’t forget to follow </strong><a href="https://coletiv.com/"><strong>Coletiv</strong></a><strong> on </strong><a href="https://medium.com/coletiv-stories"><strong>Medium</strong></a><strong>, </strong><a href="https://twitter.com/coletivstudio"><strong>Twitter</strong></a><strong>, and </strong><a href="https://www.linkedin.com/company/coletiv/"><strong>LinkedIn</strong></a> as we keep posting more and more interesting articles on multiple technologies.</p><p>In case you don’t know, Coletiv is a software development studio from Porto specialised in Elixir, iOS, and Android app development. But we do all kinds of stuff. We take care of UX/UI design, web development, and even security for you.</p><p>So,<a href="https://coletiv.com/contact"><strong> let’s craft something together?</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ecbbafb403d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>