<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pierre Le Gall</title>
    <description>The latest articles on DEV Community by Pierre Le Gall (@pierrelegall).</description>
    <link>https://dev.to/pierrelegall</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F318009%2Ffe9d0602-faf9-4690-8b7c-355a274665bc.jpg</url>
      <title>DEV Community: Pierre Le Gall</title>
      <link>https://dev.to/pierrelegall</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pierrelegall"/>
    <language>en</language>
    <item>
      <title>Elixir can make you avoid the microservices architecture</title>
      <dc:creator>Pierre Le Gall</dc:creator>
      <pubDate>Wed, 14 Dec 2022 17:54:02 +0000</pubDate>
      <link>https://dev.to/pierrelegall/about-elixir-and-the-microservices-architecture-37gi</link>
      <guid>https://dev.to/pierrelegall/about-elixir-and-the-microservices-architecture-37gi</guid>
      <description>&lt;p&gt;While many companies are still thinking about a migration to a microservice architecture, many didn't hear about Erlang/Elixir yet. It seems surprising because Erlang solved a lot of scalability headache before the microservice concept was named; even before the first releases of Java and Python!&lt;/p&gt;

&lt;h2&gt;
  
  
  The purpose of a microservices architecture
&lt;/h2&gt;

&lt;p&gt;To be as brief as possible, microservices architecture help in these cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;scalability issues: monolithic apps can be hard to scale&lt;/li&gt;
&lt;li&gt;splitting a service into functional parts: teams could have a much adapted code source organization for their project&lt;/li&gt;
&lt;li&gt;language agnostic solution: you can choose the more suitable tool to solve a specific problem&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Despite this nice characteristics, this is an expensive architecture (in time, context switching and team skills needed). If we think costs will just double, we are often far from the truth.&lt;/p&gt;

&lt;p&gt;Common advice is to start small and simple, so &lt;a href="https://www.martinfowler.com/bliki/images/microservice-verdict/productivity.png"&gt;microservices is rarely the best option at the birth of a project&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The case of Elixir
&lt;/h2&gt;

&lt;p&gt;Elixir is welcomed in a microservices architecture, like every other languages. But that is not the point here: monolithic architectures with Elixir will be compared to microservices architectures.&lt;/p&gt;

&lt;h3&gt;
  
  
  Scalability
&lt;/h3&gt;

&lt;p&gt;One of the killer feature of Elixir is the use of the BEAM (a.k.a. the Erlang VM) under the hood. The BEAM allows you to write an app as a monolith following &lt;a href="https://www.youtube.com/watch?v=ELwEdb_pD0k"&gt;the actor model&lt;/a&gt; patterns. Consequently, it runs it "as microservices" on the host machine; i.e. each operation runs in a single lightweight process without sharing memory. Data is shared between processes with message passing. So, all CPU cores are used without making a change to your code base (I really recommend &lt;a href="https://www.youtube.com/watch?v=bo5WL5IQAd0"&gt;this talk&lt;/a&gt; by late Joe Armstrong on this topic). Moreover, multiple BEAMs on different machines could work together as a cluster with &lt;a href="https://www.youtube.com/watch?v=Z2r6ZEPX5e4"&gt;a bit of configuration&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is often the main argument in favor of a microservices architecture. However, Elixir (in fact, the BEAM) solved the issue about scalability a long time ago. The reason why it shines so much on this topic is because it has been design for concurrency from start.&lt;/p&gt;

&lt;p&gt;Note &lt;a href="https://akka.io/"&gt;Akka&lt;/a&gt;, the Java &amp;amp; friends framework, is working with the actor model and have as main inspiration Erlang to mimic some features of the BEAM on top of the JVM.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functional split
&lt;/h3&gt;

&lt;p&gt;Breaking a monolith into functional parts is doable thanks to the concept of apps in Erlang/Elixir. It enables us to add an app as a dependency of another app. Because all apps run on the BEAM, you take advantage of it: processes still communicates through the classic Erlang message passing mechanism.&lt;/p&gt;

&lt;p&gt;Managing multiple Git repositories and their dependencies can be hard. In that case, &lt;a href="https://medium.com/multiverse-tech/getting-our-feet-wet-with-elixir-umbrella-applications-8ba4b1f7b7dd"&gt;Umbrella&lt;/a&gt; comes to the rescue to manage your different parts of your project in a single repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Language agnostic?
&lt;/h3&gt;

&lt;p&gt;In the case of Elixir, there is fantastic tools helping you to stay in a monolithic approach. I think about &lt;a href="https://github.com/rusterlium/rustler"&gt;Rustler&lt;/a&gt; to add safe machine code written in Rust to your project, or even &lt;a href="https://www.youtube.com/watch?v=fPKMmJpAGWc"&gt;Nx&lt;/a&gt; for AI purposes (like &lt;a href="https://numpy.org/"&gt;Numpy&lt;/a&gt; in the Python ecosystem) which can make use of the GPU for intensive scientific computations.&lt;/p&gt;

&lt;p&gt;Nevertheless, microservices is still the architecture of choice to fully enable the "good tool for the right job" spirit.&lt;/p&gt;

&lt;h2&gt;
  
  
  In short
&lt;/h2&gt;

