

# What is Amazon GameLift Servers FlexMatch?
<a name="match-intro"></a>

Amazon GameLift Servers FlexMatch is a customizable matchmaking service for multiplayer games. With FlexMatch, you can build a custom set of rules that define what a multiplayer match looks like for your game, and determines how to evaluate and select compatible players for each match. You can also fine-tune key aspects of the matchmaking algorithm to fit your game needs.

Use FlexMatch as a standalone matchmaking service or integrated with an Amazon GameLift Servers game hosting solution. For example, you might implement FlexMatch as a standalone feature with games with a peer-to-peer architecture or games that use other cloud compute solutions. Or you might add FlexMatch to your Amazon GameLift Servers managed EC2 or managed containers hosting, or on-premises hosting with Amazon GameLift Servers Anywhere. This guide provides detailed information on how to build a FlexMatch matchmaking system for your particular scenario.

FlexMatch gives you the flexibility to set matchmaking priorities depending on your game requirements. For example, you can do the following:
+ Find a balance between match speed and quality. Set match rules to quickly find matches that are good enough, or have players wait a little longer to find the best possible match for an optimum player experience.
+ Make matches based on well-matched players or well-matched teams. Create matches where all players have similar characteristics such as skill or experience. Or form matches where the combined characteristics of each team meet a common criteria.
+ Prioritize how player latency factors into matchmaking. Do you want to set a hard limit on latency for all players, or are higher latencies acceptable as long as everyone in the match has similary latency?

**Ready to start working with FlexMatch?**  
For step-by-step guidance on getting your game up and running with FlexMatch, see the following topics:  
[Roadmap: Add matchmaking to a Amazon GameLift Servers hosting solution](match-tasks.md)
[Roadmap: Create a standalone matchmaking solution with FlexMatch](match-tasks-safm.md)

## Key FlexMatch features
<a name="match-intro-features"></a>

The following features are available with all FlexMatch scenarios, whether you use FlexMatch as a standalone service or with Amazon GameLift Servers game hosting.
+ **Customizable player matching.** Design and build matchmakers to suit all of the game modes that you offer your players. Build a set of custom rules to evaluate key player attributes (such as skill level or role) and geographic latency data to form great player matches for your game.
+ **Latency-based matching.** Provide player latency data and create match rules that require players in a match to have similar response times. This feature is useful when your player matchmaking pools span multiple geographic regions.
+ **Support for match sizes up to 200 players.** Create matches of up to 40 players using match rules that are customized for your game. Create matches of up to 200 players using a matching process that uses a streamlined custom matching process to keep player wait times manageable.
+ **Player acceptance.** Require players to opt in to a proposed match before finalizing the match and starting a game session. Use this feature to initiate your custom acceptance workflow and report player responses to FlexMatch before placing a new game session for the match. If not all players accept a match, the proposed match fails and players who did accept automatically return to the matchmaking pool.
+ **Player parties support.** Generate matches for groups of players who want to play together on the same team. Use FlexMatch to find additional players to fill out the match as needed.
+ **Expandable matching rules.** Gradually relax the match requirements after a certain amount of time has passed without finding a successful match. Rule expansion lets you decide where and when to relax the initial match rules, so that players can get into playable games more quickly.
+ **Match backfill.** Fill the empty player slots in an existing game session with well-matched new players. Customize when and how to request new players, and use the same custom match rules to find additional players.

## FlexMatch with Amazon GameLift Servers hosting
<a name="match-intro-hosting"></a>

FlexMatch offers the following additional features for use with games that you're hosting with Amazon GameLift Servers. This includes games with custom game servers or Amazon GameLift Servers Realtime. 
+ **Game session placement.** When a match is successfully made, FlexMatch automatically requests a new game session placement from Amazon GameLift Servers. The data generated during matchmaking, including player IDs and team assignments, is provided to the game server so that it can use that information to start the game session for the match. FlexMatch then passes back game session connection information so that game clients can join the game. To minimize the latency experienced by players in a match, game session placement with Amazon GameLift Servers can also use regional player latency data, if provided.
+ **Automatic match backfill.** With this feature enabled, FlexMatch automatically sends a match backfill request when a new game session starts with unfilled player slots. Your matchmaking system starts the game session placement process with a minimum number of players, and then quickly fills the remaining slots. You cannot use automatic backfill to replace players who drop out of a matched game session. 

