Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Microsoft - Extending Minecraft into the real world with Azure Cosmos DB

#1
Extending Minecraft into the real world with Azure Cosmos DB

<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2020/05/extending-minecraft-into-the-real-world-with-azure-cosmos-db.png" width="634" height="534" title="" alt="" /></div><div><p><i>This post is part 1 of a two-part series about how organizations use Azure Cosmos DB to meet real world needs and the difference it’s making to them. In part 1, we explore the challenges that led service developers for Minecraft Earth to choose Azure Cosmos DB and how they’re using it to capture almost every action taken by every player around the globe—with ultra-low latency. In <a href="https://azure.microsoft.com/blog/minecraft-earth-and-azure-cosmos-db-part-2-delivering-turnkey-geographic-distribution" target="_blank" rel="noopener noreferrer">part 2</a>, we examine the solution’s workload and how Minecraft Earth service developers have benefited from building it on Azure Cosmos DB.</i></p>
<h2>Extending the world of Minecraft into our real world</h2>
<p>You’ve probably heard of the game Minecraft, even if you haven’t played it yourself. It’s the best-selling video game of all time, having sold more than 176 million copies since 2011. Today, Minecraft has more than 112 million monthly players, who can discover and collect raw materials, craft tools, and build structures or earthworks in the game’s <a href="https://www.engadget.com/2015/03/04/how-minecraft-worlds-are-made/" target="_blank" rel="noopener noreferrer">immersive, procedurally generated 3D world.</a> Depending on game mode, players can also fight computer-controlled foes and cooperate with—or compete against—other players.</p>
<p>In May 2019, Microsoft announced the upcoming release of Minecraft Earth, which began its worldwide rollout in December 2019. Unlike preceding games in the Minecraft franchise, Minecraft Earth takes things to an entirely new level by enabling players to experience the world of Minecraft within our real world through the power of augmented reality (AR).</p>
<p>For Minecraft Earth players, the experience is immediately familiar—albeit deeply integrated with the world around them. For developers on the Minecraft team at Microsoft, however, the delivery of Minecraft Earth—especially the authoritative backend services required to support the game—would require building something entirely new.</p>
<p>Nathan Sosnovske, a Senior Software Engineer on the Minecraft Earth services development team explains:</p>
<p><em>“With vanilla Minecraft, while you could host your own server, there was no centralized service authority. Minecraft Earth is based on a centralized, authoritative service—the first ‘heavy’ service we’ve ever had to build for the Minecraft franchise.”</em></p>
<p>In this case study, we’ll look at some of the challenges that Minecraft Earth service developers faced in delivering what was required of them—and how they used Azure Cosmos DB to meet those needs.</p>
<h2>The technical challenge: Avoiding in-game lag</h2>
<p>Within the Minecraft Earth client, which runs on iOS-based and Android-based AR-capable devices, almost every action a player takes results in a write to the core Minecraft Earth service. Each write is a REST POST that must be immediately accepted and acknowledged to avoid any noticeable in-game lag.</p>
<p><em>“From a services perspective, Minecraft Earth requires low-latency writes and medium-latency reads,” explains Sosnovske. “Writes need to be fast because the client requires confirmation on each one, such as might be needed for the client to render—for example, when a player taps on a resource to see what’s in it, we don’t want the visuals to hang while the corresponding REST request is processed. Medium-latency reads are acceptable because we can use client-side simulation until the backing model behind the service can be updated for reading.”</em></p>
<p>To complicate the challenge, Minecraft Earth service developers needed to ensure low-latency writes regardless of a player’s location. This required running copies of the service in multiple locations within each geography where Minecraft Earth would be offered, along with built-in intelligence to route the Minecraft Earth client to the nearest location where the service is deployed.</p>
<p><em>“Typical network latency between the east and west coasts of the US is 70 to 80 milliseconds,” says Sosnovske. “If a player in New York had to rely on a service running in San Francisco, or vice versa, the in-game lag would be unacceptable. At the same time, the game is called Minecraft Earth—meaning we need to enable players in San Francisco and New York to share the same in-game experience. To deliver all this, we need to replicate the service—and its data—in multiple, geographically distributed datacenters within each geography.”</em></p>
<h2>The solution: An event sourcing pattern based on Azure Cosmos DB</h2>
<p>To satisfy their technical requirements, Minecraft Earth service developers implemented an <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/event-sourcing" target="_blank" rel="noopener noreferrer">event sourcing pattern</a> based on <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/introduction" target="_blank" rel="noopener noreferrer">Azure Cosmos DB</a>.</p>
<p><em>“We originally considered using Azure Table storage to store our append-only event log, but its lack of any SLAs for read and write latencies made that unfeasible,” says Sosnovske. “Ultimately, we chose Azure Cosmos DB because it provides 10 millisecond SLAs for both reads and writes, along with the global distribution and multi-master capabilities needed to replicate the service in multiple locations within each geography.” </em></p>
<p>With an event sourcing pattern, instead of just storing the current state of the data, the Minecraft Earth service uses an append-only data store that’s based on Azure Cosmos DB to record the full series of actions taken on the data—in this case, mapping to each in-game action taken by the player. After immediate acknowledgement of a successful write is returned to the client, queues that subscribe to the append-only event store handle postprocessing and asynchronously apply the collected events to a domain state maintained in <a href="https://azure.microsoft.com/en-us/services/storage/blobs" target="_blank" rel="noopener noreferrer">Azure Blob storage</a>. To optimize things further, Minecraft Earth developers combined the event sourcing pattern with domain-driven design, in which each app domain—such as inventory items, character profiles, or achievements—has its own event stream.</p>
<p><em>“We modeled our data as streams of events that are stored in an append-only log and mutate an in-memory model state, which is used to drive various client views,” says Sosnovske. “That cached state is maintained in Azure Blob storage, which is fast enough for reads and helps to keep our request unit costs for Azure Cosmos DB to a minimum. In many ways, what we’ve done with Azure Cosmos DB is like building a write cache that’s really, really resilient.”</em></p>
<p>The following diagram shows how the event sourcing pattern based on Azure Cosmos DB works:</p>
<p><a href="https://azurecomcdn.azureedge.net/mediahandler/acomblog/media/Default/blog/26f4e883-2dd4-43eb-843b-46c0cc30b1f4.png"><img alt="Event sourcing pattern based on Azure Cosmos DB workflow diagram." border="0" height="534" src="https://www.sickgaming.net/blog/wp-content/uploads/2020/05/extending-minecraft-into-the-real-world-with-azure-cosmos-db.png" title="Event sourcing pattern based on Azure Cosmos DB workflow diagram." width="634"></a></p>
<h2>Putting Azure Cosmos DB in place</h2>
<p>In putting Azure Cosmos DB to use, developers had to make a few design decisions:</p>
<p><b>Azure Cosmos DB API.</b> Developers chose to use the Azure Cosmos DB Core (SQL) API because it offered the best performance and the greatest ease of use, along with other needed capabilities.</p>
<p><em>“We were building a system from scratch, so there was no need for a compatibility layer to help us migrate existing code,” Sosnovske explains. “In addition, some Azure Cosmos DB features that we depend on—such as <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.transactionalbatch?view=azure-dotnet" target="_blank" rel="noopener noreferrer">TransactionalBatch</a>—are only supported with the Core (SQL) API. As an added advantage, the Core (SQL) API was really intuitive, as our team was already familiar with SQL in general.”</em></p>
<p>Read <a href="https://devblogs.microsoft.com/cosmosdb/introducing-transactionalbatch-in-the-net-sdk/" target="_blank" rel="noopener noreferrer">Introducing TransactionalBatch in the .NET SDK</a> to learn more.</p>
<p><b>Partition key.</b> Developers ultimately decided to logically partition the data within Azure Cosmos DB based on users.</p>
<p><em>“We originally partitioned data on users and domains—again, examples being inventory items or achievements—but found that this breakdown was too granular and prevented us from using database transactions within Azure Cosmos DB to their full potential,” says Sosnovske.”</em></p>
<p><b>Consistency level.</b> Of the <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/consistency-levels" target="_blank" rel="noopener noreferrer">five consistency levels supported by Azure Cosmos DB</a>, developers chose session consistency, which they combined with heavy <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/database-transactions-optimistic-concurrency" target="_blank" rel="noopener noreferrer">etag checking</a> to ensure that data is properly written.</p>
<p><em>“This works for us because of how we store data, which is modeled as an append-only log with a head document that serves as a pointer to the tail of the log,” explains Sosnovske. “Writing to the database involves reading the head document and its etag, deriving the N+1 log ID, and then constructing a transactional batch operation that overwrites the head pointer using the previously read etag and creates a new document for the log entry. In the unlikely case that the log has already been written, the etag check and the attempt to create a document that already existed will result in a failed transaction. This happened regardless of whether another request ‘beats’ us to writing or if our request reads slightly out-of-date data.”</em></p>
<p>In <a href="https://azure.microsoft.com/blog/minecraft-earth-and-azure-cosmos-db-part-2-delivering-turnkey-geographic-distribution" target="_blank" rel="noopener noreferrer">part 2</a><strong> </strong>of this series, we examine the solution’s current workload and how Minecraft Earth service developers have benefited from building it on Azure Cosmos DB.</p>
<h2>Get started with Azure Cosmos DB</h2>
</div>


https://www.sickgaming.net/blog/2020/05/...cosmos-db/
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016