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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>From my understanding, the OTP framework designs <code>gen_server</code> (called <code>GenServer</code> in Elixir) to act as both a server and a client, similar to the TCP server/client pattern. It maintains state, but developers need to handle persistence themselves if they want to restore the state after a crash. It also receives configuration/options from a supervisor (or via manual start) and initializes its state in the <code>init</code> callback.</p>
<p>I think this can be annoying for developers when handling state in some cases.</p>
<p>In my opinion, a <code>GenServer</code> with a pluggable architecture, similar to Phoenix, would be more flexible and better aligned with the Elixir style.</p>
<p>Another interesting component is <code>gen_statem</code>. It is quite suitable for working with state transitions. I saw that Elixir implemented it in the early days, but it seems to have been discontinued.</p>
<p>For DGen, at first glance, it looks like a remote <code>GenServer</code> running on another node. If the goal is to share or persist state, this could be achieved by adding an adapter layer (similar to Plug). I think this would help users support more use cases, such as storing data in Redis, Postgres, etc.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="385149" 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/dgen-a-distributed-genserver/74409/32">Post #31</a>
	                </div>
	            </div>
              <div id="likers-container-385149" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385149"
                     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 #31"></div>
  </section>
</div>
    <div class="postbit" id="385162" data-post-id="385162">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="garrison" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  garrison
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Some programs have pesky correctness conditions like “<a href="https://jepsen.io/consistency/phenomena/stale-read" rel="noopener nofollow ugc">do not lose committed data ever</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="385162" 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/dgen-a-distributed-genserver/74409/33">Post #32</a>
	                </div>
	            </div>
              <div id="likers-container-385162" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385162"
                     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 #32"></div>
  </section>
</div>
    <div class="postbit" id="385164" data-post-id="385164">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Of course, but that isn’t something that OTP provides for <code>gen_*</code> modules for you. If you need such behaviour, then it is up to you to decide what “committed data” is and how tell user it was committed at all.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="385164" 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/dgen-a-distributed-genserver/74409/34">Post #33</a>
	                </div>
	            </div>
              <div id="likers-container-385164" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385164"
                     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 #33"></div>
  </section>
</div>
    <div class="postbit" id="385165" data-post-id="385165">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="garrison" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  garrison
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>All I’m saying is that “turn it off and on again” is inadequate for maintaining availability in a persistent system because you will either persist the bugs or lose data, neither of which is acceptable. You need correctness testing.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="385165" 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/dgen-a-distributed-genserver/74409/35">Post #34</a>
	                </div>
	            </div>
              <div id="likers-container-385165" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385165"
                     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 #34"></div>
  </section>
</div>
    <div class="postbit" id="385167" data-post-id="385167">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Of course you need correctness testing. However, it is a chicken and egg problem in the real world: what do you do before you reached absolute correctness? Nothing? With OTP you can at least limp on and monitor the log file, find out what went wrong, add a test case and fix the bug for good. It gives you a path to correctness but not the correctness itself.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="385167" data-batch-url="/posts/batch_likers">
                        4
                      </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/dgen-a-distributed-genserver/74409/36">Post #35</a>
	                </div>
	            </div>
              <div id="likers-container-385167" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385167"
                     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="385170" data-post-id="385170">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Some stuff may be acceptable in some cases. The perfect example there will be telephone switcher (what a coincidence):</p>
<p>In case of telephone call if there is a bug in software, we want to reduce impact on the overall system. If that was one-off issue, then the callers will call again and “something broke” and everyone will go back to their lives. But if bug in single process (call) can cascade to other calls, then it is highly undesirable.</p>
<p>Similar thing with HTTP services, if there will be some issue on the line, then user will simply hit “refresh”. If that issue isn’t common, and was one-off, then no-one will notice that (browser may even refresh on its own in some cases).</p>
<p>There is a lot of systems (especially related to network), where simply restarting process (often even not needed to be done automatically) will be enough for a lot of error handling in case of one-off errors.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="385170" 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/dgen-a-distributed-genserver/74409/37">Post #36</a>
	                </div>
	            </div>
              <div id="likers-container-385170" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385170"
                     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 #36"></div>
  </section>
