osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Randomizing Strings In A Microservices World


Tim Daneliuk wrote:

> I ran across a kind of fun problem today that I wanted to run past you
> Gentle Geniuses (tm):
> 
> - Imagine an environment in which there may be multiple instances of a
> given
>   microservice written in Python.
> 
> - Each of these services needs to produce a string of ten digits
> guaranteed to be unique
>   on a per service instance basis AND to not collide for - oh, let's say -
>   forever :)s
> 
> Can anyone suggest a randomization method that might achieve this
> efficiently?
> 
> My first thought was to something like nanonseconds since the epoch plus
> something
> unique about the service instance - like it's IP?  (This is in a K8s
> cluster) - to see the randomization and essentially eliminate the string
> being repeated.
> 
> Ideas welcome ..
> 
> P.S. I do not want to resort to a number generation service that each
> instance asks
>      for a new number.  The network and service call overhead militates
>      against this in my application.

Hand out a range of numbers when the service is started. Once that range is 
used up the service can terminate itself.