<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 07:38:14 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[DOCS-235] Shard Key Selection/Design Tutorial</title>
                <link>https://jira.mongodb.org/browse/DOCS-235</link>
                <project id="10380" key="DOCS">Documentation</project>
                    <description>&lt;p&gt;Create a document in /tutorial/choose-a-shard-key&lt;/p&gt;

&lt;p&gt;Link to it on sharding page and the tutorial.txt page&lt;/p&gt;

&lt;p&gt;This should be the core place for information on sharding.&lt;/p&gt;</description>
                <environment></environment>
        <key id="41773">DOCS-235</key>
            <summary>Shard Key Selection/Design Tutorial</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="william.zola@10gen.com">William Zola</reporter>
                        <labels>
                            <label>sharding</label>
                    </labels>
                <created>Tue, 19 Jun 2012 19:56:17 +0000</created>
                <updated>Mon, 30 Oct 2023 22:07:05 +0000</updated>
                            <resolved>Thu, 28 Jan 2016 18:21:34 +0000</resolved>
                                                    <fixVersion>Server_Docs_20231030</fixVersion>
                                    <component>manual</component>
                        <due></due>
                            <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="1156913" author="allison.moore@10gen.com" created="Thu, 28 Jan 2016 18:21:34 +0000"  >&lt;p&gt;It would appear that this was done a while back!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.mongodb.org/manual/tutorial/choose-a-shard-key/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://docs.mongodb.org/manual/tutorial/choose-a-shard-key/&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="134479" author="william.zola@10gen.com" created="Tue, 19 Jun 2012 19:59:42 +0000"  >&lt;p&gt;Wups!  Not familiar with creating a ticket in Jira.  Here&apos;s the text section again:&lt;/p&gt;


&lt;p&gt;== Common Shard Key Design Patterns&lt;/p&gt;

&lt;p&gt;Here are three common design patterns that folks often use when picking a shard key:&lt;/p&gt;

&lt;p&gt;A) Hashed tag value&lt;/p&gt;

&lt;p&gt;This pattern is used when you&apos;re only concerned with optimizing write performance.  You take a known-unique property of the document it, run it through a hash function (MD5 is commonly used), store that as a property of the document, and use it as the shard key.&lt;/p&gt;

&lt;p&gt;The main advantages of this pattern are guaranteed good Write Distribution and the ease of coding it.  The main disadvantage of this pattern is that it guarantees that you will have poor Read Isolation on any range queries.&lt;/p&gt;

&lt;p&gt;B) Common Search Key and Timestamp&lt;/p&gt;

&lt;p&gt;In this pattern, you use a compound shard key.  The first portion is a search key that your application will often use, and the second portion is a timestamp.  Using the email messages example from above, your shard key might be something like &quot;key: &lt;/p&gt;
{ email_id: 1, timestamp: -1 }
&lt;p&gt;&quot;.  &lt;/p&gt;

&lt;p&gt;This pattern can often balance between good write performance and read performance, especially if data is coming in in timestamp order.  &lt;/p&gt;

&lt;p&gt;If there are enough distinct values for the low-cardinality key (4x the number of anticipated shards is a reasonable lower bound) then you will most likely get good write distribution.  In addition, the presence of the timestamp will allow MongoDB to split the chunks with fine granularity if necessary.  Finally, the presence of the timestamp will help Read Isolation &amp;#8211; emails to a single user within a specific time range are likely to be in a single chunk, and therefore on a single shard.&lt;/p&gt;

&lt;p&gt;The main disadvantage of this pattern is that you will have Scatter/Gather queries if you don&apos;t query by the common search key.  For example, &quot;find all emails sent two days ago by all users&quot; will result in a scatter/gather query (since the email ID isn&apos;t part of the query).&lt;/p&gt;

&lt;p&gt;C) Coarsely Increasing Counter and Common Search Key&lt;/p&gt;

&lt;p&gt;This pattern also uses a compound shard key, but in a slightly different way.  In this pattern, you use a coarsely-increasing counter as the first portion of the shard key.  For example, instead of a timestamp with millisecond granularity, you might choose only the date (year-month-day) portion of the timestamp.  If you&apos;re getting many inserts within a single day, this portion of the shard key will group them all into a single bucket.&lt;/p&gt;

&lt;p&gt;For the second portion of the shard key, you&apos;d use a frequently-used search key, as in the above pattern.  Applying this pattern to the email example, you&apos;d get something like &quot;key: &lt;/p&gt;
{ts_day: -1, email_id: 1}
&lt;p&gt;&quot;&lt;/p&gt;

&lt;p&gt;This pattern also balances between read performance and write performance but does so in a different way.  Using the coarsely-increasing counter tends to group new documents into a single shard, but adding the search key at the end allows them to split into separate chunks and be distributed onto multiple shards.  This allows for good Read Isolation, when your most common range query is by timestamp, but also allows the write load to be distributed if a single shard tends to get &apos;hot&apos;.&lt;/p&gt;

&lt;p&gt;In general, this pattern slightly optimizes read performance over write performance.  The main disadvantage of this pattern is that you&apos;re likely to get a &apos;hot&apos; shard for a while when the coarsely increasing counter rolls over to the next unit &amp;#8211; for example, when the &apos;ts_day&apos; shifts at midnight.&lt;/p&gt;

</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 15 Jan 2013 16:45:48 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        8 years, 2 weeks, 6 days ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>emet.ozar@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            8 years, 2 weeks, 6 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>allison.moore@mongodb.com</customfieldvalue>
            <customfieldvalue>william.zola@10gen.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrsgcn:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrfwnb:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>5624</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hry6l3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                </customfields>
    </item>
</channel>
</rss>