2
neeno
69d

Is relying on probability bad practice? I have a container that needs to know about all other instances of the same container and assign a unique ID to itself on initialization. I thought that if I selected a big random number as its id on startup, the chances of it having the same id as another instance is very low.

To prevent two instances from having the same id I could check for all running instances on the network, but what if two instances start at the same time? They won't find each other since none of them will be fully initialized when their id checks run.

Probability says I'll be fine, Murphy's law says I won't. What do?

Comments
  • 3
    Maybe set up a service that gives out IDs and keeps track of them.
  • 0
    @metamourge I thought of that but it adds some complexity I don't really want. Plus, if this fails everything else fails.
  • 0
    Honestly, I don't even want to give them IDs, the less state they have the better, but Apache Zookeeper requires an ID in initialization, for some reason it cannot determine one by itself... Maybe I'm just overcomplicating things, I should just make three containers with three different configs, one with each id. Later on I'll figure something out to enable autoscaling for it.
  • 2
    Relying on probability is not bad practice. That’s the whole premise of uuids, can you use an uuid as the instance id?
  • 0
    @abirz I think I can. I'm gonna look into it, thanks!
Add Comment