<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Jan 26, 2017 at 5:20 AM Charles Shuller <<a href="mailto:charles.shuller@gmail.com">charles.shuller@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg">What things should be considered when deciding if a chunk of functionality should be implemented as a plain old module or a gen_server??<br class="gmail_msg"></div></div></div></blockquote><div><br></div><div>As a main rule:<br><br></div><div>Stateless functionality goes into library modules, stateful functionality goes into a gen_server process.<br><br></div><div>A good example is a database pool. The protocol encoder/decoder for the database is a library and should live separately. A stateful connection to the DB uses the protocol module to provide its functionality. Finally, a separate system handles the pooling and its guarantees.<br><br></div><div>By splitting the system up, you can reuse the DB connection code in another pool. Or you can move the connection handling into another process by calling directly into the library.<br><br></div><div>Another main rule:<br><br></div><div>Each concurrent activity which needs to keep state must have its own process.<br><br></div></div></div>