if (this.sequence < Snowflake.MAX_SEQUENCE) { I think here: if (this.sequence < (Snowflake.MAX_SEQUENCE - 1)) {