Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
"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: – JVerstry Oct 22 '12 at 9:34
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.


Andy Grove
Chief Architect

share|improve this answer

Your Answer


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.