How to configure the workerID of the current machine in distributed mode?

I am using the [flake-idgen]( npm library, which is used for generating ordered IDs in distributed scenarios.
It allows configuration of datacenter and worker IDs.
For example, I have two machines, both with datacenter ID set to 0, with worker IDs set to 0 and 1, respectively.
How should I configure this in I was planning to do the configuration via secrets, but it doesn’t seem quite right. :flushed:

1 Like

I glanced the docs and seems that those values are bits, if they could have been string you could just use the machine ID and region maybe. Here’s a few suggestions, feel free to mix, change iterate on them:

  • My go to way would be set enviroment variables specific for each machine and pick those values as you wish. You can use fly m update MACHINE_ID -e WORKER=1 DATACENTER=0 for example.
  • You can get fancy by mapping regions to a datacenter number maybe. Like iad=0 and gru=1. We will add more regions on the future but using the current known regions can get you far.
1 Like

Thanks, Can environment variables be obtained using process.env.WORKER? Maybe I should try it.

Yup, they can!

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