# How many shards for 5 millions of groups?

**URL:** <https://discuss.elastic.co/t/how-many-shards-for-5-millions-of-groups/250756>\
**Category:** Elasticsearch\
**Created:** [October 2, 2020, 7:08am UTC](https://discuss.elastic.co/t/how-many-shards-for-5-millions-of-groups/250756 "2020-10-02T07:08:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![harisk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harisk/32/75997_2.png) [@harisk](https://discuss.elastic.co/u/harisk)\
**Post date:** [October 2, 2020, 7:08am UTC](https://discuss.elastic.co/t/how-many-shards-for-5-millions-of-groups/250756/1 "2020-10-02T07:08:45Z")

</div>

Now we have about **5 millions of groups** and 100 millions of users. There are about **120 million messages every day** users sent to the group, approximate **12GiB**. We'd like to use Elasticsearch to search group messages with text.

We're testing with a **time-based index** (index by **day** , **week** , and **month** ). We are also using **5 shards/index** with routing key is **groupID**.

The text analyzer is **edge-nGram** with **min-gram** is **2** and **max-gram** is **20**.

The peak **indexing rate** is **4000 req/s**. However, the **searching** is **too slow**. We've expected that we can process **3000 req/s** for searching. Because of the big number of groups, Elasticsearch spent a lot of time to query.

We've tried to compare **5 shards/index** and **11 shards/index** for both **daily-index** and **monthly-index** , but searching on **11 shards/index** is slower than **5 shards/index**. Anyway, both sharding strategies are unsatisfied with our case.

My questions are:

- Which time-based index we should use in our case? By day, week, or month?
- How many shards we should use for the selected index?

P/S

I've read [a blog from Discord](https://blog.discord.com/how-discord-indexes-billions-of-messages-e3d5e9be866f) talking about how Discord indexes billions of messages for group search. I know Discord is using **their shard allocator** which do **mapping** from **groupId** to **(cluster, index)** of Elasticsearch. Their mapping is using a database with caching. They don't use sharding from Elasticsearch because of their application-level sharding.

I concern that we should follow as Discord architecture or believe Elasticsearch Sharding.

Many thanks!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 2, 2020, 8:13am UTC](https://discuss.elastic.co/t/how-many-shards-for-5-millions-of-groups/250756/2 "2020-10-02T08:13:19Z")

</div>

If you are using routing you probably want to have a large number of primary shards as that improves efficiency. Given the you want to keep shards reasonably large this probably means you should use monthly indices.

---

<div class="post-metadata">

**Author:** ![harisk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harisk/32/75997_2.png) [@harisk](https://discuss.elastic.co/u/harisk)\
**Post date:** [October 2, 2020, 8:23am UTC](https://discuss.elastic.co/t/how-many-shards-for-5-millions-of-groups/250756/3 "2020-10-02T08:23:01Z")

</div>

Hi @Christian_Dahlqvist,

If we use monthly indices, there are about **3,6 billion documents per index**. How many shards we should use for an index and How many data nodes we should scale shards?

I'd like to try with **100 shards per index** , it is estimated to around 36 million documents/shard. Is it OK?

Tks!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 2, 2020, 8:26am UTC](https://discuss.elastic.co/t/how-many-shards-for-5-millions-of-groups/250756/4 "2020-10-02T08:26:28Z")

</div>

Aim for a shard size around 10GB and use this to determine the number of primary shards to use as a starting point. How many nodes you will need will depend on the hardware as well as the retention period.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 30, 2020, 8:26am UTC](https://discuss.elastic.co/t/how-many-shards-for-5-millions-of-groups/250756/5 "2020-10-30T08:26:38Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
