---
updatedAt: 2025-11-11T19:47:05.000Z
agentTools:
  projectIndex: https://beamable2.readme.io/llms.txt
---

# Microservices - Guide

Create and deploy server-authoritative C# [CLCP-Microservices-02]

<ul class="breadcrumb">
  <li><a href="/docs/">Docs</a></li>
  <li><a href="/docs/cloud-compute">Cloud Compute</a></li>
  <li><a href="/docs/microservices-feature-overview">Microservices</a></li>
  <li>Microservices - Guide</li>
</ul>

<div class="links">
  <a class="link normal" href="/docs/microservices-feature-overview" style={{textDecoration: 'none'}}>Overview</a>
  <a class="link active" href="/docs/microservices-guide" style={{textDecoration: 'none'}}>Guide</a>
  <a class="link normal" href="/docs/microservices-code" style={{textDecoration: 'none'}}>Code</a>
    <a class="link normal" href="/docs/microservices-custom-content" style={{textDecoration: 'none'}}>Content</a>
    <a class="link normal" href="/docs/microservices-dlls" style={{textDecoration: 'none'}}>DLLs</a>
    <a class="link normal" href="/docs/microservices-debugging" style={{textDecoration: 'none'}}>Debugging</a>
    <a class="link normal" href="/docs/microservices-distributing" style={{textDecoration: 'none'}}>Distributing</a>
    <a class="link normal" href="/docs/microservices-tool-window" style={{textDecoration: 'none'}}>Tool Window</a>
  <a class="link normal" href="/docs/microservices-class-sharing" style={{textDecoration: 'none'}}>Class Sharing</a>
</div>

The purpose of this guide is for game makers to create and deploy **server-authoritative C# functionality** within their games with Beamable [Microservices](https://beamable2.readme.io/docs/microservices-feature-overview).

This guide includes everything needed to use the **Microservices** feature in the "Beamable SDK for Unity". Or watch this video.

<HTMLBlock>{`
<div class="videoEmbed">
  <iframe 
  	src="https://www.youtube.com/embed/3e99GMu2BjY"
    allowfullscreen
  >
  </iframe>
</div>
<style>
  .videoEmbed 
  {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
  }
  
 .videoEmbed iframe
  {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
</style>
`}</HTMLBlock>

