Unique ID generator for service calls for log tracking


Userlevel 2
Badge

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 ?


2 replies

Userlevel 3
Badge

@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

Userlevel 2
Badge

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


© 2024 commercetools GmbH - All rights reserved