[LRUG] Scoping sequences to a parent

Andrew Stewart boss at airbladesoftware.com
Fri Sep 2 03:38:03 PDT 2016


> 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.
> 
> 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.
> 
> 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.

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.




More information about the Chat mailing list