> 📘 Related Feature
>
> • More details are covered in related feature page(s). See [Microservices](https://beamable2.readme.io/docs/microservices-feature-overview) for more info.

## Game Maker User Experience

There are 3 major parts to <Glossary>Microservice</Glossary> setup process. During development, the game maker's user experience is as follows:

<HTMLBlock>{`
<div class="lucidChart1">
  <iframe class="lucidChart1" 
   src="https://app.lucidchart.com/documents/embeddedchart/41e8ef32-4517-470d-be78-716617106399" id="WZbw6J85P_4M">
  </iframe>
</div>


<style>
  .lucidChart1 { 
    
    /* DO NOT EDIT */
    pointer-events: none; 
    user-select: none; 
    position: relative; 
    background-color:rgba(0, 0, 0, 0);
    width: 100%; 
    border:none;
    
    /* EDIT AS DESIRED */
    min-height: 285px; 
  }
</style>
`}</HTMLBlock>

## Example

In this **AddMyValues()** example a new c# server-side <Glossary>Microservice</Glossary> is created and exposes a method to be called by any c# client-side scope.

The source-code for **both** server-side and client-side sits local in your Unity project for efficiency and ease-of-use.

**Creating a Microservice**

```csharp
namespace Beamable.Examples.Features.Microservices
{
   [Microservice("MyMathMicroservice")]
   public class MyMathMicroservice : Microservice
   {
      [ClientCallable]
      public int AddMyValues(int a, int b)
      {
         return a + b; 
      }
   }
}
```

**Calling a Microservice**

```csharp
namespace Beamable.Examples.Features.Microservices
{
    public class MyMathMicroserviceExample : MonoBehaviour
    {
        private MyMathMicroserviceClient  _myMathMicroserviceClient;

        protected async void Start()
        {
            var beamContext = BeamContext.Default;
            await beamContext.OnReady;

            Debug.Log($"beamContext.PlayerId = {beamContext.PlayerId}");
            
            _myMathMicroserviceClient = new MyMathMicroserviceClient();
            
            int myValues = await _myMathMicroserviceClient.AddMyValues(10, 5);
                
            Debug.Log ($"AddMyValues() Result = {myValues}");
        }
    }
}
```

The following steps will demonstrate how to setup that example code in a real-world project.

## Getting Started With Beamable Microservices

Follow these steps to get started:

Beamable Microservices uses the industry standard Docker technology. Beamable handles all coordination and configuration.

See [Microservices (Beamable & Docker)](https://beamable2.readme.io/docs/microservices-code#beamable--docker) for more info.

**Beamable's Docker Setup**

* Hosts the client Microservices environment and hides complexity of .Net core
* Hosts the server Microservices environment

**Order of Execution**

1. Game maker changes C# code
2. Unity recompiles
3. Beamable synchronizes Client <-> Server, only if needed

<HTMLBlock>{`
<div class="lucidChart1">
  <iframe class="lucidChart1" 
   src="https://app.lucidchart.com/documents/embeddedchart/40f85014-580b-421c-a14c-14b19beba992" id="~dMwFDussakP">
  </iframe>
</div>
`}</HTMLBlock>

**Step 1. Setup Docker**

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Detail
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        1. Download & Install Docker
           (Windows or Mac)
      </td>

      <td>
        • Visit <a href="https://www.docker.com/get-started" target="_blank">Docker.com</a>  

        *Note: You may skip the Docker official tutorial*
      </td>
    </tr>

    <tr>
      <td>
        2. Open Command Line
      </td>

      <td>
        •  **Window**: Press Windows+R to open the “Run” box. Type `cmd` and then click “OK”.\
        •  **Mac**: Open the Applications folder, then open Utilities and double-click on Terminal, or press Command+Spacebar to launch Spotlight and type `Terminal`
      </td>
    </tr>

    <tr>
      <td>
        3. Run Docker Command Line
      </td>

      <td>
        • Type `docker ps`
      </td>
    </tr>

    <tr>
      <td>
        4. Verify that Docker is operational (With no Microservices running yet)
      </td>

      <td>
        <img src="https://files.readme.io/948ac1e-docker_ps.jpg" />
      </td>
    </tr>
  </tbody>
</Table>

**Step 2. Create Microservice**

By design, creating Microservice C# server-code is as straight-forward as creating any traditional C# client-code. Let's take a look at an example.

Here is a traditional C# method.

```csharp
public int AddMyValues(int a, int b)
{
  return a + b;
}
```

<HTMLBlock>{`
<div class="lucidChart1">
  <iframe class="lucidChart1" 
   src="https://app.lucidchart.com/documents/embeddedchart/a8a92e3e-85d5-4517-a109-bb5938de496b" id="zgPwXatDVqHD">
  </iframe>
</div>
`}</HTMLBlock>

And here is the equivalent C# Microservice method.

```csharp
[ClientCallable]
public int AddMyValues(int a, int b)
{
  return a + b;
}
```

<HTMLBlock>{`
<div class="lucidChart1">
  <iframe class="lucidChart1" 
   src="https://app.lucidchart.com/documents/embeddedchart/cf7fc687-6613-4e93-9807-59dc3905cc81" id="lpPwDk2ImD_p">
  </iframe>
</div>
`}</HTMLBlock>

> 🚧 Windows Users
>
> Remember that the maximum File Path/Name size in Windows is 255 characters. Due to that, we recommend you keep your projects in a folder close to the root (and avoid unnecessarily long Micro Service names) to avoid any issues.
>
> For some more context, as part of the Microservice building process we generate a file structure in your Unity's Temp folder. This can lead to a pretty deep file path hierarchy.

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Detail
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        1. Open the "Microservices Manager" Window
      </td>

      <td>
        • Unity → Window → Beamable → Open Microservices Manager
      </td>
    </tr>

    <tr>
      <td>
        2. Create a new Microservice
      </td>

      <td>
        • Unity → Window → Beamable → Create New Microservice  

        <img src="https://files.readme.io/6bd205c-Screen_Shot_2022-11-02_at_1.18.39_PM.png" width="400" />  
          
        • Populate all form fields
      </td>
    </tr>

    <tr>
      <td>
        3. Implement the Microservice method
      </td>

      <td>
        `[ClientCallable]`\
        `public int AddMyValues(int a, int b)`\
        `{`\
              `     return a + b;`\
        `}`
      </td>
    </tr>

    <tr>
      <td>
        5. Run the Microservice
      </td>

      <td>
        <img src="https://files.readme.io/40980ff-Screen_Shot_2022-11-02_at_1.21.25_PM.png" width="400" />  
          
        • See Beamable Microservice Manager Window
      </td>
    </tr>

    <tr>
      <td>
        6. Play the Scene
      </td>

      <td>
        • Unity → Edit → Play  

        *Note: Verify that the code properly functions. This varies depending on the specifics of the game logic*
      </td>
    </tr>

    <tr>
      <td>
        7. Stop the Scene
      </td>

      <td>
        • Unity → Edit → Stop
      </td>
    </tr>
  </tbody>
</Table>

With each newly created Microservice, there is auto-generated code. This serves as a working **template** for the game maker, who will write the actual implementation.

> 👍 Hot Reload
>
> In Beamable versions 1.1 and newer, microservices only need to be started once. This also applies to the microservice's generated documentation (Microservice ⋮ → Local → View Documentation). The hot-reload functionality can be disabled from the Microservice Configuration's "Enable Hot Module Reload" option.

### Example

> 📘 Beamable SDK Examples
>
> • The following example code is available for download at <a target="_blank" href="https://github.com/beamable/Beamable_Microservices_Examples">GitHub.com/Beamable\_Microservices\_Examples</a>

In this example, two values will be added together and returned.

```csharp MyMathMicroservice.cs
using Beamable.Server;

namespace Beamable.Examples.Features.Microservices.MyMathMicroserviceExample
{
   [Microservice("MyMathMicroservice")]
   public class MyMathMicroservice : Microservice
   {
      /// <summary>
      /// Add 2 integers and return the result.
      /// </summary>
      /// <param name="a">The first value to add</param>
      /// <param name="b">The second value to add</param>
      /// <returns>Returns the sum of the values</returns>
      [ClientCallable]
      public int AddMyValues(int a, int b)
      {
         return a + b; 
      }
   }
}
```

> 📘 Best Practices
>
> These hints make efficent use of concepts and workflows.
>
> • Enable Autorun of Microservices - Click the "Autorun" Button. This will start the service in Unity's PlayMode and stop the service in Unity's EditMode

**Step 3. Call Microservice**

By design, calling a Microservice C# server-code is as straight-forward as calling any traditional C# client-code. Choose a location in existing C# client-code, or create a new class. Then call the Microservice as shown here.

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Detail
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        1. Create a new MonoBehaviour class
      </td>

      <td>
        • Unity → Assets → Create → C# Script
      </td>
    </tr>

    <tr>
      <td>
        2. Call the Microservice
      </td>

      <td>
        The syntax will vary depending on the Microservice  

        *Note: Avoid passing parameters with type references to any`UnityEngine` and `UnityEditor` namespaces* 
      </td>
    </tr>
  </tbody>
</Table>

### Example

> 📘 Beamable SDK Examples
>
> • The following example code is available for download at <a target="_blank" href="https://github.com/beamable/Beamable_Microservices_Examples">GitHub.com/Beamable\_Microservices\_Examples</a>

In this example, the Microservice is created, called, and the result is logged out to the Unity Console Window.

```csharp MyMathMicroserviceExample.cs
using UnityEngine;
using Beamable.Server.Clients;

namespace Beamable.Examples.Features.Microservices.MyMathMicroserviceExample
{
    /// <summary>
    /// Demonstrates <see cref="Microservices"/>.
    /// </summary>
    public class MyMathMicroserviceExample : MonoBehaviour
    {
        //  Properties  -----------------------------------
        
        //  Fields  ---------------------------------------
        private MyMathMicroserviceClient  _myMathMicroserviceClient;
        
        //  Unity Methods  --------------------------------

        protected void Start()
        {
            Debug.Log("Start() Instructions...\n" + 
            "* Complete docker setup per https://docs.beamable.com/docs/microservices-feature\n" +
            "* Start the server per https://docs.beamable.com/docs/microservices-feature\n" +
            "* Play This Scene\n" + 
            "* Enjoy!\n\n\n");
            
            SetupBeamable();
        }
        
        //  Methods  --------------------------------------
        private async void SetupBeamable()
        {
            var beamContext = BeamContext.Default;
            await beamContext.OnReady;

            Debug.Log($"beamContext.PlayerId = {beamContext.PlayerId}");
            
            _myMathMicroserviceClient = new MyMathMicroserviceClient();
            
            // #1 - Call Microservice with (10, 5)
            int result = await _myMathMicroserviceClient.AddMyValues(10, 5);
            bool isSuccess = result == 15;
                
            // #2 - Result = 15
            Debug.Log ($"AddMyValues() Result = {result}, Success={isSuccess}");
        }
    }
}
```

## Advanced

This section contains any advanced configuration options and workflows.

### Designing Microservices

Optionally, the Microservice can take Beamable content as input and pass Beamable player state as output. This is a suggested workflow for many game designs.

See [Microservices (Designing)](https://beamable2.readme.io/docs/microservices-code#designing-microservices) for more info.

### Debugging Microservices

Development of Beamable Microservices within the Unity client is straight-forward and transparent. It is the ideal environment for development including debugging tools.

See [Microservices (Debugging)](https://beamable2.readme.io/docs/microservices-code#debugging-microservices) for more info.

### Deploying Microservices

During development, the Microservice is run locally within a developer-specific sandbox. When ready, the game maker can promote/deploy the Microservice to production.

See [Microservices (Deploying)](https://beamable2.readme.io/docs/microservices-code#deploying-microservices) for more info.

### Microservice Serialization

See [Microservices (Serialization)](https://beamable2.readme.io/docs/microservices-code#microservice-serialization) for more info.

## Discussion

Questions? Comments? Join the discussion in the Beamable <a href="https://docs.beamable.com/discuss" target="_blank" >Ask A Question </a>Forum!

> 🚧 Gotchas
>
> Here are hints to help explain some of the trickier concepts:
>
> * Unlike many Beamable features, Microservices does not require a specific Beamable <Glossary>Feature Prefab</Glossary> to be used.
> * Within the Microservice method implementation, avoid any references to `UnityEngine` and `UnityEditor` namespaces
> * For parameters passed to a Microservice method, avoid any references to `UnityEngine` and `UnityEditor` namespaces

<HTMLBlock>{`
<style>
  .links {
    padding: 0 1em 1em 0;
    display: flex;
    flex-flow: row wrap;
  }

  .link {
    margin-right: 2em;
    margin-bottom: 0.75em;
    padding: 0.3em 1.5em;
    box-sizing: border-box;
  }

  .active {
    border: 1px solid #4274f6;
    background-color: #4274f6;
    color: white;
  }

  .normal {
    background-color: white;
    border: 1px solid gray;
    cursor:pointer;
    text-decoration: none;
  }

  .normal:active {
    background-color: #c4d4ff;
  }

  .normal:hover {
    background-color: #c4d4ff;
  }

  .active:active {
    color: white;
  }

  .active:hover {
    color: white;
  }
  
  ul.breadcrumb {
    padding: 10px 16px;
    list-style: none;
  }
  ul.breadcrumb li {
    display: inline;
    font-size: 18px;
  }
  ul.breadcrumb li+li:before {
    padding: 8px;
    color: black;
    content: "/\\00a0";
  }
  ul.breadcrumb li a {
    color: #0275d8;
    text-decoration: none;
  }
  ul.breadcrumb li a:hover {
    color: #01447e;
    text-decoration: underline;
  }
  
        @media only screen and (max-width:700px){
 		    ul.breadcrumb {
    padding-top:0;
          padding-left:0;
  }
      
       .link {
    margin-right: 1em;
         margin-bottom:1em;
  }
  }
</style>
`}</HTMLBlock>