# Best Practices

> Follow recommended patterns to optimize lobby performance by using events instead of polling and maintaining active lobbies.

The Lobby service is very flexible and can be used for a wide variety of different scenarios, but there are a few
patterns and practices that you should generally try to follow to provide the best experience for your users.

* [Prefer using events instead of polling](#prefer-using-events-instead-of-polling)
* [Lobbies are not "realtime"](#lobbies-are-not-realtime)
* [Ensure your lobby remains active](#ensure-your-lobby-remains-active)

## Prefer using events instead of polling

Polling a lobby will result in longer delays between changes to the lobby being synchronized and will result in higher
bandwidth and compute usage by the client.  Events will ensure that clients only do work when there is a change to the
lobby metadata.

## Lobbies are not "realtime"

Try to avoid using a lobby to pass "realtime" data.  Lobbies are intended to be used to find other players and then
connect to them using some other mechanism (e.g. a direct P2P connection, or a [Relay](/relay.md).  These "realtime"
connections allow much faster communication between clients and are much more efficient for passing larger amounts of
data.

As a general rule of thumb, you should store data in a lobby that would likely be used to find or filter lobbies, or
certain private data that needs to be accessible to all lobby members.

For example:

* Map Type: *Free For All* - Public lobby data to enable a player to find a specific game mode.
* Player Character: *Mage* - Public player data used to determine whether someone is already in the lobby with a
  specific character class.
* Dedicated Server Connection Key: *\[something secret]* - Private lobby data that members use to connect to a game
  server.

If you are keeping the lobby active for a longer period of time, then it can be reasonable to store other types of data
that need to be synchronized between lobby members but don't need particularly low latency.  This can be useful for
certain asynchronous game types where players don't maintain a direct connection with each other or a central server.

## Ensure your lobby remains active

If you don't [heartbeat a lobby](./heartbeat-a-lobby) it will go inactive!
