Skip to content

Concurrent bulk generation of Snowflake IDs from same machine is failing #22

Description

@anubhav-pandey1

If we try to bulk generate multiple snowflake IDs concurrently from the same machine, all the IDs are same:

const generateSnowflakeId = (machineId = null) => {
  const config = {
    instance_id: machineId,
    custom_epoch: new Date("2001-01-01").getTime(),
  };
  const uid = new Snowflake(config);
  const snowflakeId = uid.getUniqueID();
  return snowflakeId;
};

const COUNT = 10;
const CURRENT_MACHINE_ID = 1; // Assumed
const snowflakeIds = [];
for (let i = 0; i < COUNT; i++) {
  const snowflakeId = generateSnowflakeId(CURRENT_MACHINE_ID);
  snowflakeIds.push(objectId);
}

All the IDs are the same. Am I doing something incorrectly?

Node.js version: 16.17 and 18.17
Package version: 2.0.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions