3 ms·
Yeah, I implemented a vector clock a few years ago, and I never really found an elegant way to deal with conflicts like this. My very-much-inelegant solution w
by tombert 1y ago
Yeah, I implemented a vector clock a few years ago, and I never really found an elegant way to deal with conflicts like this. My very-much-inelegant solution was every item attached an epoch time in milliseconds which was used in a tiebreaker, and if both timestamps were the same I would hash something and choose the smaller one of those.
It seems wrong to rely on NTP for a distributed system like this, but I couldn't really figure out a better way at the time.
- withinboredom 1y agoThe most elegant solutions is to look at Lamport’s other papers, like Paxos or their derivatives. Tie-breaking doesn’t actually happen at the clock level, but at the conflict resolution level, which is a bit higher. IIRC, paxos traditionally uses the node id as the tie-breaker, making leadership deterministic in the face of conflicts. Though in all honesty, NTP is mostly fine for datacenter deployments where clocks are usually within nanoseconds of each other, so you can use a timestamp with microsecond precision and probably be fine.