<?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 Philip Sampaio on Medium]]></title>
        <description><![CDATA[Stories by Philip Sampaio on Medium]]></description>
        <link>https://medium.com/@philipsampaio?source=rss-ab6e760c94b1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pKR0gXZK_1MtwgX9o2W0fQ.jpeg</url>
            <title>Stories by Philip Sampaio on Medium</title>
            <link>https://medium.com/@philipsampaio?source=rss-ab6e760c94b1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:38:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@philipsampaio/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[Communication between Rails engines]]></title>
            <link>https://medium.com/magnetis-backstage/communication-between-rails-engines-ea5953250121?source=rss-ab6e760c94b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea5953250121</guid>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[ddd]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Philip Sampaio]]></dc:creator>
            <pubDate>Mon, 19 Oct 2015 03:15:25 GMT</pubDate>
            <atom:updated>2015-10-20T15:54:07.431Z</atom:updated>
            <content:encoded><![CDATA[<p>So you had the idea to separate different areas, A.K.A. domains, of your application using Rails Engines? You thought it was a great idea until have to communicate through two or more engines?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*Z84HzZgUmxBm3idf_7u7Lg.png" /><figcaption>An example of what you want to do</figcaption></figure><p>This article explains how to do that communication, and how you can keep the productivity using Rails and a little bit of DDD.</p><p>If you are not familiar with Rails engines, they are great tools to separate concerns, reuse code, or simply namespace things. The most famous example of Rails Engine is <a href="https://github.com.br/plataformatec/devise">Devise</a>. You can learn much more reading the Rails guides about it.</p><h3>A bank system</h3><p>To illustrate the problem, I will follow the common case of a bank system. The engine one is called &quot;Accounting&quot;, the engine two is called &quot;Credit Report&quot;. They are two different domains of our Bank system. You can call them &quot;subsystems&quot;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zjNMvxLaR_93KOkVIuYf0A.png" /><figcaption>The domain of this bank system</figcaption></figure><p>The <strong>Accounting</strong> engine is responsible for the <strong>transfer transaction</strong> that needs to <strong>trigger</strong> a new <strong>credit report</strong> for the <strong>accounts related</strong> to the transfer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1af93600aeb0472a827e3ce08804a09/href">https://medium.com/media/d1af93600aeb0472a827e3ce08804a09/href</a></iframe><p>So we need to send a message to the &quot;Credit Report&quot; subsystem somewhere around the return of the &quot;transfer&quot; method.</p><p>Something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f4933c9407e231976db788c461470c6/href">https://medium.com/media/5f4933c9407e231976db788c461470c6/href</a></iframe><p>In this example you can see the message being sent to other domain (&quot;CreditReport&quot;), directly inside the &quot;transfer money&quot; use case.</p><p>This article could finish here, but this would lead to some problems: I&#39;m invading a domain with another that does not have a strong relationship. It means that two subdomains are strongly connected. This is … not good.</p><h4>Using dependency injection</h4><p>An alternative to that is to inject the &quot;CreditReport&quot; subsystem into the &quot;Accounting&quot;.</p><p>This can be done using a configuration, by setting the constant representing the Credit Report subsystem as string.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b2cd0303855fdc343ed2a1cd734d237/href">https://medium.com/media/3b2cd0303855fdc343ed2a1cd734d237/href</a></iframe><p>And this configuration would be done inside some initializer in the main app (Bank). The reason we are configuring using a string (and getting the constant dynamically) is that Rails can use auto load without problems.</p><p>We can change the &quot;transfer money&quot; use case to use that injected/configured dependency.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a5f2d26d7ba6fc9322a3ac210df3c05/href">https://medium.com/media/6a5f2d26d7ba6fc9322a3ac210df3c05/href</a></iframe><p>Good! Now the system is more flexible. There is still existing a contract between the two subsystems, but now &quot;Accounting&quot; does not need to know that a real &quot;CreditReport&quot; exist.</p><p>The problem with this approach is that if we want to test this engine in isolation, we will eventually need to depend on &quot;Credit Report&quot; engine or create a mock to represent that subsystem.</p><h4>Using events</h4><p>To avoid a strong relationship between the Accounting and Credit Report engines, we can create a Pub/Sub communication between them.</p><p>Watch out:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78c3b0027029e669c52d27fee3d4098a/href">https://medium.com/media/78c3b0027029e669c52d27fee3d4098a/href</a></iframe><p>You can see that the Credit Report dependency is gone. A new line get in. That line publishes the event with the result value.</p><p>This approach enables us to configure a subscriber class that receives the event and sends the message to the target, which is the Credit Report subsystem.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0bfe7b931d3f8c1bc406a9ca0de3b4f4/href">https://medium.com/media/0bfe7b931d3f8c1bc406a9ca0de3b4f4/href</a></iframe><p>And the actual message to the &quot;Credit report&quot; goes inside the &quot;AccountingTransferDoneEvent&quot; class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b9973058b94207e80c5cf1fe66f21f3/href">https://medium.com/media/4b9973058b94207e80c5cf1fe66f21f3/href</a></iframe><p>A possible problem with this is that the events are almost async. You can&#39;t check if they work as expected in the publisher class. This is not a problem if you are dealing with something that can be treated as async job, and therefore can handle errors in isolation.</p><h3>Conclusion</h3><p>Communication between two domains is very common, and using Rails engines is easy to get separation of concerns while we keep the productivity that Rails brings to us.</p><p>Using dependency injection through configuration facilitates the communication, and enable us to easily change the implementation of the dependency. But it&#39;s much more flexible to have the event system when you can deal with async messages.</p><p>A POC using the event system can be found at <a href="https://github.com/philss/bank">https://github.com/philss/bank</a>.</p><p>This article is highly inspired in the Clean Architecture ideas applied to Rails. Thanks to <a href="https://medium.com/u/600226ac8c56">Fabiano B.</a> for the insights and great discussions we always have. And thanks to the <a href="https://www.bankfacil.com.br/">BankFacil</a> folks, that started a great discussion about architecture using Ruby.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea5953250121" width="1" height="1" alt=""><hr><p><a href="https://medium.com/magnetis-backstage/communication-between-rails-engines-ea5953250121">Communication between Rails engines</a> was originally published in <a href="https://medium.com/magnetis-backstage">magnetis backstage</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing everyday]]></title>
            <link>https://medium.com/@philipsampaio/writing-everyday-9ab533ffa475?source=rss-ab6e760c94b1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ab533ffa475</guid>
            <dc:creator><![CDATA[Philip Sampaio]]></dc:creator>
            <pubDate>Sat, 03 Jan 2015 01:59:59 GMT</pubDate>
            <atom:updated>2015-01-05T21:34:46.568Z</atom:updated>
            <content:encoded><![CDATA[<p>Yesterday, January 1st, I challenge myself to write everyday a little piece of text. Something more than one tweet is enough.</p><p>My idea is to talk about everything: programming, politics, education, science, humans and beyond.</p><p>The rules are:<br>- I don&#39;t need to publish everyday;<br>- The text must be more than 140 characters;<br>- It should be done before midnight (taking my current TZ, which is America/São Paulo).</p><p>This text is the first one!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ab533ffa475" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>