twitter/snowflake — Issue #6: Duplicate ids possible if clock moves backwards
Author: stefanth
Created: 2012-02-23 16:30:17+00:00
State: open

If the clock moves backwards the sequence is reset to 0 before raising InvalidSystemClock. When the time moves again forward to lastTimestamp then the IdWorker will generate duplicate ids for that millisecond (from 0 up to the old value of the sequence variable, depending on how many calls are made when that millisecond is revisited). The correct way is probably to do the "timestamp < lastTimestamp" check before the "lastTimestamp == timestamp" check.