<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Steven Tseng on Medium]]></title>
        <description><![CDATA[Stories by Steven Tseng on Medium]]></description>
        <link>https://medium.com/@stetseng?source=rss-844770727efb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*g2W8l5SatFov2o7yma6nzQ.jpeg</url>
            <title>Stories by Steven Tseng on Medium</title>
            <link>https://medium.com/@stetseng?source=rss-844770727efb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 20:44:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stetseng/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Handling 10M offline matchmaking using Amazon OpenSearch (Part 4 of 4)]]></title>
            <link>https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-4-of-4-b28a43ad943a?source=rss-844770727efb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b28a43ad943a</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[opensearch]]></category>
            <category><![CDATA[offline]]></category>
            <category><![CDATA[matchmaking-service]]></category>
            <dc:creator><![CDATA[Steven Tseng]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 01:01:59 GMT</pubDate>
            <atom:updated>2022-10-12T01:53:46.128Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the final part of my 4-part Matchmaking with Amazon OpenSearch series. In this part, we will explore CloudWatch monitoring, additional tips and best practices for your OpenSearch cluster, look at the <strong>randomise function</strong>, and dive a bit deeper into <strong>Atomicity</strong>.</p><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-1-of-4-3fc720e1c598">For the introduction definition of the problem and how I decided to choose this service as a solution, please refer to Part 1.</a></p><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-2-of-4-a6e92cce402f">In Part 2 we covered Data ingestion, server capacity planning and preparation.</a></p><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-3-of-4-69f5dbf3ddfd">In Part 3, we covered OpenSearch queries, visualisations and dashboards.</a></p><p><em>As each game’s design is unique, with different mechanics and matchmaking requirements, I’ve written this blog with the intention of sharing my knowledge. The contents of this blog are my opinions only.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YFhVOjpndIaYoNTSM0VjnQ.png" /></figure><h3>Additional Tips</h3><h4>CloudWatch monitoring &amp; SlowLogs</h4><p>As OpenSearch has close integration with Amazon CloudWatch, OpenSearch service can expose the following logs directly into CloudWatch</p><ul><li>Error logs</li><li>Search Slow logs</li><li>Indexing Slow logs</li><li>Audit logs</li></ul><p>By default, <strong>these logs are not enabled</strong>, but you can easily enable either through the console, AWS CLI or the AWS SDK. It is highly recommended you have separate log streams for each of the log types, and enable Search Slow Logs to track down which queries do not meet an expected time threshold. For additional information, <a href="https://docs.aws.amazon.com/opensearch-service/latest/developerguide/createdomain-configure-slow-logs.html">please refer to the documentation here</a>.</p><p>To enable slow logs, you need to perform some additional steps, which are outlined on the <a href="https://opensearch.org/docs/latest/opensearch/logs/#slow-logs">OpenSearch documentation</a>.</p><p>Remember to set appropriate CloudWatch log group lifecycle policies, so you don’t keep logs unnecessarily beyond a period of time.</p><h4>OpenSearch Best Practices</h4><p>Because OpenSearch can become more and more operationally complex at scale, a number of best practices are available through <a href="https://docs.aws.amazon.com/opensearch-service/latest/developerguide/bp.html">documentation here</a>. Generally, you want to ensure that you have appropriate monitoring and analytics alarms setup, to cover the main concerns:</p><ul><li><strong>OpenSearch cluster hard drive space </strong>— Because of the way Lucene indexes use immutable segments (see part 2), we want to ensure that the cluster does not run out of hard drive space when performing segment merges. Be sure to scale up your database usage, and monitor your database hard disk usage and ensure your cluster can handle spikes during heavy merge processes.</li><li><strong>Cluster CPU / Memory health </strong>— You can monitor these metrics by either navigating to the <strong>Cluster Health </strong>tab of your OpenSearch cluster, or by viewing these metrics through CloudWatch metrics.</li><li><strong>Have a RPO / RTO for backup data</strong>, and test that your data is being appropriately restored</li><li>Ensure you have appropriate security and user policy setup, to prevent unauthorised access, and avoid public subnet OpenSearch configurations whenever possible. To connect to a private subnet OpenSearch cluster, you could use a bastion host, or through a network VPN.</li></ul><h4>Randomise Function</h4><p>With OpenSearch, you can randomise the results from running a query if you use the random_score attribute in your request. You will need to specify the random_score function within your query statement, such as the following:</p><pre>{<br>   &quot;query&quot;: {<br>      &quot;function_score&quot;: {<br>         &quot;query&quot;: {<br>            ...<br>         },<br>         &quot;random_score&quot;: {<br>            &quot;seed&quot;: &quot;1234&quot;,<br>            &quot;field&quot;: &quot;_seq_no&quot;<br>         }<br>    }<br>  }<br>}</pre><p>Breaking down how the random_score function works, if you don’t specify any values, the random_score function will use an internal Lucene document ID as the source of randomness, which is very efficient, but not reproducible as documents might be renumbered by merges.</p><pre>&quot;random_score&quot;: {<br>   &quot;seed&quot;: 10,<br>   &quot;field&quot;: &quot;_seq_no&quot;<br>}</pre><p>If you wanted to be able to reproduce the random_score results, you can specify the seed and field values. The field allows you to use a particular field to influence the score.</p><p>For deeper examples, please refer to the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-random">ElasticSearch</a> documentation.</p><h3>Atomicity</h3><p>Atomicity, and ACID (Atomic, Consistent, Isolated and Durable) transactions is a priority consideration if you are running workloads where reading and writing of documents can happen very quickly in parallel.</p><p><strong>Referring </strong><a href="https://discuss.elastic.co/t/transactional-acid-features-in-es/5357/2"><strong>to this post by Elastic’s Staff </strong></a><strong>— Atomicity is performed at the per document level. If you wanted to ensure that your transactions are ACID (Atomic, Consistent, Isolated and Durable), you need to pay careful attention to the difference in single vs bulk updates.</strong></p><p>When a bulk update is performed, each single transaction can succeed or fail independently of other actions — as opposed to an all-or-nothing approach.</p><p>With single document changes, you can use the _seq_no and _primary_term fields to restrict document updates to apply only against the latest version.</p><pre>POST /matchmaking/_update/cc840cee-3d82-438b-8cb1-607fff5b6d6a?if_seq_no=1029086&amp;if_primary_term=1</pre><pre>OR</pre><pre>POST /matchmaking/_update/cc840cee-3d82-438b-8cb1-607fff5b6d6a<br>{<br>  &quot;doc&quot;: {<br>    ...<br>  },<br>  &quot;if_seq_no&quot;: &quot;2151984&quot;,<br>  &quot;if_primary_term&quot;: 1<br>}</pre><p>To retrieve results with seq_no and _primary_term, use the seq_no_primary_term: true</p><pre>{<br>   &quot;query&quot;: { ... },<br>   &quot;seq_no_primary_term&quot;: true<br>}</pre><p>If you try and update the document with the wrong sequence number or primary term, you will encounter an error:</p><pre>{<br>  &quot;error&quot; : {<br>    &quot;root_cause&quot; : [<br>      {<br>        &quot;type&quot; : &quot;version_conflict_engine_exception&quot;,<br>        &quot;reason&quot; : &quot;[cc840cee-3d82-438b-8cb1-607fff5b6d6a]: version conflict, required seqNo [2151984], primary term [1]. current document has seqNo [2151985] and primary term [1]&quot;<br>      }<br>    ],<br>    &quot;type&quot; : &quot;version_conflict_engine_exception&quot;,<br>    &quot;reason&quot; : &quot;[cc840cee-3d82-438b-8cb1-607fff5b6d6a]: version conflict, required seqNo [2151984], primary term [1]. current document has seqNo [2151985] and primary term [1]&quot;<br>  },<br>  &quot;status&quot; : 409<br>}</pre><h3>Cost</h3><p>When considering cost, it is always important to understand the different ways you could reduce the cost of running your cluster. You may be able to use the included free tier — 750 hours per month of t2.small.search or t3.small.search with 10GB of EBS volume, to test your use case at no cost.</p><p>Take for example the on-demand running price of a r6g.large cluster</p><ul><li>r6g.large (US-East-1) | $0.167 USD p/hr | $4 USD per day</li></ul><p>If you have an expected baseline volume of traffic where you can take advantage of Reserved Instances, you can cost optimise your cluster with commitment based savings:</p><p><strong>1 Year — No Upfront</strong></p><ul><li>r6g.large (US-East-1) | $0.115 USD p/hr | $2.76 USD per day — 31% savings</li></ul><p><strong>1 Year — Partial Upfront</strong></p><ul><li>r6g.large (US-East-1) | $0.112 USD p/hr | $2.68 USD per day — 33% savings</li></ul><p><strong>1 Year — Fully Upfront</strong></p><ul><li>r6g.large (US-East-1) | $0.109 USD p/hr | $2.62 USD per day — 35% savings</li></ul><p><strong>3 Year — No Upfront</strong></p><ul><li>r6g.large (US-East-1) | $0.087 USD p/hr | $2.08 USD per day — 48% savings</li></ul><p><strong>3 Year — Partial Upfront</strong></p><ul><li>r6g.large (US-East-1) | $0.084 USD p/hr | $2.02 USD per day — 50% savings</li></ul><p><strong>3 Year — Fully Upfront</strong></p><ul><li>r6g.large (US-East-1) | $0.080 USD p/hr | $1.92 USD per day — 52% savings</li></ul><p>Looking at the above numbers, the best value for savings would be 1 year no-upfront options, as you don’t have any immediate capital expenses, but have to adjust for the next year of steady workload. 3 Years is another option if you know your workload may not change across a 3 year timeframe.</p><h3>Conclusion</h3><p>Hopefully by the end of this blog you have learned how you could tackle offline matchmaking, by using Amazon OpenSearch. Some of the content i have covered can be transferred to non-gaming usecases, especially around server capacity management, and understanding how shards and the lucene segments operate.</p><p>I hope this 4 part blog helps you in your decision making when thinking about potential services you could use with designing your own game matchmaking service.</p><p>If you would like to get in touch, please reach out at stetseng@amazon.com — Always happy to have a chat!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b28a43ad943a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling 10M offline matchmaking using Amazon OpenSearch (Part 3 of 4)]]></title>
            <link>https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-3-of-4-69f5dbf3ddfd?source=rss-844770727efb------2</link>
            <guid isPermaLink="false">https://medium.com/p/69f5dbf3ddfd</guid>
            <category><![CDATA[opensearch]]></category>
            <category><![CDATA[matchmaking-service]]></category>
            <category><![CDATA[offline]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Steven Tseng]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 01:00:38 GMT</pubDate>
            <atom:updated>2022-10-12T01:53:36.771Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the third part of my 4-part Matchmaking with Amazon OpenSearch series. In this section, we will dive into writing some OpenSearch queries, review some performance numbers, and also craft some visualisations and dashboards to understand our data in a better fashion.</p><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-1-of-4-3fc720e1c598">For the introduction definition of the problem and how I decided to choose this service as a solution, please refer to Part 1.</a></p><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-2-of-4-a6e92cce402f">In Part 2 we covered Data ingestion, Server Capacity Planning and Preparation.</a></p><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-4-of-4-b28a43ad943a">If you want to skip to Additional tips, Atomicity and cost, please navigate to Part 4.</a></p><p><em>As each game’s design is unique, with different mechanics and matchmaking requirements, I’ve written this blog with the intention of sharing my knowledge. The contents of this blog are my opinions only.</em></p><h3>Deep Dive — Writing OpenSearch Queries</h3><p>While you can use HTTP parameters to perform simple searches, for more complex queries you want to either use domain-specific language (DSL), or SQL. For this blog, I’ll be referring to DSL and take you through how I crafted my own parameters using DSL, step-by-step.</p><p><strong>Simple Example — Must match</strong></p><p>The simplest example to start with is to perform a match against the playerLevel. The <a href="https://opensearch.org/docs/latest/opensearch/query-dsl/bool/">bool</a> logic allows you to combine multiple search queries, narrowing or broadening your search results.</p><p>Because OpenSearch &amp; ElasticSearch are based on a relevance value in order to rank search results, be careful with the should keyword. Results that should not be returned may appear, due to the should keyword impacting the relevancy scores, as opposed to an explicit match. For explicit matching, you need to use the must keyword.</p><pre>POST /_search <br>{<br>   &quot;size&quot;: 5,<br>   &quot;query&quot;: {<br>      &quot;bool&quot;: {<br>         &quot;must&quot;: [<br>            {<br>               &quot;match&quot;: {<br>                  &quot;playerLevel&quot;: 10<br>               }<br>            }<br>         ]<br>      }<br>   }<br>}</pre><p>What if we want to write a query that involves a <strong>WHERE</strong> clause?</p><p>For example:</p><p><em>Return results for users with a playerLevel of 5, WHERE their player score is between 1000 and 1200</em></p><p>We want to use the filter keyword because a filter keyword is a binary yes-no option. Filter options have no impact on relevancy scores, and you generally want to use <strong>Filters on exact matches, ranges, dates, numbers etc.</strong></p><pre>POST /_search <br>{<br>   &quot;size&quot;: 5,<br>   &quot;query&quot;: {<br>      &quot;bool&quot;: {<br>         &quot;must&quot;: [<br>            {<br>               &quot;match&quot;: {<br>                  &quot;playerLevel&quot;: 5<br>               }<br>            }<br>         ],<br>         &quot;filter&quot;: [<br>            # FOR RANGE            <br>            {<br>               &quot;range&quot;: {<br>                  &quot;powerScore&quot;: {<br>                     &quot;gte&quot;: 1000,<br>                     &quot;lte&quot;: 1200<br>                  }<br>               }<br>            },<br>            # FOR EXACT<br>            {<br>               &quot;term&quot;: {<br>                  &quot;powerScore&quot;: 1200<br>               }<br>            }      <br>         ]<br>      }<br>   }<br>}</pre><p>You can also apply filters on ISO8601 date strings, using gt,gte, lt, lte operators.</p><pre>POST /_search<br>{<br>   &quot;size&quot;: 10,<br>   &quot;query&quot;: {<br>      &quot;bool&quot;: {<br>         &quot;must&quot;: [<br>            {<br>               &quot;match&quot;: {<br>                  &quot;playerLevel&quot;: 12<br>               }<br>            }<br>         ],<br>         &quot;filter&quot;: [<br>            {<br>               &quot;range&quot;: {<br>                  &quot;dateTimeCreated&quot;: {<br>                     &quot;gte&quot;: &quot;2022-08-05T04:12:00+0000&quot;<br>                  }<br>               }<br>            }<br>         ]<br>      }<br>   }<br>}</pre><h3><strong>Performance Numbers</strong></h3><p>Running 500 iterations on my OpenSearch cluster (5 primary shards, 10,774,298 documents), I’ve captured the average running time of performing each iteration, including the minimum and maximum for each set of iteration.</p><p>I ran these metrics using my own laptop from Perth, Australia before switching to a physical location in Melbourne, Australia, to compare the latency difference.</p><p><em>With performance of OpenSearch results, these values are to be used as a guideline, and may not reflect your own experience. Please ensure you test extensively with your own data, as your numbers may be different.</em></p><p><strong>Australia — Perth to Sydney (~3290km)</strong></p><ul><li>Highest: 324.340ms (first run, was slow)</li><li>Lowest: 63.025ms</li><li>Average: 63.025ms</li></ul><p><strong>Australia — MELBOURNE to SYDNEY (~708km) — Test 1</strong></p><ul><li>Highest 69.075ms</li><li>Lowest 13.890ms</li><li>Average: 21.293ms</li></ul><p><strong>Australia — MELBOURNE to SYDNEY — Test 2</strong></p><ul><li>Highest: 46.593ms</li><li>Lowest: 12.269ms</li><li>Average: 17.283ms</li></ul><p><strong>Australia — MELBOURNE to SYDNEY — Test 3</strong></p><ul><li>Highest: 116.370ms</li><li>Lowest: 11.901ms</li><li>Average: 16.336ms</li></ul><p>One of the most common patterns I noticed was the highest initial request, which can be explained by the overhead of setting up connection pooling, and how these connections were performed through a public endpoint and not a private VPC connection.</p><p>Some additional fine tuning for performance could be performed such as:</p><ul><li>F<a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/preload-data-to-file-system-cache.html">ield data preloading</a></li><li>Index warming (<a href="https://www.elastic.co/blog/elasticsearch-data-lifecycle-management-with-data-tiers">ES Node Roles</a>, <a href="https://docs.aws.amazon.com/opensearch-service/latest/developerguide/ultrawarm.html">OpenSearch Ultrawarm Storage</a>) or</li><li>Using <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html">doc_values</a></li></ul><p>Additional tips can be found in <a href="https://aws.amazon.com/premiumsupport/knowledge-center/opensearch-latency-spikes/">this AWS premium support article</a>.</p><h3>Visualisations and Dashboards</h3><p>In Part 2, we’ve ingested 10 M records into our OpenSearch cluster, and in this part we’ve written and used queries to retrieve these records with sub 20ms latency. We will now dive into the OpenSearch dashboard feature, and create a few visualisations.</p><p><strong><em>Note: </em></strong><em>Remember to set the date period at the top right, otherwise your charts and dashboards may not show data as it is set to a rolling time window.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HjvsoUzQhD1wNU9D9vdh9A.jpeg" /><figcaption>Example dashboard showing different visualisations</figcaption></figure><p>Let’s start with the easiest visualisation, which is the count of total players.</p><ol><li>Start by navigating to the <strong>visualisations, </strong>by navigating through the sidebar</li><li>Select the <strong>Metric </strong>visualisation, and after choosing your source, you should get a nice simple visualisation of your document count.</li></ol><p>To add this visual to your dashboard, navigate to <strong>Dashboard </strong>using the sidebar again, and if you do not have a dashboard already, create a new dashboard.</p><p>You can add visuals to your dashboard using the add button on the top right toolbar. Just remember to <strong>save</strong> after you make any changes to your dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3972g6Ai7xQ55uhDa54vpw.jpeg" /></figure><p>Now that we have a simple visualisation, we will create a more complicated visualisation, involving stacked bars and lines.</p><h3>Creating a stacked bar chart:</h3><ol><li>Repeat the same process as before, and select the <strong>Vertical Bar</strong> option.</li><li>After choosing your source, use the right inspector window to modify the Bucket option and set the x-axis to <strong>aggregate by terms</strong>, upon the <strong>field playerLevel</strong>. A bucket is used to categorise a set of documents.</li><li>You can modify the Order Size, if you have more values you want to chart, modify the panel options, labels and colours with the other chart tabs.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-0S45xcEvLDUF5p_0WRzw.jpeg" /><figcaption>Stack bar chart</figcaption></figure><h3>Creating a multiple line chart</h3><p>Maybe we want to show a specific range of minimum, average and maximum values, given by the player level, such as a player’s range of power scores. We can easily show this by creating a multiple y-axis line chart.</p><ol><li>Start by creating another visual, and this time select the <strong>line </strong>option.</li><li>Modify the Y-Axis aggregation to Min, and set the field to powerScore</li><li>Set the bucket X-Axis to playerLevel, and you should see the line begin to populate</li><li>If you are not seeing your data, check the time period setting on the top right.</li><li>Remember to save your visualisation</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-qxWq3YwEbY-74tJKBidg.jpeg" /><figcaption>Line Chart with single Y-Axis, repeat for Max and Average</figcaption></figure><p>Finally, we can add these visualisations onto our dashboard, and congratulations, you now have a populated dashboard!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HjvsoUzQhD1wNU9D9vdh9A.jpeg" /><figcaption>Example dashboard with multiple visualisations</figcaption></figure><h3><strong>Up Next: Additional Tips, Atomicity &amp; Cost</strong></h3><p>That concludes part 3, please <a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-4-of-4-b28a43ad943a">navigate to Part 4 for additional tips, CloudWatch logging, best practices, atomicity, random scores and cost.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69f5dbf3ddfd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling 10M offline matchmaking using Amazon OpenSearch (Part 2 of 4)]]></title>
            <link>https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-2-of-4-a6e92cce402f?source=rss-844770727efb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6e92cce402f</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[opensearch]]></category>
            <category><![CDATA[offline]]></category>
            <category><![CDATA[matchmaking-service]]></category>
            <dc:creator><![CDATA[Steven Tseng]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 01:00:01 GMT</pubDate>
            <atom:updated>2022-10-12T01:53:23.860Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the second part of my 4-part Matchmaking with Amazon OpenSearch series. For this part, we will dive into data ingestion and dive into how to plan for server capacity.</p><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-1-of-4-3fc720e1c598">For the introduction definition of the problem and how i decided to choose this service as a solution, please navigate to Part 1.</a></p><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-3-of-4-69f5dbf3ddfd">If you want to skip to OpenSearch queries, visualisations and monitoring, please navigate to Part 3.</a></p><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-4-of-4-b28a43ad943a">If you want to skip to CloudWatch monitoring, Additional tips, Atomicity and cost, please navigate to Part 4.</a></p><p><em>As each game’s design is unique, with different mechanics and matchmaking requirements, I’ve written this blog with the intention of sharing my knowledge. The contents of this blog are my opinions only.</em></p><h3>Data Ingestion — Planning &amp; Preparation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-5-goMWjsUGyfKsRhAXLfQ.png" /></figure><p><em>All good things start with data</em>. With data being the backbone of your player base and matchmaking, you need to make sure your data is formatted, presented and filtered in the right format, while considering whether auxiliary metadata has a material impact in affecting the results being returned. You may need to factor these additional considerations for your data format:</p><ul><li><strong>User location</strong> having a higher impact on latency &amp; gameplay</li><li>Whether player score / ranking / power restricts the pool of players</li><li>New Player requirements — a player beneath a certain level cannot engage in matchmaking game modes</li><li>A mechanism to capture Player feedback on whether they are enjoying or disliking the matchmaking algorithm</li></ul><p>By defining these attributes upfront, you generally only want to store the data you need, otherwise you will over-indexing unnecessary data and impact both your storage &amp; performance. For example it’s not necessary to store a binary representation of your user’s profile image, in your matchmaking service unless a player’s profile image is used as an auxiliary attribute.</p><p>For an example data set to represent my player data, I have defined the player data inJSON format as follows:</p><pre>{<br>    &quot;playerId&quot;: &quot;12693c84-da92–4eab-aeae-8b3ea87d1705&quot;,<br>    &quot;playerLevel&quot;: 5,<br>    &quot;powerScore&quot;: 1500,<br>    &quot;dateTimeCreated&quot;: &quot;2022-08-04T10:30:25.346&quot;<br>}</pre><h3>Server Capacity planning , Sharding &amp; Dedicated Master Nodes</h3><p>When planning for capacity, there is unfortunately no definitive formula to prescribe for all use-cases. You are highly encouraged to run tests and observe the storage and performance requirements on a representation of your cluster as you scale up. If you are running a large-scale busy production environment, it’s always advised to start with an over-provisioned environment to prevent impacts of disruption, and then slowly scale down and right size accordingly once you understand your cluster requirements.</p><p>One of the toughest and common questions is on your sharding strategy. Taking learnings from the <a href="https://videos.elastic.co/watch/jhzuMRajpCR5E8r4e3n8PD?chapter=1">Elastic Sharding video</a>, you need to work backwards from your organisation and data requirements, to support your expected index and search rate. If you don’t have clear business index or search rate requirements, you can run experiments to measure performance of your cluster, and see whether it is within an acceptable value.</p><p>In order to maximise your OpenSearch performance, you start by running a couple of experiments:</p><ol><li>We start with a <strong>Single node cluster</strong>, <strong>1 index</strong>, <strong>1 primary shard</strong> and <strong>0 replicas</strong>. This gives us a simple cluster to perform experiments and compare baseline performance.</li><li>Index a decent amount of data (1GB or 10m documents)</li><li>Measure our disk utilization rate, and how much storage it uses after a force merge. A force merge is important for logging / timeseries use-cases, as we only perform this action when we are 100% certain we have finished writing to that index.</li><li>We determine the point of diminishing returns, using realistic queries to plot the index speed against your query response time. After doing this we will be able to see when a shard is saturated, and does not meet your expected response time.</li><li>Repeat with 2 primary shards, and repeat steps 2–4.</li></ol><p>After you repeat this experiment a couple times, you will see the maximum number of shards a node can utilise before hitting diminishing returns.</p><p>Following <a href="https://docs.aws.amazon.com/opensearch-service/latest/developerguide/bp.html">OpenSearch best practices</a>, you generally want to keep your shard size between 10 GB to 50 GB for better performance.</p><p>With your data nodes, <strong>your cluster will operate as fast as your slowest node</strong>. With this in mind, if you run data nodes across 2 Availability-Zones. You want to have an even amount of shards, as an uneven amount of shards will be distributed unevenly across the nodes. If you are looking at a 3 Availability Zone setup, you want to have a multiple-of-3 shard value (3, 6, 9 etc), so the shards are evenly balanced across your nodes.</p><p>In this blog series, I’ve used a r6g.large instance, with default settings3 nodes, default5 primary shards and 1 replica shard , as a baseline to experiment performance with.</p><h3><strong>Volume Size and Lucene’s Immutable Segments</strong></h3><p>When considering how much hard drive volume to provision for your cluster, you first need to understand how the Lucene shards handles the document operations, and commits the data to disk.</p><p>At a high level, each Index consists of 1 or more shards. As data is written to a shard, it will be periodically written to an immutable Lucene segment. Only after these segments are committed to disk —will the data become available for querying. As the number of segments grow, periodically these segments will be consolidated into a larger segment — this is a process referred to as a <strong><em>merge. </em>As all segments are immutable, disk size usage will fluctuate due to new merged segments being created before the the replaced segments can be deleted.</strong></p><blockquote><strong>Merging can be disk intensive in terms of disk I/O</strong></blockquote><p>As segments are immutable, <strong>updating a document</strong> requires the document to be added as an updated version, and then deleted. Deleted documents additionally undergo a similar set of operations, and will tie up some disk space, and some system resources until they are merged out, due to the immutable nature of segments.</p><p>It is imperative you over-provision your hard disk requirements for your cluster, to prevent your data nodes from crashing &amp; restarting due to large segments being merged and running out of disk space.</p><p>For additional information, please refer to <a href="https://www.elastic.co/blog/how-many-shards-should-i-have-in-my-elasticsearch-cluster">Elastic’s blog on Shards and the Index Segment lifecycle here</a>.</p><h3><strong>Dedicated Master Nodes</strong></h3><p>Dedicated master nodes performs cluster management tasks, and does not hold data or respond to data upload requests. The offloading of cluster management tasks increases the stability of your cluster, so your reader and writer nodes are not having to perform cluster management tasks in addition to data operations.</p><p>For development environments, you can get away with using 1 dedicated master node, but for production workloads you want to have minimum 3 dedicated master nodes. When a dedicated master node is impacted with downtime, the cluster conducts an election using the quorum of nodes. This is why we need to avoid an even number of dedicated master nodes, otherwise the cluster is unable to reach a consensus on electing a new leader. A quorum is the number of dedicated master nodes / 2 + 1 (rounded down to the nearest whole number).</p><h3><strong>OpenSearch Public Subnet — Security Consideration</strong></h3><p>If you are using an OpenSearch cluster which is publicly accessible, commonly seen in development / testing setups, you need to ensure you sign your <a href="https://docs.aws.amazon.com/opensearch-service/latest/developerguide/request-signing.html">HTTP requests using V4 signature</a>. If you do not sign your requests, the endpoint will time out and not respond. Also remember to add additional guardrails of security, such as <strong>IP whitelisting</strong> and <strong>restricted user permission boundaries</strong> when using public subnet setups.</p><h3>Importing Data</h3><p>When importing data, you have two methods at your disposal — Single and Bulk. At first glance, the two methods may not seem that different, except when we start to import data at scale. Always remember each insert inbulk imports can independently fail of one another as opposed to where if 1 insert fails, all inserts fail, so if you need to guarantee itemized transactional inserts, you should include the if_seq_no and if_primary_term parameters. More on this in <strong>Part 4: Atomicity</strong></p><p>Running my experiment, I started with a local NodeJS application, performing single insert commands running in a loop. I hit a maximum of ~640 Indexing rate per minute, roughly 10–15 inserts per second.</p><p>Seeing if my indexing rate is linear, I scaled up my NodeJS processes to run 3 in parallel, and indexed at a rate of ~1800 per minute. This was far too slow because it would have taken hours to insert the 10 M records.</p><p>Switching my NodeJS application to utilise bulk insert to batch 100 records at a time, the single NodeJS process hit an index rate of 38,000 per minute (633 per second, increased 59x performance).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rUhk5F7u-21wOxqYiUfhBw.png" /><figcaption>Indexing Rate — 1 Process, 3 Process and Bulk Process</figcaption></figure><p>Tripling the NodeJS bulk insert processes, I managed to saturate the node, hitting ~100,000 indexes per minute (1666 per second), with the CPU operating at 85%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ciYxEg6tkvrKm-n1kQzkVw.png" /><figcaption>Indexing Rate — 3 NodeJS Process using Bulk</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*XWUGHLNBM5wrXa-iZwqRZg.png" /><figcaption>OpenSearch — CPU utilisation during Bulk insert</figcaption></figure><h3><strong>Data Ingestion — Future Improvement</strong></h3><p>I theoretically could have hit a higher number of inserts if i had performed this data import process on an instance as close as possible to the OpenSearch cluster — namely on an EC2 instance within the same VPC, to remove the overheads of opening and closing a network connection — including v4 signing of each request. However, with the import time sitting at just under 2 hours, this was an acceptable time period to generate 10 M worth of documents to test my queries.</p><h3><strong>Up Next: OpenSearch Queries, Visualisations and Monitoring</strong></h3><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-3-of-4-69f5dbf3ddfd">Please navigate to Part 3 for OpenSearch queries, visualisations and monitoring.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6e92cce402f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling 10M offline matchmaking using Amazon OpenSearch (Part 1 of 4)]]></title>
            <link>https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-1-of-4-3fc720e1c598?source=rss-844770727efb------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fc720e1c598</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[offline]]></category>
            <category><![CDATA[opensearch]]></category>
            <category><![CDATA[matchmaking-service]]></category>
            <dc:creator><![CDATA[Steven Tseng]]></dc:creator>
            <pubDate>Wed, 12 Oct 2022 00:59:23 GMT</pubDate>
            <atom:updated>2022-10-27T04:42:48.459Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f72k88diQavR_p_p3jFK0g.png" /></figure><p><em>As each game’s design is unique, with different mechanics and matchmaking requirements, I’ve written this blog with the intention of sharing my knowledge. The contents of this blog are my opinions only.</em></p><p>In multiplayer games, matchmaking is a process which connects players together to join an online session. Game Matchmaking itself can be simple, or very complicated depending on your rules and restrictions. Gameplay design and mechanics usually dictate how complicated the matchmaking process is. For example, a game targeting a younger audience will have simpler matchmaking requirements compared to a skill-based ranked-session based game. Game Matchmaking additionally has huge social impact on players enjoyment — which could both impact your business revenue and more importantly the perception of your company, especially if matchmaking is performed or designed poorly. In this blog, I will showcase how I designed a matchmaking service, deep dive into some core concepts, build queries and data visualisation using my service of choice — Amazon OpenSearch.</p><p><em>There are concerns with atomicity of documents, especially with how OpenSearch handles ACID transactions, which i will tackle in </em><strong><em>Part 4: Atomicity.</em></strong></p><h3>Contents</h3><ul><li>Part 1: Defining the problem &amp; Available Service Solutions</li><li><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-2-of-4-a6e92cce402f">Part 2: Data Ingestion, Server Planning &amp; Preparation</a></li><li><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-3-of-4-69f5dbf3ddfd">Part 3: Deep Diving into OpenSearch Queries</a></li><li><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-4-of-4-b28a43ad943a">Part 4: CloudWatch Monitoring, Additional Tips, Atomicity &amp; Cost</a></li></ul><h3><strong>The Problem at hand</strong></h3><p>Let’s start with the problem statement — Matchmaking complexity can be a sliding scale between easy and complex and highly dependent on your game dynamics. Some initial considerations when thinking about your games matchmaking are:</p><ul><li>Is matchmaking being designed for an online session based game?</li><li>Do you need to support Offline player matchmaking?</li><li>Is matchmaking designed for a highly competitive game mode?</li><li>How do we support multiple players with different skill based ratings?</li></ul><p>Matchmaking for online session games have requirements that are different compared to offline matchmaking service, such as the sheer player size that you could match against, as players do not have both be available, and accept the lobby invite at the same time. Latency requirements are more relaxed, but for the purpose of this blog, i’ll be focusing on Offline-based Matchmaking.</p><p>If you are designing for Offline matchmaking, you will have to deal with a problem of scale early on. If you have a large number of players in your database, and you do not have a stringent set of matchmaking rules, your matchmaking service could be paying expensive overheads in querying data, as you’re returning too many results and could be normalising or designing your access patterns to be more efficient.</p><p>I’ll explore handling matchmaking for highly competitive game modes, as well as theories around handling different skill based ratings matchmaking in a future blog post.</p><h3><strong>What service(s) should i use?</strong></h3><p>We have a number of potential solutions we could use when designing a matchmaking service. You could use or build:</p><ul><li>A matchmaking ruleset with your Relational-Database</li><li>A Redis-backed solution</li><li>A GraphDB solution similar to a shopping recommendation engine</li><li>A simple rule-based algorithm within the application itself</li><li>Amazon GameLift FlexMatch — A very customisable rule based matchmaking service</li></ul><p>However, I chose <strong>Amazon OpenSearch</strong> because of a number of benefits:</p><ul><li>OpenSearch is able to scale both horizontally and vertically to support your matchmaking workload, with Multi-Availability Zone support to minimise service interruptions.</li><li>OpenSearch is fast enough to handle the majority of use-cases with acceptable performance. For extremely critical, large-scale, latency sensitive applications, you may need to use a Redis solution.</li><li>OpenSearch can support up to 3 PetaBytes of storage</li><li>Most importantly, OpenSearch Dashboards is included to help visualise your data. If you use Redis, you would need to use a solution such as <a href="https://redis.com/redis-enterprise/redis-insight/">Redis Insights</a>.</li></ul><p>I chose not to use GameLift FlexMatch in this situation due to FlexMatch unfortunately not being suited for offline based matchmaking.</p><p>With matchmaking and player data, the visual component becomes very important so you can visualise your player base metrics and attributes. Your team can then use these visuals to analyse, troubleshooting, tweak your matchmaking algorithms, or even design future content for the large majority of players.</p><p>Now that we have explored the different matchmaking types, and have chosen our service, we will dive into the data import process.</p><h3><strong>Up Next: Data Ingestion, Server Planning and Preparation</strong></h3><p><a href="https://medium.com/@stetseng/handling-10m-offline-matchmaking-using-amazon-opensearch-part-2-of-4-a6e92cce402f">Please navigate to Part 2 for data ingestion, server capacity planning, volume size, and dedicated master nodes.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fc720e1c598" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How user generated content (UGC) can help improve player retention]]></title>
            <link>https://medium.com/@stetseng/how-user-generated-content-ugc-can-help-improve-player-retention-8ca68687be98?source=rss-844770727efb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ca68687be98</guid>
            <category><![CDATA[game-modding]]></category>
            <category><![CDATA[player-retention]]></category>
            <category><![CDATA[ugc]]></category>
            <dc:creator><![CDATA[Steven Tseng]]></dc:creator>
            <pubDate>Mon, 19 Sep 2022 01:12:07 GMT</pubDate>
            <atom:updated>2022-09-19T01:39:28.981Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y58pBs7FMGu3t8RQRko17Q.png" /></figure><p><em>I’ve written this blog with the intention of sharing my knowledge. The contents of this blog are my opinions only.</em></p><p>One of the most challenging problems in today’s games market is maintaining and growing your game’s player base. As more and more high quality games are being produced and released into the market, this ever-growing challenge of talent forces each Game Studio to strengthen their player retention strategies.</p><p>Typically, a game generates higher revenue if players are playing the game several times a week, or multiple times a day. With the industry average of Day 1 player retention being only 25% (for comparison really successful games achieving about 35%), the Day 7 industry average sharply drops to only 11%. With this drop in retention, it’s very important to identify what game features resonates with your target audience, to keep players engaged with your game.</p><p>User Generated Content (or UGC) is one strategy you can use to help retain, attract and build a strong social community for your game.</p><p><strong>What is User Generated Content?</strong></p><p>User Generated Content (or UGC) is a term used to describe any content that was created by the player base. UGC has existed in games for decades, most recognised in the form of <strong>‘modding’</strong> , the term used to describe In-game modifications created by players to change or manipulate existing game behaviour. UGC historically has not been welcomed due to how these modifications were distributed through third-party forums or has been seen as unauthorised changes made to the game by the studios / publishers themselves.</p><p>UGC however, has been responsible for spawning some of the largest titles created in gaming history, such as DOTA / League of Legends, Counter-Strike series, Tower Defense genre, Auto Chess, Garry’s Mod, and more. Modding in Games has even birthed and popularised the new Battle Royale genre through DayZ, creating further titles such as Fortnite, PUBG, including other successful titles across multiple platforms.</p><p><strong>Embarking on the journey to support User Generated Content</strong></p><p>You might have been considering including UGC in your game, but may have found the commitment to managing a content’s lifecycle to be daunting. However, with careful planning and consideration, we can make this process simple and easier to tackle. Lets start with some questions to ensure that UGC is the right fit for your use-case:</p><ol><li><strong>Understand your games player base</strong></li></ol><p>After your game has been released to the market and a number of players have started to play your game on a consistent basis, you may notice behaviours which can lead towards investigating adding UGC as a feature.</p><p>You may notice members in the community discussing, designing or even building content themselves, and posting about this on game forums, Discord or Twitter. Your community managers / volunteers may hear about this feature request after surveying the player base — especially if a consistent concern is about the amount of content available, and replayability / longevity of a game.</p><p>All of these characteristics are strong signals which indicate UGC may be a potent solution to help players contribute back to your games ecosystem.</p><p><strong>2. Is UGC the right fit for your game &amp; company?</strong></p><p>Depending on the game mechanics, UGC may or may not be the best fit. For high tier competitive play, such as tournament games, UGC may give players an unfair advantage, and so a stringent set of rules may need to be applied on whether competitive gameplay is only supported on vanilla or unmodded versions.</p><p>If your game includes features which pairs nicely to UGC — such as Valheim, Minecraft, Roblox or Cities Simulator style game mechanics, UGC might be the perfect fit for users to build and contribute ideas. What you want to consider is the legal implications if users submit trademarked content, such as highly protected images, content or logos of other businesses - and have strong, transparent guardrails around this.</p><p>If your game is in a position where UGC appears to be the right fit, and you need assistance to start the journey to support user-generated content, Mod.io may be the right solution.</p><h3><strong>Introducing Mod.io</strong></h3><p>In 2002 the <a href="https://mod.io/">Mod.io</a> team launched ModDB.com, and over the next 20 years, have refined and built a platform dedicated to supporting Mods. Mod.io believes that UGC makes every game better, and helps game studios simplify the process to develop their own player content driven economy, to take advantage of UGC faster. With cross-platform support, Mod.io is designed for studios who want to enable their community’s creativity across PCs, consoles, and mobile.</p><p>Mod.io helps bring legitimacy to the modding space, allowing players to avoid navigating hidden and sometimes untrusted sources to obtain mod content. The Mod.io platform helps players find, access and install mods in an easy to use single interface, rather than having to navigate into complicated system folders and manually manipulate individual files. Gone are the days of having to manually keep each mod updated — especially for games that may support hundreds of mods.</p><p>Most importantly, the tenured team at Mod.io helps bring years of experience, along with a structured process to help you setup your UGC platform, managing and simplifying a large amount of the heavy lifting required. Since Mod.io’s launch in 2019, Mod.io has been used by over 100+ games, with over 400,000+ users accessing the platform daily. Together they have created over 600,000 pieces of content, with over 100 million mods installed total.</p><h3><strong>Success Stories</strong></h3><p><strong>Saber Interactive</strong>, the team behind SnowRunner, is capable of delivering 200 new vehicles on a regular basis. After implementing UGC, and within the same time period, the community helped craft 1500+ additional vehicles, with most vehicles being virtually indistinguishable in terms of quality.</p><blockquote><strong>Tim Willits, Chief Creative Officer of Saber Interactive<br></strong>“SnowRunner’s modding community has greatly expanded the game’s experience for dedicated players. The constant influx of fresh content is certainly a key driver of the title’s long-term success. We could not have achieved this without Mod.io — their tech and support are unmatched.”</blockquote><p><strong>Easy Day Studios</strong>, the team behind <strong>Skater XL</strong>, demonstrated incredible growth through UGC, <a href="https://blog.mod.io/skater-xl-setting-records-with-ugc-on-consoles-c96779382870">hitting 1 M downloads within 24 hours</a>, over 250 new pieces of content on PS4 and Xbox One. Over 90% of the downloads were on console, showing a clear demand of Modding content with the console community, potentially exceeding the modding demand commonly associated with PC gaming.</p><blockquote><strong><em>Dain Hedgepeth, Director of Easy Day Studios, creators of Skater XL<br></em></strong><em>“If studios aren’t thinking of games as a place for players to hang out, create and express themselves they’re missing the direction the whole industry is moving in. Since launching our M</em><a href="http://mod.io/"><em>od.io</em></a><em> site 4 months ago we’ve had over 3 million mod downloads, this is a huge part of what drives the life and vibrancy of the Skater XL world.”</em></blockquote><p>To conclude, if you have noticed your game community actively talking about wanting more content, or are showing strong signals such as developing their own tools and content for your game, then it is a strong indication that supporting a UGC platform will allow players to contribute to the content ecosystem. Instead of embarking on building your own solution, you should definitely consider working with the tenured team at <a href="https://mod.io/">Mod.io</a>, and reap the benefits of UGC.</p><p><em>All contents of this blog are written with my own opinion, please reach out if you want to discuss anything Game or GameTech related!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ca68687be98" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>