5 ms·
I'm weighing in here on the comments about "Solving a problem that doesn't exist" - the database is quite loaded, and we have Redis in the stack anyway. The sol
by codebeaker 14y ago
I'm weighing in here on the comments about "Solving a problem that doesn't exist" - the database is quite loaded, and we have Redis in the stack anyway. The solution to this problem is any backend which creates unique numbers atomically; I happened to choose Redis because I'm interested in it technologically and I like the API.
It's worth mentioning that Rails doesn't encourage access to the underlying database features - and that stepping outside of the Rails/ActiveRecord results in features which are difficult to test and more difficult to maintain in the face of an ever changing API.
I don't care where the next atomic ID comes from, as long as it comes from a datastore that is fast, and that I can trust.
- kstrauser 14y ago> I'm weighing in here on the comments about "Solving a problem that doesn't exist" - the database is quite loaded Can you give a ballpark estimate of your write load? And in any case, a server-side trigger executed on insert could handle the process much closer to the data, with fewer round trips and much greater performance. > I happened to choose Redis because I'm interested in it technologically and I like the API. With due respect, you've gotta get over that. I'm all about experimentation, but there's a time to break new ground and a time to use the tools that others have already developed and tested. > It's worth mentioning that Rails doesn't encourage access to the underlying database features That may be true, but if you're pushing it near the edge of breaking, it may be time to bite the bullet and move small amounts of logic into the database. It's only very slightly harder to test - the general principals are the same - and I'd dare say far easier to maintain.
- jeltz 14y agoIt is a very isolated change so my view is that relying on your database is worth it. Furthermore sequences are very cheap in most databases, I have never heard anyone complaining about sequences in PostgreSQL being to contention point.