# Matchmaker ticket flow

> Understand how tickets move from creation through matching to server allocation.

When using Matchmaker with a game server hosting provider, you must use [Cloud Code modules](/cloud-code/modules/overview.md) to allocate servers and coordinate matchmaking results. The following Matchmaker flow diagram takes you through the creation of a matchmaking ticket to the allocation of a server for the created match, and the ticket assignment.


**Flow of a ticket from creation to allocation.:**
```mermaid
sequenceDiagram
  participant Player
  participant Game_Client as Game Client
  participant Matchmaker
  participant Cloud_Code as Cloud Code
  participant Hosting_Provider as Hosting Provider

  Player->>Game_Client: Player launches game
  Game_Client->>Game_Client: Game client authenticates player via UGS Authentication

  Player->>Game_Client: Player selects their game parameters
  Game_Client->>Matchmaker: Game client creates a ticket for matchmaking

  Matchmaker->>Matchmaker: Ticket matched with other players' tickets
  Matchmaker->>Cloud_Code: Matchmaker calls Cloud Code allocation function

  Cloud_Code->>Hosting_Provider: Cloud Code allocation function makes an<br>allocation request to hosting provider
  Hosting_Provider->>Cloud_Code: Allocation data returned to Cloud Code allocation function
  Cloud_Code->>Matchmaker: Allocation data returned to Matchmaker

  Hosting_Provider->>Hosting_Provider: Hosting provider allocates a dedicated game server
  Matchmaker->>Cloud_Code: Matchmaker repeatedly calls Cloud Code<br>polling function with allocation data
  Cloud_Code->>Hosting_Provider: Cloud Code polling function makes an<br>allocation status request to hosting provider
  Hosting_Provider->>Cloud_Code: When available, connection details (for example, IP and port)<br>returned to Cloud Code polling function
  Cloud_Code->>Matchmaker: Connection details returned to Matchmaker
  Matchmaker->>Matchmaker: Connection details are assigned to all tickets in the match

  Matchmaker->>Game_Client: Game client polls for ticket status until connection<br>details are available, then connects to the server
```

1. When a player launches the game, the game client authenticates using the Unity Authentication Service.
2. Once the player has selected their game parameters (such as game mode), the game client creates and sends a ticket to the Matchmaker service.
3. Matchmaker matches the ticket with other players' tickets and requests a game server allocation from your preferred game server hosting service to host the match by calling the Cloud Code allocation function configured for that pool. If supported, the allocation can be passed information about the match made via [matchmaking results](https://services.docs.unity.com/matchmaker/v2/index.html#tag/matchmaking_results_model).
4. In the request to the Cloud Code polling function, Matchmaker passes the data returned by the allocation function to gather information about the allocation. The polling function can return one of three states: `allocated`, `pending`, and `error`. If the polling function returns `pending`, Matchmaker repeatedly calls the polling function until it returns `allocated` or `error`. If `error` is returned, then Matchmaker assigns an error to all the tickets in that match.
5. After the polling function returns `allocated`, the server starts. The server retrieves the [matchmaking results](https://services.docs.unity.com/matchmaker/v2/index.html#tag/matchmaking_results_model) from either a provider-specific endpoint, if supported, or the Matchmaker's [matchmaking results endpoint](https://services.docs.unity.com/matchmaker/v2/index.html#tag/Matches) to get the information on who the players are and their distribution across the different teams.
6. Once the server is allocated, Matchmaker updates the tickets in the match with the connection information.
7. The game client polls the Matchmaker service every second to get the ticket status. Once the server connection information is added to the ticket, the game client retrieves it, connects to the server, and joins the match.