&lt;p&gt;Erlang/Elixir can avoid you many complexities of a microservices architecture, because it's written as a monolith (with actor model patterns), but runs concurrently at the fine grain of processes. If you start a project, choosing it allows you to build a monolith without the need to rebuild everything as microservices in the future. If you feel the need of a functional split of the source code, the concept of "apps" comes to the rescue. But if Elixir does not seem to feet your requirements, feel free to think about a microservices architecture, but start simple as possible (probably with a monolith finally).&lt;/p&gt;

&lt;p&gt;I will finish with a real world example of a company using Erlang/Elixir for their little messaging service called WhatsApp, &lt;a href="https://www.wired.com/2015/09/whatsapp-serves-900-million-users-50-engineers/"&gt;which only needs 50 engineers for its 900M users&lt;/a&gt;. To name some others: &lt;a href="https://discord.com/blog/how-discord-scaled-elixir-to-5-000-000-concurrent-users"&gt;Discord&lt;/a&gt;, &lt;a href="https://medium.com/pinterest-engineering/introducing-new-open-source-tools-for-the-elixir-community-2f7bb0bb7d8c"&gt;Pinterest&lt;/a&gt;, &lt;a href="https://technology.riotgames.com/news/riot-messaging-service"&gt;Riot Games&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Stay curious, but pragmatic.&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>erlang</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Git: amending commits and forcing with lease a push</title>
      <dc:creator>Pierre Le Gall</dc:creator>
      <pubDate>Thu, 16 Jan 2020 10:03:44 +0000</pubDate>
      <link>https://dev.to/zenika/git-amending-commits-and-forcing-with-lease-a-push-jmk</link>
      <guid>https://dev.to/zenika/git-amending-commits-and-forcing-with-lease-a-push-jmk</guid>
      <description>&lt;p&gt;I often have a discussion about &lt;code&gt;git commit --amend&lt;/code&gt; and &lt;code&gt;git push --force&lt;/code&gt; versus &lt;code&gt;git push --force-with-lease&lt;/code&gt; with new colleagues.&lt;/p&gt;

&lt;p&gt;First things first: it is ok to rewrite commits on your working branches, even already pushed commits. It allows you to remove useless commits and inconsistencies, resulting in a cleaner history.&lt;/p&gt;

&lt;p&gt;Rewriting commits seems tricky as a beginner. However, if you want to rewrite the last one, &lt;code&gt;git commit --amend&lt;/code&gt; allows you to do it easily. Not only the commit message is alterable, but the content of the commit too (you just have to add or remove some changes before your &lt;code&gt;git commit --amend&lt;/code&gt;). This is definitely my main way for editing a commit. More advanced history rewrites may be done with &lt;code&gt;git rebase&lt;/code&gt; which is a broad topic I will not discuss in this post.&lt;/p&gt;

&lt;p&gt;After changing an already committed work, you will then be forbidden to push it the regular way. The reason is it would result to an inconsistent synchronization between your local machine and the remote. So you have to force your &lt;code&gt;git push&lt;/code&gt;. But as you maybe already heard, &lt;code&gt;git push --force&lt;/code&gt; is a truly bad habit. This is because, if something changed on the remote, it will not be taken into account. Put it another way, if someone else pushed a commit and you didn't pull it before, the commit will be lost (or more precisely, it will be hard to recover).&lt;/p&gt;

&lt;p&gt;Maybe you think &lt;code&gt;git push --force&lt;/code&gt; is unavoidable after rewriting your commits history? Spoiler alert: it's not true. The alternative is to use &lt;code&gt;git push --force-with-lease&lt;/code&gt;. The &lt;code&gt;--force-with-lease&lt;/code&gt; option works somehow like a &lt;code&gt;--force&lt;/code&gt;, but will check if you are well synchronized with the remote before pushing. If you are not up-to-date locally, the command fails and warns you. In other words, you are forcing, but safely. This good practice may avoid many “where is that damn commit?!” situations in your team.&lt;/p&gt;

&lt;p&gt;I sometimes heard: “I do not &lt;code&gt;git push --force-with-lease&lt;/code&gt; but I always &lt;code&gt;git pull&lt;/code&gt; before every &lt;code&gt;git push --force&lt;/code&gt;”. Unfortunately, this is not enough yet because another push could be done by someone else between the two commands. Rare, but not impossible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flepieru%2Flepieru.github.io%2Fmaster%2Fimages%2Fforce-with-lease-meme.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Flepieru%2Flepieru.github.io%2Fmaster%2Fimages%2Fforce-with-lease-meme.jpg" alt="But when I do, I use --force-with-lease"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Git CLI gets nicer these days, e.g. adding in version 2.23 the &lt;code&gt;switch&lt;/code&gt; and &lt;code&gt;restore&lt;/code&gt; sub-commands to do some stuff &lt;code&gt;checkout&lt;/code&gt; is already capable of. Thanks to this update, we have now more suitable verbs to do the job. However, the CLI change I would be the most happy to see is a &lt;code&gt;-f&lt;/code&gt; short option bound to the &lt;code&gt;--force-with-lease&lt;/code&gt; option of &lt;code&gt;git push&lt;/code&gt;. In this case, brutal force short option could use &lt;code&gt;-F&lt;/code&gt; instead. Sadly, it would be a breaking change. Nevertheless, I am still passively hoping.&lt;/p&gt;

</description>
      <category>git</category>
    </item>
  </channel>
</rss>
