<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Redis certainly sounds good here.  I'm a little surprised that there doesn't seem to be a standard pattern for doing this in the database because it doesn't seem like such an unusual use case.</blockquote><div><br></div><div>I'd recommend Redis as well or any datastore with atomic updates that can deal with the parent counter for you. </div><div><br></div><div><br></div><div class="gmail_extra"><div class="gmail_quote">On 2 September 2016 at 11:38, Andrew Stewart <span dir="ltr"><<a href="mailto:boss@airbladesoftware.com" target="_blank">boss@airbladesoftware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">> For this type of thing I really love Redis. You can create a counter per parent and atomically increment without worrying about concurrency. It's also blazingly fast, so you don't have to worry about bulk imports and performance problems, and unlike memcached you can add persistence so you'll never lose your counters.<br>
><br>
> Chances are you are already using in your system, maybe for caching, maybe as a dependency for sidekiq, or as the actioncable backend, so you might not even need to install a new component. And if you have to install it, Redis is very clean to install, easy to monitor, and very robust.<br>
><br>
> You would still use the callback as you are doing now, but you would increment without having to read first. A side effect you might get is having gaps in the sequence if a model increases the counter and then rolls back the transaction. If that's not a problem for you, then I'd strongly recommend to go with Redis.<br>
<br>
</span>Redis certainly sounds good here.  I'm a little surprised that there doesn't seem to be a standard pattern for doing this in the database because it doesn't seem like such an unusual use case.<br>
<div class="gmail-HOEnZb"><div class="gmail-h5"><br>
______________________________<wbr>_________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/<wbr>pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.<wbr>cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/<wbr>listinfo.cgi/chat-lrug.org</a><br>
</div></div></blockquote></div><br></div></div>