When designing data structures for an application, what are some best practices to make sure it can be sharded?
In particular, which of the following is better:
- Creating relationships in databases
- Establishing relationships in SQL queries as necessary?
-
"Sharded"? I don't know such word and can't find it in any dictionary. Did you mean "shared"?Jan Hudec– Jan Hudec2012年10月22日 07:10:26 +00:00Commented Oct 22, 2012 at 7:10
-
2"sharded" is the correct term in this question, but you could also use "partitioned" in this case.Jan Prieser– Jan Prieser2012年10月22日 07:31:01 +00:00Commented Oct 22, 2012 at 7:31
-
For more information about sharding: en.wikipedia.org/wiki/Shard_%28database_architecture%29Jérôme Verstrynge– Jérôme Verstrynge2012年10月22日 09:34:43 +00:00Commented Oct 22, 2012 at 9:34
1 Answer 1
You would typically shard a group of tables based on a key such as customer_id. One simple approach is to use the modulus. For example if you have 4 shards then divide the customer_id by 4 and use the remainder to determine which shard to use.
However, this approach isn't very flexible when you want to change the number of shards later on.
You may want to read this database sharding whitepaper that explains the theory in much more detail.
Regards,
Andy Grove
Chief Architect
http://www.dbshards.com