</div>
    <div class="postbit" id="385173" data-post-id="385173">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Asd" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Asd
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="mudasobwa" data-post="31" data-topic="74409">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/48/5298_2.png" class="avatar"> mudasobwa:</div>
<blockquote>
<p>In such a case it makes total sense to restart preserving the latest state</p>
</blockquote>
</aside>
<aside class="quote no-group" data-username="mudasobwa" data-post="31" data-topic="74409">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/48/5298_2.png" class="avatar"> mudasobwa:</div>
<blockquote>
<p>Andalso, the error might be provoked by the wrong state indeed, but the previous state was all right and it might make sense to rollback to this “previous” state rather than to the point blank one.</p>
</blockquote>
</aside>
<p>I think that you’re missing the point. Some time ago, I’ve seen your <a href="https://github.com/am-kantox/peeper" rel="noopener nofollow ugc">Peeper library</a> which stores the state of some GenServer in ets and loads it back when the GenServer restarts. It got me thinking about it and I decided that this approach is just reinventing the bicycle</p>
<p>You are completely right that restoring the latest correct state after the crash is the best option. However, it is not the best assumption that this latest correct state is the state which the GenServer was in right before the crash or before it received the message which crashed the GenServer. And even more, there is no generic answer about how to decide which state (the GenServer is in at some moment) is correct and which is not.</p>
<p>That’s why GenServer has callbacks. Namely <code>init/1</code> is the callback which executes some code which has to recreate some state which is correct for sure. This approach is generic, because it imposes no expectations and lets the developer decide which state is correct and which is not. If you have a bug in <code>init/1</code> which returns the incorrect state, then your server will restart with an incorrect state, but that’s just a one callback, and its a callback, a function, which may return different results. That means, that GenServer will recover if <code>init/1</code> returns a correct state at least once.</p>
<p>Rolling back to some of the previous states will impose the hard requirement onto the developer, who now needs to write the code in a way, that no <code>handle_*</code> callback ever returns incorrect state. If it returns incorrect state once, you’re forever stuck with it. Otherwise every crash will restart the server with incorrect state, thus indefinitely persisting the incorrect state without any chance for automatic recovery. That means, that GenServer will recover only if all callbacks return correct state all the time.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="385173" 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/dgen-a-distributed-genserver/74409/38">Post #37</a>
	                </div>
	            </div>
              <div id="likers-container-385173" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385173"
                     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 #37"></div>
  </section>
</div>
    <div class="postbit" id="385175" data-post-id="385175">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mudasobwa" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/120/5298_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mudasobwa
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Cure</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="Asd" data-post="38" data-topic="74409">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/a/c68b51/48.png" class="avatar"> Asd:</div>
<blockquote>
<p>I think that you’re missing the point.</p>
</blockquote>
</aside>
<p>I think that not all the people whose opinion differs from yours are <em>missing the point</em> <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>If there was a rock solid solution allowing the developer to properly recover from anything, preserving a proper good state, it’d been incorporated into OTP, I’m 102% positive. Obsiously, there is not such a silver bullet.</p>
<p>It does not mean the developer cannot narrow their usecases to some less general surface. For some cases, like aforementioned “wrong message, correct state,” <em>Peeper</em> just does everything right. If I can ensure that my code does not corrupt the state under any circumstances, <em>Peeper</em> would have a lot of hassle prevented. Does it work for everyone under any circumstances?—Of course not. Small libraries are not usually cover each and every need of the depeloper all across the world, standard lib (OTP) does.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="385175" 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/dgen-a-distributed-genserver/74409/39">Post #38</a>
	                </div>
	            </div>
              <div id="likers-container-385175" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385175"
                     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 #38"></div>
  </section>
</div>
    <div class="postbit" id="385176" data-post-id="385176">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="mudasobwa" data-post="39" data-topic="74409">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/48/5298_2.png" class="avatar"> mudasobwa:</div>
<blockquote>
<p>For some cases, like aforementioned “wrong message, correct state,” <em>Peeper</em> just does everything right. If I can ensure that my code does not corrupt the state under any circumstances, <em>Peeper</em> would have a lot of hassle prevented.</p>
</blockquote>
</aside>
<p>If I knew that, wouldn’t it be simpler to reject the wrong message and keep the GenServer humming?</p>
<p>You library might be useful for cases like Liveview, where the life span of the process is tied to the health of the socket. However, in the case of LV, the restart of the process is triggered by async user action, not a supervisor, so there could be race conditions between the serialization and de-serialization, thus corrupt the state for good?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="385176" 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/dgen-a-distributed-genserver/74409/40">Post #39</a>
	                </div>
	            </div>
              <div id="likers-container-385176" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385176"
                     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 #39"></div>
  </section>
</div>
    <div class="postbit" id="385192" data-post-id="385192">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mudasobwa" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/mudasobwa/120/5298_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mudasobwa
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Cure</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I don’t actually think that abusing the process lifetime to depend on some external action is a good idea in the first place, so LV is likely out of scope here.</p>
<blockquote>
<p>If I knew that, wouldn’t it be simpler to reject the wrong message and keep the GenServer humming?</p>
</blockquote>
<p>Might be, but that would somewhat violate fail-fast paradigm, because we would need to carefully handle all the wrong paths instead of just implementing happy paths and allow it to fail on any incoming garbage, knowing that we are to resurrect with the correct state. The most vivid example is probably handling 3rd party calls.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="385192" 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/dgen-a-distributed-genserver/74409/41">Post #40</a>
	                </div>
	            </div>
              <div id="likers-container-385192" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="385192"
                     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 #40"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/74409/load_more?page=5">Load more posts (1 remaining)</a>
</div></template></turbo-stream>