Different env variables for manual scaling?

Hey all!

I have a web service that I want to manually scale from 1 instance to 2 instances. However, I want a specific env variable to be different between the 2 instances. E.g. let’s say I have NAME (currently defined in a env group) that I want to be set to be INSTANCE_1 for the first instance and INSTANCE_2 for the second one.

How would I go about setting instance specific env variables when I manually scale?

My root problem is when I have 2 instances, I will have concurrency issues calling an API. So I basically want to solve the issue by giving each instance a unique, separate, and distinct API key to use.

We don’t have any way in the platform to achieve this. But you could probably come up with a way to achieve it though. A key can’t have different values so you’d have to have multiple keys and use RENDER_INSTANCE_ID which will be unique per instance and read from a different key

John B

Hey John! RENDER_INSTANCE_ID is different each time the service is deployed – is there a way to know how many instances of a service are live, and if we’re currently on the “second” or “third” instance which should use a different key?

Not built into the platform - but if you were to store the RENDER_INSTANCE_IDs in a Redis key as services start (empty it on build) you could figure out which instance you were on based on the index of the ID in the key.

John B

1 Like

Hey John! For some reason, it seems like every time we redeploy our service, there is a “ghost” deploy. For example, we have 3 Render instances and we have a startup function that should only be run 3 times. However, it’s running 4 times and we’re obviously getting an error. How can we fix this?

Michael,

When services are deployed we run a port detection process to determine the ports that your service is listening on, this involves booting your service to inspect its ports. As you’ve discovered this can have adverse effects if you’re doing something like you’re doing here.

You have 2 options however

  • If you set PORT to the port you’re running your service on we would not run port detection
  • Inspect `RENDER_PORT_DETECTOR and if it’s true then don’t run your start up script.

I hope that helps,

Regards,

John B

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