Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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:

  1. Creating relationships in databases
  2. Establishing relationships in SQL queries as necessary?
share|improve this question
    
"Sharded"? I don't know such word and can't find it in any dictionary. Did you mean "shared"? –  Jan Hudec Oct 22 '12 at 7:10
2  
"sharded" is the correct term in this question, but you could also use "partitioned" in this case. –  Jan Prieser Oct 22 '12 at 7:31
    
For more information about sharding: en.wikipedia.org/wiki/Shard_%28database_architecture%29 –  JVerstry Oct 22 '12 at 9:34

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.