Is it possible to translate RENDER_INSTANCE_ID into "index" of instance?

Hey, I’m trying to determine if I can leverage horizontal scaling for my Discord.js bot hosted on render. To do this I believe the straightforward approach would be to know if code was running on render instance 0, 1, 2,… N. I found the RENDER_INSTANCE_ID env variable, but I’m not sure how to translate that into a “index” to indicate which render instance the code is running in.

For more context about discordjs/why I’m looking for this info:

The tricky part about discordjs is that only one instance of the bot can be active at a time per server. This is improved with sharding which they provide a useful API for, but it does not support a load balancing approach like a web app.

HOWEVER - the code must manually tell the shard manager which shards to run on the current instance. This would be fairly straightforward if I had a simple number to indicate which render instance the code was currently running on, I could basically take shard count / render instance count and then increment by the instance index, and voila each instance would manage it’s set of shards.

Thanks in advance for any help!

Hi Billy,

Thanks for reaching out.

Scaled instances on services don’t have an index number, but the last 5 characters of the RENDER_INSTANCE_ID will be unique to the instance. If you could utilise that, then you may be able to achieve your sharding.

Kind regards

Alan

Hmm - these are just random characters, not some kind of encoded timestamp or anything right?

Yes, just random characters.

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.