#StackBounty: #database #facebook #instagram #sharding #id-generation Why would you append a shard ID to a generated ID?

Bounty: 50

I’m reading this:
https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c

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?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.