-14

How does stack overflow generate user ids?

Judging by the number of digits in ids, it seems they have more than a million users.

How do they handle id collisions?

4

1 Answer 1

10

They just use sequential ids. You can tell by checking the user with id of 1. It's not random. Now they probably wouldn't have to worry about collisions as long as the id sequence is determined in one server.

6
  • I guess StackOverflow's DB is distributed. How do they generate subsequent sequence numbers? Do they have one single instance hit by all clients? If so, couldn't this lead to a bottleneck if many clients request an ID at the same time? What do you think?
    – tonix
    Commented Oct 12, 2020 at 10:58
  • It's a bottleneck, but they can shard each table into it's own server and have read replicas, so the master server takes all the writes and the others handle reading which works great for this type of website because likely 99% of requests are reads. Commented Oct 12, 2020 at 16:40
  • So you say that they have a single "mega" master server which accepts all the writes and then they shard/divide and replicate the written data across several shards so that each shards servers only a portion of the whole data? If so, does it mean that the master DB server has a questions/answers table of billions of records?
    – tonix
    Commented Oct 12, 2020 at 18:02
  • 1
    In the case that was a lot of records, in Stackoverflow case turns out a single server and standby replica can handle everything: stackexchange.com/performance Commented Oct 16, 2020 at 16:09
  • 1
    I think you underestimate how much a giant bare metal optimized database server can take. Commented Oct 16, 2020 at 16:13
  • Where is this single giant master DB server mentioned at stackexchange.com/performance? Is it this beast here in the 4 SQL Servers section: Stack Overflow -> RAM: 1.5 TB • DB size: 2.8 TB? Thank you!
    – tonix
    Commented Oct 16, 2020 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .