<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 4, 2015 at 9:40 AM, Roberto Ostinelli <span dir="ltr"><<a href="mailto:roberto.ostinelli@widetag.com" target="_blank">roberto.ostinelli@widetag.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">However, I'd feel better in finding a way to guarantee the atomicity of the operation.</blockquote></div><br>When you request atomicity of the operation, you are asking for linearizability, which is a quite specific guarantee. You request that there is some point in time, and once you go beyond that point, any read will always see the new value and can't be stale (This is an informal description, but the real linearizability guarantee has a fully formal notion). Reads which overlap the point in time sees either the new or the old value, but reads that come after the point in time will *always* see the new value. This is the essential guarantee of atomicity/linearizability.</div><div class="gmail_extra"><br></div><div class="gmail_extra">In the sense of CAP, you are now in CP land, as linearizability is strictly in CP. This means you need coordination of some kind in order to solve it. Your method of electing a leader is one, if done correctly (i.e., hi consensus algorithms or distributed locking). The other one is to run a mnesia-transaction, which almost gets you there[0].</div><div class="gmail_extra"><br></div><div class="gmail_extra">But chances are you don't need linearizability for the operation in the first place. And then, you can avoid having to coordinate as you may be able to put yourself in AP instead. AP is typically much faster due to the lack of coordination, but do see the work of e.g., Neha Narula (<a href="http://et.al">et.al</a>.) for counterexamples to this.</div><div class="gmail_extra"><br></div><div class="gmail_extra">[0] I've argued before that mnesia is neither CP nor AP, and since you can't be CA, mnesia isn't really a distributed system in the typical notion of the word.<br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">J.</div>
</div></div>