How would I learn more about sharding userdata for a website?

后端 未结 2 1219
情话喂你
情话喂你 2021-02-06 16:52

I\'m interested in sharding my websites user data across multiple servers.

For example, users will login from the same place. but the login script needs to figure out wh

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 17:32

    One option you might want to consider: use a simple hash. For example, take the MD5 hash of the username, then treat the last 8 bytes of that as a long. Take that long mod (number of servers) and make that the server to put the data on. That way you don't need any central registry/configuration other than an ordered list of servers.

    The disadvantage is that changing the number of servers involves moving all the data to the new "correct" location...

    (There's also the matter that if one machine goes down, those users are stuffed - you'll want to consider having some sort of redundancy.)

提交回复
热议问题