<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>microservices « Plataformatec Blog</title>
	<atom:link href="/tag/microservices/feed/" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>Plataformatec&#039;s place to talk about Ruby, Ruby on Rails, Elixir, and software engineering</description>
	<lastBuildDate>Tue, 30 Jun 2015 16:03:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.2</generator>
	<item>
		<title>Elixir in times of microservices</title>
		<link>/2015/06/elixir-in-times-of-microservices/</link>
					<comments>/2015/06/elixir-in-times-of-microservices/#comments</comments>
		
		<dc:creator><![CDATA[José Valim]]></dc:creator>
		<pubDate>Tue, 30 Jun 2015 12:00:52 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[elixir]]></category>
		<category><![CDATA[microservices]]></category>
		<guid isPermaLink="false">/?p=4787</guid>

					<description><![CDATA[<p>Since microservices have been a common topic lately, there are a lot of questions about how Elixir fits in microservice architectures. On this post, I won&#8217;t focus on the merits of microservices, as many have already discussed that to exhaustion. In particular, Martin Fowler&#8217;s entry on the topic aligns well with my thoughts and is ... <a class="read-more-link" href="/2015/06/elixir-in-times-of-microservices/">»</a></p>
<p>The post <a href="/2015/06/elixir-in-times-of-microservices/">Elixir in times of microservices</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Since microservices have been a common topic lately, there are a lot of questions about how Elixir fits in microservice architectures.</p>
<p>On this post, I won&#8217;t focus on the merits of microservices, as many have already discussed that to exhaustion. In particular, <a href="http://martinfowler.com/bliki/MicroservicePremium.html">Martin Fowler&#8217;s entry on the topic</a> aligns well with my thoughts and is definitely worth reading.</p>
<p>It is also worth mentioning that I have seen many companies pursuing microservices because they fail to organize large applications as their tooling (languages and frameworks) do not provide good abstractions to manage those. So microservices are often seen as a solution for structuring code by imposing the separation of concerns from top to bottom. Unfortunately, prematurely adopting microservices often negatively impacts the team&#8217;s productivity. Therefore, it is also important for languages and frameworks to provide proper abstractions for handling code complexity as the codebase grows.</p>
<h2>Background</h2>
<p><a href="http://elixir-lang.org/">Elixir</a> is a concurrent and distributed programming language that runs on the Erlang Virtual Machine (Erlang VM) focusing on productivity and maintainability. Before we go into microservices, I would like first to argue why Elixir/Erlang may be the best platform out there for developing distributed systems (regardless if you have a microservices architecture or not).</p>
<p>The Erlang VM and its standard library were designed by Ericsson in the 80&#8217;s for building distributed telecommunication systems. The decisions they have done in the past continue to be relevant to this day and we will explore why. As far as I know, Erlang is the only runtime and Virtual Machine used widely in production designed upfront for distributed systems.</p>
<h2>Applications</h2>
<p>The Elixir runtime has the notion of <strong>applications</strong>. In Elixir, code is packaged inside applications which:</p>
<ol>
<li>are started and stopped as a unit. Any Elixir node (Virtual Machine instance) runs a series of applications, with Elixir itself being one of them and starting (and stopping) your system is a matter of starting all applications in it</p>
</li>
<li>
<p>provide a unified directory structure and configuration API. If you have worked with one application, you know the structure and how to configure any other one</p>
</li>
<li>
<p>contains your application supervision tree, with all <strong>processes</strong> and their state</p>
</li>
</ol>
<p>Throughout this post, <strong>processes</strong> mean a lightweight thread of execution managed by the Erlang VM. They are cheap to create, isolated and exchange information via messages.</p>
<p>The impact of applications in a project is highly beneficial. It means that Elixir developers, when writing applications, are given a more explicit approach to:</p>
<ol>
<li>how their code is started and stopped, as it is contained and isolated inside each application</p>
</li>
<li>
<p>what are the processes that make part of an application and therefore what is the application state. If you can introspect your application tree, you can introspect any process and, therefore, all the components that make up your application</p>
</li>
<li>
<p>how the application processes will react and be affected in case of crashes or when something goes wrong</p>
</li>
</ol>
<p>Not only that, the tooling around applications is great. If you have Elixir installed, open up &#8220;iex&#8221; and type: <code>:observer.start()</code>. Besides showing information and graphs about your live node, you can kill random processes, see their memory usage, state and more. Here is an example of running this in a <a href="http://phoenixframework.org/">Phoenix</a> application:</p>
<p><img decoding="async" src="http://i.stack.imgur.com/7j9BR.png" alt="Observer running within a Phoenix application" /></p>
<p>You can see all applications that are part of this node on the left side. Clicking an application shows the processes tree of that application. Double-clicking any process opens up a window with information about the process, which function it is executing, its particular state and more. Furthermore, you can kill any process and see the impact it will have on your system.</p>
<p>When compared to other languages, the difference here is that Applications and Processes give you an abstraction to reason about your system in production. Many languages provide packages, objects and modules mostly for code organization with no reflection on the runtime system. If you have a class attribute or a singleton object: how can you reason about the code that manipulates it? If you have a memory leak or a bottleneck, how can you find the entity responsible for it?</p>
<p>This visibility is one of the major benefits of building systems in Elixir. If you ask anyone running a distributed system, that&#8217;s the kind of insight they want, and with Elixir you have that as the building block.</p>
<h2>Communication</h2>
<p>When building a distributed system, you need to choose a communication protocol and how the data will be serialized. Although there are many options out there, unfortunately a lot of developers choose HTTP and JSON, which is a very verbose and expensive combination for performing what ends up becoming RPC calls.</p>
<p>With Elixir, you already have a communication protocol and a serialization mechanism out of the box via Distributed Erlang. If you want to have two nodes communicating with each other, you only need to give them names, ensure they share the same secret cookie, and you are done.</p>
<p>Not only that, because all Elixir processes communicate with each other via message passing, the runtime provides a feature called <strong>location transparency</strong>. This means it doesn&#8217;t really matter if two processes are in the same node or in different ones, they are still able to exchange messages.</p>
<p>I wrote a quick introduction to Elixir that covers how to get started with Elixir from creating a brand new project up to node communication on <a href="http://howistart.org/posts/elixir/1">How I Start</a>. Check it out for more information.</p>
<p>The Distributed Erlang protocol and serialization mechanism are also documented and therefore it can be used to communicate with other languages. The Erlang VM ships with a binding for Java and others can be found for Python, Go and more.</p>
<h2>Breaking monolithic applications</h2>
<p>Earlier I mentioned I have seen many companies pursuing microservices because they fail to organize code at the project level. So often they prematurely split their architecture in microservices which affects productivity in the short and long run. From Martin Fowler&#8217;s article:</p>
<p><img decoding="async" src="http://martinfowler.com/bliki/images/microservice-verdict/productivity.png" alt="Complexity and Productivity of monoliths and microservices" /></p>
<p>In Elixir, breaking a large application into smaller ones is simpler than anywhere else, as the process tree already outlines dependencies and the communication between those dependencies always happen explicitly via message passing. For example, imagine you have an application called <code>abc</code> that has grown larger with time, you can break it apart into applications <code>a</code>, <code>b</code> and <code>c</code> by extracting its supervision tree to different applications.</p>
<p>This is such a common aspect of working with Elixir projects that its build tool, called Mix, provides a feature called <strong>umbrella projects</strong> where you have a project composed of many applications that may depend on each other on any fashion.</p>
<p>Umbrella projects allows you to compile, test and run each application as a unit but also perform all the tasks at once if required. Here is quick example:</p>
<pre><code class="shell">$ mix new abc --umbrella
$ cd abc/apps
$ mix new a
$ mix new b --sup
$ mix new c --sup
</code></pre>
<p>The snippet above creates a new umbrella project, enters its <code>apps</code> directory and create three applications: <code>a</code>, <code>b</code> and <code>c</code>, where the last two contain a supervision tree. If you run <code>mix test</code> at the <code>abc</code> project root, it will compile and test all projects, but you can still go inside each application and work with it in isolation.</p>
<p>Once the main application <code>abc</code> is broken apart, you may also move each part to a separate repository if desired, or you may not. The benefit is that developers are able to handle growing code complexity in small, granular steps, without making large decisions upfront. We cover this with more details in <a href="http://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html">our Mix and OTP guide</a>.</p>
<h2>Microservices</h2>
<p>So far I haven&#8217;t talked about microservices. That&#8217;s because, up to this point, they don&#8217;t really matter. You are already designing your system around tiny processes that are isolated and distributed. Call them nanoservices if you&#8217;d like to!</p>
<p>Not only that, those processes are packaged into applications, which group them as entities that can be started and stopped as unit. Combined with Distributed Erlang, if you want to deploy your <code>a</code>, <code>b</code> and <code>c</code> applications as <code>[a, b]</code> + <code>[c]</code> or <code>[a]</code> + <code>[b]</code> + <code>[c]</code>, you will have very little trouble in doing so due to their inherent design and built-in communication.</p>
<p>In other words, you can focus on how to deploy your applications based on what is driving you to break them apart. Is it code complexity? You can work on them separately but still deploy them as a unit. Is it for scability or multi-tenancy reasons? If <code>c</code> requires more instances or the application with user specific concern, then it is reasonable to isolate it and deploy multiple instances of <code>c</code>.</p>
<h2>Is Elixir good only for building distributed systems?</h2>
<p>If you are not familiar with Elixir, after reading this far, you may be wondering: is Elixir good only for building distributed systems?</p>
<p>Elixir is excellent for building any kind of long running system exactly because of all the insights you have on your application, even if it is deployed to a single node. The language is also expressive and pleasant to learn and work with (I am certainly biased though), with a <a href="http://elixir-lang.org/getting-started/introduction.html">getting started guide</a> and <a href="http://elixir-lang.org/learning.html">many learning resources</a> already available.</p>
<p>While there is a learning curve, the abstractions outlined here are elegant and simple, and the tooling does an excellent job on guiding you to build your first application. The command <code>mix new my_app --sup</code> we have executed above will generate an application, with its own process tree, which you can directly use and explore to learn more.</p>
<h2>Wrapping up</h2>
<p>I hope I have illustrated how the design decisions done by Elixir and the Erlang VM provide a great foundation for building distributed systems.</p>
<p>It is also very exciting to see companies starting to enjoy and explore those characteristics through the Elixir programming language. In particular, it is worth watching <a href="https://www.youtube.com/watch?v=_i6n-eWiVn4">Jamie Windsor talk at Erlang Factory 2015 and how they were able to leverage this to build a game platform</a>.</p>
<p>Finally, a lot of this post focuses on building systems through Distributed Erlang. Although Distributed Erlang will definitely be the most productive approach, there is no reason why you can&#8217;t leverage the benefits outlined here by using Elixir with another protocol like Apache Thrift.</p>
<p>And, if at the end of the day, all you want is to use HTTP and JSON, that is fine too and libraries like <a href="https://github.com/elixir-lang/plug">Plug</a> and frameworks like <a href="http://phoenixframework.org/">Phoenix</a> will guarantee you are as productive as anywhere else while enjoying the performance characteristics and robustness of the abstractions outlined here.</p>
<p>Happy coding!</p>
<p><em>Note I have not covered techniques like blue/green and canary deployments because they depend on the system and communication protocol you are running. Elixir provides conveniences for process grouping and global processes (shared between nodes) but you can still use external libraries like Consul or Zookeeper for service discovery or rely on HAProxy for load balancing for the HTTP based frontends.</em></p>
<p><a href="http://plataformatec.com.br/elixir-radar"><br />
  <img decoding="async" src="/wp-content/uploads/2015/05/elixir-radar-subscribe.png" alt="Subscribe to Elixir Radar" style="border:0"><br />
</a></p><p>The post <a href="/2015/06/elixir-in-times-of-microservices/">Elixir in times of microservices</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>/2015/06/elixir-in-times-of-microservices/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>Organizing microservices in a single git repository</title>
		<link>/2015/01/organizing-microservices-in-a-single-git-repository/</link>
					<comments>/2015/01/organizing-microservices-in-a-single-git-repository/#comments</comments>
		
		<dc:creator><![CDATA[Gustavo Dutra]]></dc:creator>
		<pubDate>Thu, 22 Jan 2015 10:44:30 +0000</pubDate>
				<category><![CDATA[English]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[microservices]]></category>
		<guid isPermaLink="false">/?p=4397</guid>

					<description><![CDATA[<p>Microservices has gained popularity recently and some projects I&#8217;ve worked on had followed this approach. Basically, it&#8217;s an approach of software architecture that allows breaking monolithic applications into smaller decoupled, business-oriented and isolated deployable applications. Each microservice normally is hosted in its own git repository, since it has very defined business boundaries and the code ... <a class="read-more-link" href="/2015/01/organizing-microservices-in-a-single-git-repository/">»</a></p>
<p>The post <a href="/2015/01/organizing-microservices-in-a-single-git-repository/">Organizing microservices in a single git repository</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Microservices has gained popularity recently and some projects I&#8217;ve worked on had followed this approach. Basically, it&#8217;s an approach of software architecture that allows breaking monolithic applications into smaller decoupled, business-oriented and isolated deployable applications.</p>
<p>Each microservice normally is hosted in its own git repository, since it has very defined business boundaries and the code must be isolated from other microservices to ensure decoupling and deploy independance.</p>
<p>It may work greatly if you organize a team by each microservice. So, if a team is responsible for a given microservice and won&#8217;t work on other microservices, this organization may be good enough.</p>
<p>During project developments, we at Plataformatec understood that it is not so productive to focus on specific parts of a feature. Instead, we design and develop features by perceiving it as a whole, as it would be perceived by the end user. We don&#8217;t work with application specialists, we work with generalists and a lot of communication through pull requests.</p>
<p>So the best fit for the way we work, as our experience has shown us, is to put all the microservices and the clients that consume them into a single git repository. It may sound weird or semantically wrong for some, but after all, those microservices are small parts of a whole, something bigger, that is called <a href="http://en.wikipedia.org/wiki/Software_ecosystem">software ecosystem</a>. Since they share or exchange information among them, they&#8217;re somehow connected to each other.</p>
<p>This pragmatic approach is not exclusively ours, many people out there apply it. Two very nice examples are <a href="http://www.quora.com/Why-does-Facebook-have-so-much-of-their-source-code-in-1-giant-git-repo-did-they-not-think-that-this-approach-wont-scale">Facebook</a> and <a href="https://news.ycombinator.com/item?id=7020584">Google</a>. Of course their codebase is far larger than a normal application. They&#8217;re an exception. Google&#8217;s codebase, for instance, keeps really low level information like operating system configurations.</p>
<p>Using a single repository has proven to be a very good practice for us, because we can keep track of relevant pull requests easier; we can refactor, create and test new features throughout all the microservices faster; and test its integration without leaving the current context. Also, project gardening is way simpler: upgrading Ruby, Rails version, gem updates, using shared paths as gems, tests and deploy all of them can be automated and run across all microservices.</p>
<p>Have you worked with a single or multiple repositories? Please share your thoughts about it in the comments below!</p>
<div style="padding:40px 0 20px;">
<a href="/subscribe/"><img decoding="async" src="/wp-content/uploads/2014/11/subscribe-to-our-blog.png" alt="Subscribe to our blog" style="border:none;" /></a>
</div><p>The post <a href="/2015/01/organizing-microservices-in-a-single-git-repository/">Organizing microservices in a single git repository</a> first appeared on <a href="/">Plataformatec Blog</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>/2015/01/organizing-microservices-in-a-single-git-repository/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