If you use Amazon GameLift Servers FleetIQ with games that are hosted with Amazon Elastic Compute Cloud (Amazon EC2) resources, implement FlexMatch as a standalone service.

## Pricing for Amazon GameLift Servers FlexMatch
<a name="match-intro-pricing"></a>

Amazon GameLift Servers charges for instances by duration of use and for bandwidth by quantity of data transferred. If you host your games on Amazon GameLift Servers, FlexMatch usage is included in the fees for Amazon GameLift Servers. If you host your games on another server solution, FlexMatch usage is charged separately. For a complete list of charges and prices for Amazon GameLift Servers, see [Amazon GameLift Servers Pricing](https://aws.amazon.com/gamelift/servers/pricing).

For information on calculating the cost of hosting your games or matchmaking with Amazon GameLift Servers, see [Generating Amazon GameLift Servers pricing estimates](https://docs.aws.amazon.com/gameliftservers/latest/developerguide/gamelift-calculator.html), which describes how to use the [AWS Pricing Calculator](https://calculator.aws/#/createCalculator/GameLift).

# How Amazon GameLift Servers FlexMatch works
<a name="gamelift-match"></a>

This topic provides an overview of the Amazon GameLift Servers FlexMatch service, including the core components of a FlexMatch system and how they interact.

You can use FlexMatch with games that use Amazon GameLift Servers managed hosting or with games that use another hosting solution. Games that are hosted on Amazon GameLift Servers, including Amazon GameLift Servers Realtime, use the integrated Amazon GameLift Servers service to automatically locate available game servers and start game sessions for the matches. Games that use FlexMatch as a standalone service, including Amazon GameLift Servers FleetIQ, must coordinate with the existing hosting system to assign hosting resources and start game sessions for the matches.

For detailed guidance on setting up FlexMatch for your games, see [Getting started with FlexMatch](match-getting-started.md).

## Matchmaking components
<a name="gamelift-match-components"></a>

A FlexMatch matchmaking system includes some or all of the following components.

**Amazon GameLift Servers components**

These are Amazon GameLift Servers resources that control how the FlexMatch service performs matchmaking for your game. They are created and maintained using Amazon GameLift Servers tools, including the console and the AWS CLI or, alternatively, programmatically using the AWS SDK for Amazon GameLift Servers.
+ **FlexMatch matchmaking configuration (also called a matchmaker)** – A matchmaker is a set of configuration values that customizes the matchmaking process for your game. A game can have multiple matchmakers, each configured for different game modes or experiences as needed. When your game sends a matchmaking request to FlexMatch, it specifies which matchmaker to use.
+ **FlexMatch matchmaking rule set** – A rule set contains all the information that is needed to evaluate players for a potential matches and approve or reject. The rule set defines a match's team structure, declares the player attributes that are used for evaluation, and provides rules that describe the criteria for an acceptable match. Rules can apply to individual players, teams, or the entire match. For example, a rule might require that every players in the match choose the same game map, or it might require that all teams have similar player skill average.
+ **Amazon GameLift Servers game session queue (for FlexMatch with Amazon GameLift Servers managed hosting only)** – A game session queue locates available hosting resources and starts a new game session for the match. The queue's configuration determines where Amazon GameLift Servers looks for available hosting resources and how to select the best available host for a match. 

**Custom components**

The following components encompass functionality that's required for a complete FlexMatch system that you must implement based on the architecture of your game.
+ **Player interface for matchmaking** – This interface enables players to join a match. At a minimum, it initiates a matchmaking request through the client matchmaking service component and provides player-specific data, such as skill level and latency data, as needed for the matchmaking process.
**Note**  
As a best practice, communication with the FlexMatch service should be done by a backend service, not from a game client. 
+ **Client matchmaking service** – This service fields the player join requests from the player interface, generates matchmaking requests, and sends them to the FlexMatch service. For requests in process, it monitors matchmaking events, tracks matchmaking status, and takes action as needed. Depending on how you manage game session hosting in your game, this service may return game session connection information back to players. This component uses the AWS SDK with the Amazon GameLift Servers API to communicate with the FlexMatch service.
+ **Match placement service (for FlexMatch as a standalone service only)** – This component works with your existing game hosting system to locate available hosting resources and start new game sessions for matches. The component must get the matchmaking results and extract the information needed to start a new game session, including player IDs, attributes, and team assignments for all players in the match. 

# FlexMatch matchmaking process
<a name="gamelift-match-howitworks"></a>

This topic describes the sequence of events in a basic matchmaking scenario, including the interactions between the various your game components and the FlexMatch service. 

**Step 1: Request matchmaking for players**  
A player using your game client clicks a "Join Game" button. This action causes your client matchmaking service to send a matchmaking request to FlexMatch. The request identifies the FlexMatch matchmaker to use when fulfilling the request. The request also includes player information that your custom matchmaker requires, such as skill level, play preferences, or geographic latency data. You can make matchmaking requests for one player or multiple players.

**Step 2: Add requests to the matchmaking pool**  
When FlexMatch receives the matchmaking request, it generates a matchmaking ticket and adds it to the matchmaker's ticket pool. The ticket remains in the pool until it is matched or a maximum time limit is reached. Your client matchmaking service is periodically notified about matchmaking events, including changes in ticket status.

**Step 3: Build a match**  
Your FlexMatch matchmaker continually runs the following process on all tickets in its pool:  

1. The matchmaker sorts the pool by ticket age, then begins building a potential match starting with the oldest ticket. 

1. The matchmaker adds a second ticket to the potential match and evaluates the result against your custom matchmaking rules. If the potential match passes evaluation, the ticket's players are assigned to a team. 

1. The matchmaker adds the next ticket in sequence and repeats the evaluation process. When all player slots have been filled, the match is ready.
Matchmaking for large matches (41 to 200 players) uses a modified version of the process described above so that it can build matches in a reasonable time frame. Instead of evaluating each ticket individually, the matchmaker divides a pre-sorted ticket pool into potential matches, and then balances each match based on a player characteristic that you've specified. For example, a matchmaker might pre-sort tickets based on similar low-latency locations, and then use post-match balancing to make sure that the teams are evenly matched by player skill.

**Step 4: Report matchmaking results**  
When an acceptable match is found, all matched tickets are updated and a successful matchmaking event is generated for each matched ticket.   
+ FlexMatch as a standalone service: Your game receives match results in a successful matchmaking event. Result data includes a list of all matched players and their team assignments. If your match requests contain player latency info, the results also suggest an optimal geographic location for the match. 
+ FlexMatch with an Amazon GameLift Servers hosting solution: Match results are automatically passed to an Amazon GameLift Servers queue for game session placement. The matchmaker determines which queue is used for game session placement.

**Step 5: Start a game session for the match**  
After a proposed match is successfully formed, a new game session is started. Your game servers must be able to use the matchmaking result data, including player IDs and team assignments, when setting up a game session for the match.  
+ FlexMatch as a standalone service: Your custom match placement service gets match result data from successful matchmaking events, and connects to your existing game session placement system to locate an available hosting resource for the match. After a hosting resource is found, the match placement service coordinates with your existing hosting system to start a new game session and acquire connection information.
+ FlexMatch with an Amazon GameLift Servers hosting solution: The game session queue locates the best available game server for the match. Depending on how the queue is configured, it tries to place the game session with the lowest-cost resources and where players will experience low latency (if player latency data is provided). Once the game session is successfully placed, the Amazon GameLift Servers service prompts the game server to start a new game session, passing on the matchmaking results and other optional game data. 

**Step 6: Connect players to the match**  
After a game session is started, players connect to the session, claim their team assignment, and begin gameplay.   
+ FlexMatch as a standalone service: Your game uses the existing game session management system to provide connection information back to players. 
+ FlexMatch with an Amazon GameLift Servers hosting solution: On a successful game session placement, FlexMatch updates all of the matched tickets with game session connection information and a player session ID. 

# FlexMatch supported AWS Regions
<a name="match-regions"></a>

If you're using FlexMatch with an Amazon GameLift Servers hosting solution, you can host matched game sessions in any location where you are hosting games. See the [complete list of AWS Regions and locations for Amazon GameLift Servers hosting](https://docs.aws.amazon.com/gameliftservers/latest/developerguide/gamelift-regions.html).