Skip to main content

In one of our implementations we need to make quite a few internal service calls and the services expect the calls to have a unique request id (max 12 chars). Whats the best way to generate them from Apihub? With the elastic pods expansion we wont be able to use npm uuid as it cannot be made unique across a cluster of pods (if i am correct). We tried to use custom objects in commercetools to store and retrieve a running number and increasing that on every call to get an incremented value -- but with this being called from every pod and there are so many of them during peak load + there are so many different services that need a running number, we see a lost of 409s due to incrementing the custom object value. Any one has done such a thing in their implementations ? Any suggestion / pointers ?

@Naga 

What about using a epoch time?

The epoch time that will be always incremented naturally :)

What do you think about this idea?

function generateId() {
const epochTimeMillis = Date.now();
const epochString = epochTimeMillis.toString();
const epoch12Char = epochString.slice(-12);
return epoch12Char;
}

Regards,

Obed


Thanks @Obed Murillo But since we see a lot of pods there could be a possibility of clash across them causing some of the requests to fail due to non uniqueness - may be we can prefix with the pod 5 char unique id and add the later bit of the epoch to fill in and see if that solves the problem. 

 


Reply