I’m reading this:
In in the last section “Solution”, where they are generating a globally unique ID based on the DB’s autoincrement feature + milliseconds since epoch + shard ID.
Why do we need to append shard ID to it?
Specifically, it says
Next, we take the shard ID for this particular piece of data we’re
trying to insert. Let’s say we’re sharding by user ID, and there are
2000 logical shards; if our user ID is 31341, then the shard ID is
31341 % 2000 -> 1341. We fill the next 13 bits with this value
THis doesn’t make sense: if you are already modding user ID by number of shards (31341 % 2000), that means 1) You already have user ID! 2) You already know the shard it belongs to with the mod function!
What am I misunderstanding here?