Kiran Patil said over 6 years ago on UUID in Rails with ActiveUUID :

Hi,


I want to create a subscriber id which should be unique, can we use UUID as subscriber id ?


In general how people are creating unique subscriber id during registration ?


Do we have any ruby gem to get unique id by providing name, date and other parameter as input to the function to get new unique is ?


I also would like to know the pattern to generate ticket id as well, which is used in incident management where each reported incident is a ticket to be resolved.


Thanks.


David Kimura PRO said over 6 years ago on UUID in Rails with ActiveUUID :

You could use a UUID for this, but I think that it would probably be a bit overkill.

I would personally just do something like this with SecureRandom.hex (which is part of the ruby core)

        before_create :populate_subscriber_id
        private
        def populate_subscriber_id
          begin
            self.subscriber_id = SecureRandom.hex
          end while self.class.exists?(subscriber_id: subscriber_id)
        end

almokhtar said over 3 years ago on UUID in Rails with ActiveUUID :
any performance issues ?

David Kimura PRO said over 3 years ago on UUID in Rails with ActiveUUID :
  I had originally implemented this in an application and ended up disliking it. It was on a table with a potential of several billion records. I ended up ditching this effort as it was cumbersome to work with at times. I haven't looked back since. I ended up going with an unsigned BIGINT which can go up to 18,446,744,073,709,551,615. This was good enough for my purposes. I think that I would revisit this if I had a situation where concurrency was a major concern and duplicate IDs could be possible.

Login to Comment