tags:

views:

1018

answers:

1

1) Anyone know the difference between redis replication and redis sharding? 2) What are they use for? Redis stores data in memory, how does this affect replication/sharding? 3) Is it possible to use both of them together?

Thank you!

+9  A: 

Sharding is almost replication's antithesis, though they are mutually exclusive concepts and work well together.

Sharding, also known as partitioning, is splitting the data up by key; While replication, also know as mirroring, is to copy all data.

Sharding is useful to increase performance, reducing the hit and memory load on any one resource. Replication is useful for high availability. If you read from multiple replicas, you will also reduce the hit rate on all resources, but the memory requirement for all resources remains the same.

Suppose you have the following tuples: [1:Apple], [2:Banana], [3:Cherry], [4:Durian] and we have two machines A and B. With Sharding, we might store keys 2,4 on machine A; and keys 1,3 on machine B. With Replication, we store keys 1,2,3,4 on machine A and 1,2,3,4 on machine B.

Sharding is typically implemented by performing a consistent hash upon the key. The above example was implemented with the following hash function h(x){return x%2==0?A:B}.

To combine the concepts, We might replicate each shard. In the above cases, all of the data (2,4) of machine A could be replicated on machine C and all of the data (1,3) of machine B could be replicated on machine D.

Any key-value store (of which Redis is only one example) supports sharding, though certain cross-key functions will no longer work. Redis supports replication out of the box.

Alex
cool. i think the answer not only limited to redis
joetsuihk
Good answer (in general), but does not really answer the question imho :)
Sune Rievers