<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="133144" data-post-id="133144">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="habutre" data-post="11" data-topic="23324">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/habutre/48/15887_2.png" class="avatar"> habutre:</div>
<blockquote>
<p>But is just to create isolation between <code>MyBackendApp</code> and <code>MyPhoenixApp</code></p>
</blockquote>
</aside>
<p>On a single node that is usually accomplished with “<a href="https://forum.elixirforum.com/t/discussion-dont-add-a-database-layer-to-your-phoenix-application/8623/15" rel="nofollow">parallel dependencies</a>” (<a href="https://embedded-elixir.com/post/2017-05-19-poncho-projects/" rel="noopener nofollow ugc">poncho projects</a> within Nerves).</p>
<p>For example from an <a href="https://forum.elixirforum.com/t/elixir-for-programmers-pragdave-currently-on-offer-for-30/6335" rel="nofollow">elixir course</a>: <a href="https://github.com/thebrianemory/elixir-for-programmers/blob/master/hangman/lib/hangman/game.ex" rel="noopener nofollow ugc"><code>game.ex</code></a> is “the <a href="https://github.com/thebrianemory/elixir-for-programmers/tree/master/hangman" rel="noopener nofollow ugc">hangman</a>” backend to “the <a href="https://github.com/thebrianemory/elixir-for-programmers/tree/master/gallows" rel="noopener nofollow ugc">gallows</a>” phoenix application. And <code>game.ex</code> isn’t even a process - it simply defines a <code>struct</code> which captures the state that is manipulated only through the module’s functions.</p>
<p>The <code>hangman</code> backend does have it’s own <a href="https://github.com/thebrianemory/elixir-for-programmers/blob/master/hangman/lib/hangman/server.ex" rel="noopener nofollow ugc">server</a> but that is only run for use with the <a href="https://github.com/thebrianemory/elixir-for-programmers/tree/master/text_client" rel="noopener nofollow ugc">text client</a>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="133144" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/application-communication-best-practices/23324/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-133144" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="133144"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="133261" data-post-id="133261">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="al2o3cr" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/al2o3cr/120/3457_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  al2o3cr
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="habutre" data-post="11" data-topic="23324">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/habutre/48/15887_2.png" class="avatar"> habutre:</div>
<blockquote>
<p>So if <code>GenServer</code> is not the way to go could be <code>Task</code> or simple <code>Process</code> ?</p>
</blockquote>
</aside>
<p>Have you considered using… nothing? Let’s walk through a typical Phoenix + Ecto application to explain what I mean.</p>
<p>(h/t to <a class="mention" href="/u/jola" rel="nofollow">@jola</a>, this is a long version of that earlier comment)</p>
<p>There are two big clumps of processes running: database connections and acceptors.</p>
<p>The application’s <code>Repo</code> is a single process, started at boot, and manages a pool of <code>DBConnection</code> processes, keeping track of which connections are checked out and handling failures.</p>
<p>A Phoenix endpoint uses Cowboy (and ultimately Ranch) to start a bunch of “acceptor” processes which (as the name might suggest) accept incoming TCP connections and start a new “handler” process that does the actual work (<a href="https://www.amberbit.com/blog/2018/7/24/when-web-requests-fail-in-elixir-and-phoenix/" rel="nofollow">here’s a diagram and additional discussion</a>).</p>
<p>That process handles running the per-request Phoenix code as well as user-defined plugs and eventually calls the specified function in the controller. When that code calls functions like <code>Ecto.Repo.insert</code>, Ecto checks out a connection - borrowing it from the <code>DBConnection</code> process that holds it when idle - and interacts with the database.</p>
<p>Notably absent here is a process boundary: some of the code that gets executed is defined in modules within the Phoenix “app” (routing, plugs, controllers), and some comes from the Ecto “app” (schemas, changesets) but all of it executes within that single “handler” process created for the specific HTTP request.</p>
<p>This is what the GenServer docs mean by “use processes only to model runtime properties, not code organization”. The runtime property desired here is per-HTTP-request concurrency.</p>
<p>On the other hand, having an <code>EctoApp</code> GenServer that every HTTP request interacts with would result in a bottleneck at that GenServer’s message queue.</p>
<p>So “nothing” at the beginning of this post is a little hyperbolic, but “a function call” is pretty close. The BEAM has a lot of powerful architectural features, but it’s vitally important to understand the philosophy underpinning them to use them correctly. GenServers != microservices</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="133261" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/application-communication-best-practices/23324/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-133261" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="133261"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="133274" data-post-id="133274">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="joaothallis" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/joaothallis/120/14276_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  joaothallis
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Is there any reason why the web code has to stay in another node (separete machine)?</p>
<p>If the codes can stay on the same machine why not call the function directly? For me this is the best practice and the simplest.</p>
<p>One option to decouple and use the same machine is to use RabbitMQ or something, but for a simple API I understand it as a bad practice.</p>
<p>If you would you like build microservices was some approaches: <a href="http://www.ubazu.com/microservice-approaches-in-elixir" rel="noopener nofollow ugc">http://www.ubazu.com/microservice-approaches-in-elixir</a></p>
<p>It’s worth seeing: <a href="http://www.ubazu.com/decouple-your-elixir-application-from-phoenix-and-ecto" rel="noopener nofollow ugc">http://www.ubazu.com/decouple-your-elixir-application-from-phoenix-and-ecto</a></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="133274" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/application-communication-best-practices/23324/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-133274" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="133274"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-solved cat-solved" title="Marked as solution"></div>
  </section>
</div>
    <div class="postbit" id="133377" data-post-id="133377">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="habutre" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/habutre/120/15887_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  habutre
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You got my point, since I came mostly from Java world where the lately there is a big movement towards microservices and event-driven architectures I tend to use more or less the same approach with Elixir.</p>
<p>Since I didn’t get constructive driven-by-example feedback from my aforementioned colleagues I end up here trying to find out the Elixir-way to write code that is decoupled, distributed and/or isolated among contained services holding mainly business logic.</p>
<p>I really appreciate all points that people brought me here and help me a lot. Thanks <a class="mention" href="/u/kokolegorille" rel="nofollow">@kokolegorille</a> <a class="mention" href="/u/jola" rel="nofollow">@jola</a> <a class="mention" href="/u/peerreynders" rel="nofollow">@peerreynders</a> <a class="mention" href="/u/axelson" rel="nofollow">@axelson</a> <a class="mention" href="/u/al2o3cr" rel="nofollow">@al2o3cr</a> and <a class="mention" href="/u/joaothallis" rel="nofollow">@joaothallis</a> for spend your time to help me on my journey to become a good Elixir Dev.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="133377" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/application-communication-best-practices/23324/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-133377" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="133377"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>