# How does zero move the larger shard in the group to other groups?

**URL:** <https://discuss.dgraph.io/t/how-does-zero-move-the-larger-shard-in-the-group-to-other-groups/9009>\
**Category:** Dgraph\
**Created:** [July 26, 2020, 10:25am UTC](https://discuss.dgraph.io/t/how-does-zero-move-the-larger-shard-in-the-group-to-other-groups/9009 "2020-07-26T10:25:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tss](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/tss/32/4409_2.png) [@tss](https://discuss.dgraph.io/u/tss)\
**Post date:** [July 26, 2020, 10:25am UTC](https://discuss.dgraph.io/t/how-does-zero-move-the-larger-shard-in-the-group-to-other-groups/9009/1 "2020-07-26T10:25:35Z")

</div>

When the amount of data in a group is large, will zero move the larger shard in the group to other groups? How did it move? Does the copy on the copy also move?

---

<div class="post-metadata">

**Author:** ![Naman](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/naman/32/3498_2.png) [@Naman](https://discuss.dgraph.io/u/Naman)\
**Post date:** [July 26, 2020, 2:02pm UTC](https://discuss.dgraph.io/t/how-does-zero-move-the-larger-shard-in-the-group-to-other-groups/9009/2 "2020-07-26T14:02:40Z")

</div>

Yes, Zero moves the shards from larger size groups to smaller size groups (see `--rebalanceInterval` flag). Periodically after that interval, it checks if rebalancing would be useful. The rebalancing decision is based on heuristics (currently it just uses size of groups, maybe query traffic could be another parameter to try on later).

The logic for that decision can be seen [here](https://github.com/dgraph-io/dgraph/blob/c51d007e7d53a0d313bab3e73e8536ff1fc455c0/dgraph/cmd/zero/tablet.go#L180) in the code. To summarize:

1. Sort the groups on the basis of size.
2. **Decide srcGroup:** Find the active group (from largest → smallest), and see if the size difference with the smallest group is big enough that it would be advantageous to move.
3. **Decide tablet from srcGroup:** Finds a tablet as big a possible such that on moving it dstGroup’s size is less than or equal to srcGroup.

> [@tss](#):
>
> How did it move?

You can see it here. Feel free for follow-ups.

> <https://github.com/dgraph-io/dgraph/blob/master/dgraph/cmd/zero/tablet.go#L38-L57>

> [@tss](#):
>
> Does the copy on the copy also move?

Can you please elaborate on what you mean by this?
