MemoryStore and MessagingService: matchmaking across servers

Match Beacon Yard players across lobby servers with a MemoryStore queue and MessagingService, with the documented quotas worked out and the failure cases a real queue must survive.

Project lesson, about 80 minutes, 12 steps

By the end you can

  • Choose between DataStore, MemoryStore and MessagingService for a given piece of cross-server state
  • Build a matchmaking queue with MemoryStoreQueue, and explain invisibility timeouts, expiry and why a server can only teleport its own players
  • Use MessagingService for announcements and match-ready hints, treating delivery as best effort, and budget requests against the documented quotas
  • Decide when Roblox's built-in matchmaking with a server attribute is enough, and when you need your own queue

Before this: A lobby place: reserved servers and teleports, DataStores: saving without losing a single coin

1Two lobby servers, one queue

At the m11-two-places milestone, Beacon Yard splits into Lobby and Yard places. Three players stand in lobby server A and two in lobby server B. A yard needs four. Each lobby has a Lua table of waiting players, and neither can see the other's. Five players are waiting and nobody can start a match.

The lesson uses a yard of four so the arithmetic is easy to see. The repo is smaller: Config at m11-two-places has MATCH_SIZE = 2, QUEUE_HIDE_SECONDS = 10 and MATCH_WAIT_SECONDS = 20. Read the lesson's 4 and 30 as teaching numbers. The idea is the same, and the diff shows the repo's values.

The fix is a place that every server can read and write: a queue outside any single server. Roblox gives you three cross-server services, and they are for different jobs.

Cross-server matchmaking flowLobby servers add and read tickets in a MemoryStore queue, announce formed groups on MessagingService, teleport their own players to a reserved Yard server, and persist profiles in DataStore.ticketsmatchteleport ownsaveLobby serversAddAsync / pollMemoryStoreyard-queueMessagingmatch-readyDataStoreprofiles, boardYard serverreserved match
Figure 1.1. MemoryStore holds short-lived tickets, MessagingService broadcasts match-ready hints, and DataStore keeps durable profiles.

Match each need to the service that fits it.

  1. A player's coins, kept for years
  2. A queue of players waiting for a match, gone in minutes
  3. Tell every server a team just finished a 10-round streak
  4. A global top-100 board that must survive restarts
Answer

A player's coins, kept for years: DataStore (through ProfileStore); A queue of players waiting for a match, gone in minutes: MemoryStore queue; Tell every server a team just finished a 10-round streak: MessagingService; A global top-100 board that must survive restarts: OrderedDataStore. Durable data goes in DataStores. Short-lived shared state goes in MemoryStore. A one-off message to other servers goes through MessagingService, which keeps nothing.

Open this step in lesson mode · Link to this step · This confused me

2MemoryStore: the lobby whiteboard

MemoryStore is a fast, in-memory service that every server in the experience can reach. It is meant for frequent, short-lived data, and entries vanish when they expire1. It has three data structures: a sorted map (keys with a sort order), a hash map (plain key-value, spread over many partitions) and a queue.

Stored dataMemoryStore is the lobby whiteboard, wiped regularly.
In the pictureIn Roblox
The whiteboardA MemoryStore queue, sorted map or hash map
Writing a name on itAddAsync or SetAsync with an expiration
The janitor wiping itItems expiring

See the whole analogy cast

MemoryStore is the whiteboard in the lobby. Anyone can walk up and write a name on it, and the janitor wipes it on a schedule. Never keep your only copy of anything on the whiteboard.

Think of it as The lobby whiteboard, wiped regularly

Every item has an expiration in seconds, up to a maximum of 45 days (3,888,000 seconds), which is also the default. The docs recommend the shortest one that works, and explicit deletion for freeing space1. A matchmaking ticket that is still waiting after two minutes is probably stale, so it should expire after two minutes.

Why must the queue never be the only place a player's coins live?

  1. Entries expire and can be lost, while a DataStore profile is durable
  2. MemoryStore cannot hold numbers
  3. Queues only work for strings
  4. Coins are too large for a queue
Answer

Entries expire and can be lost, while a DataStore profile is durable. Expiry is part of the design, and the memory quota can reject writes. Anything that must survive is saved through DataStores, and the queue holds only a ticket that points at it.

Open this step in lesson mode · Link to this step · This confused me

3The queue API

A queue is first in, first out, with an optional priority per item. The calls you need2:

Reference MemoryStoreQueue, the calls matchmaking uses

Reading does not remove. Removing is a separate, explicit step.

MemoryStoreService:GetQueue(name, invisibilityTimeout?)
A queue shared by every server, by name. The invisibility timeout defaults to 30 seconds.
queue:AddAsync(value, expiration, priority?)
Adds a ticket that disappears after expiration seconds. Higher priority is read first; equal priority is first in, first out.
queue:ReadAsync(count, allOrNothing?, waitTimeout?) -> (items, id)
Reads up to 100 items and hides them from other readers for the invisibility timeout. With waitTimeout 0 it returns at once.
queue:RemoveAsync(id)
Permanently removes the items a read returned. Do it before the timeout ends.

The invisibility timeout is what stops two lobby servers reading the same four tickets. A read hides the items from other readers. If the reader crashes before RemoveAsync, the items reappear after the timeout, so no ticket is lost.

luau
local queue = MemoryStoreService:GetQueue("yard-queue", 30)
 
-- A lobby server adds a player who stepped on the pad.
queue:AddAsync({ userId = player.UserId }, 120)
 
-- One server forms matches. waitTimeout 0 means do not wait.
local items, readId = queue:ReadAsync(4, false, 0)
if items and #items >= MIN_PLAYERS then
	-- start a match, then:
	queue:RemoveAsync(readId)
end

A server reads 4 tickets, then crashes before RemoveAsync. Their expiration is later than the invisibility timeout. What happens to the tickets?

  1. They become visible again after the invisibility timeout, so another server can match them
  2. They are deleted at once
  3. They stay hidden forever
  4. They move to a DataStore
Answer

They become visible again after the invisibility timeout, so another server can match them. The invisibility timeout guarantees that every ticket can be processed even if a reader fails. The same rule means a slow reader that removes late can be duplicated: finish within the timeout.

Open this step in lesson mode · Link to this step · This confused me

4A server can only teleport its own players

Here is the catch that shapes the whole design. TeleportAsync takes Player objects, and a server only has Player objects for players who are in it. The server that reads the queue forms a match of four players, but those four may be spread over three lobby servers. It cannot teleport the other servers' players.

So the matcher does two things. It creates the match, picking a ReservedServerId, and it tells everyone. Then each lobby server teleports its own players with that same id. Here MessagingService enters3.

Stored dataRemember: MemoryStore is the lobby whiteboard, wiped regularly.

The whiteboard holds the tickets. The matcher posts "match 7f3c: players 11, 12, 13, 14" and each lobby server looks for names it knows.

	local session = playerStore:StartSessionAsync(profileKey(player.UserId), {
		Cancel = function()
			return player.Parent ~= Players
		end,
	})
Figure 4.1

On arrival in the yard, the same call loads the profile. It waits while the lobby server still holds the lock, which is why the lobby ends its session before the teleport.

Put the matchmaking steps in order.

  1. One server reads 4 tickets and creates a match with a new ReservedServerId
  2. The matcher removes the tickets from the queue
  3. The matcher records the match and publishes a message that it is ready
  4. Players step on the pad; their lobby server adds tickets to the queue
  5. Each lobby server finds its own players in the match and calls TeleportAsync with that id
Answer

1. Players step on the pad; their lobby server adds tickets to the queue 2. One server reads 4 tickets and creates a match with a new ReservedServerId 3. The matcher records the match and publishes a message that it is ready 4. Each lobby server finds its own players in the match and calls TeleportAsync with that id 5. The matcher removes the tickets from the queue. Queue, match, announce, every server teleports its own, then clean up. Removing the tickets last in this version keeps them safe if the matcher dies early, at the cost of finishing within the invisibility timeout.

Open this step in lesson mode · Link to this step · This confused me

5MessagingService: the PA system

MessagingService lets one server publish a message to a topic, and every server subscribed to that topic runs its callback. Nothing is stored. A server that is not listening at that moment never hears it. Delivery is best effort and not guaranteed, so Roblox says to design the experience so that failed deliveries are not critical3.

Stored dataMessagingService is the PA system across arenas.
In the pictureIn Roblox
The announcementPublishAsync to a topic
Listening for itSubscribeAsync on every server
Missing itA server that was not subscribed at the time never hears it

See the whole analogy cast

MessagingService is the PA system across arenas. An announcement goes out once, to whoever is listening. If you were in the restroom, you missed it.

Think of it as The PA system across arenas

Stored dataRemember: MessagingService is the PA system across arenas.

luau
MessagingService:SubscribeAsync("match-ready", function(message)
	local data = message.Data -- a table, at most 1 kB
	for _, userId in data.userIds do
		local player = Players:GetPlayerByUserId(userId)
		if player then
			-- teleport this server's own players with data.serverId
		end
	end
end)
 
MessagingService:PublishAsync("match-ready", { serverId = id, userIds = ids })
Where does it break?“The PA system across arenas” is a good picture of messagingservice. Where does it stop being true?

It breaks here. Delivery is best effort and a message can be late or lost, so it is only a hint; keep the truth in a store that servers can poll.

The true model. MessagingService publishes small messages (1 kB) to a topic and every subscribed server receives them. Nothing is stored, and Roblox says delivery is not guaranteed.

The PA picture breaks on trust. A real PA announcement is heard by everyone and loud. A message here can be late, dropped, or arrive in a different order than it was sent, so it can only be a hint. The match record has to live somewhere a lobby server can look it up, so a server that missed the message still finds its players. MemoryStore is the place: write userId → serverId entries with a short expiry, and have every lobby poll for its own players every few seconds as a backup.

Lobby server B was restarting when match-ready was published. How does its player still get teleported?

  1. B polls the match records in MemoryStore for its own players, so the missed message only delays things
  2. Roblox replays the message when B starts
  3. The player is stuck in the lobby forever
  4. B teleports everyone in the queue
Answer

B polls the match records in MemoryStore for its own players, so the missed message only delays things. MessagingService stores nothing, so a missed message is gone. The short-lived match record stays in MemoryStore long enough for lobbies to poll it, and polling is the backup that makes the system correct rather than merely fast.

Open this step in lesson mode · Link to this step · This confused me

6Limits and quotas, worked out

Cross-server services have budgets like DataStores do. The numbers below were checked against the documentation on 2026-11-23, and the docs say MessagingService's limits are subject to change3.

Reference Documented limits used in this lesson

Memory stores are separate in Studio and in live servers, and Extended Services can raise the defaults for a fee.

64 KB + 1.2 KB × users
Per experience, not per server. Writes that add memory fail with TotalMemoryOverLimit when it is full.
1000 + 120 × concurrent users per minute
Queue and sorted-map range reads cost units by items returned, with a minimum of 1. Queue reads add 1 unit every 2 seconds spent waiting.
1,000,000 items, 100 MB
Per data structure. A sorted map or queue lives on one partition.
about 30,000 request units per minute
A safeguard, not a quota. Shard hot structures across several queues or keys.
128 characters, 32 KB
Sorted maps only.
1 kB
Per MessagingService message.
600 + 240 × players per minute
Per game server.
40 + 80 × servers per minute
Per topic. Across the whole game: 400 + 200 × servers.
20 + 8 × players
Plus 240 subscribe requests per minute per server.
Luau
-- 40 players online, 5 lobby servers polling the queue every 5 seconds,
-- each read returning up to 4 tickets (each ticket costs 1 unit).
local ccu = 40
local budget = 1000 + 120 * ccu
local polls = 5 * (60 / 5)
local units = polls * 4
print("budget " .. budget .. " units/min")
print("polling " .. units .. " units/min")
print("share " .. math.round(units / budget * 1000) / 10 .. "%")
 
-- Ten lobby servers each listening to one topic.
local servers = 10
print("topic limit " .. 40 + 80 * servers .. " messages/min")
Figure 6.1. Expected output: budget 5800 units/min polling 240 units/min share 4.1% topic limit 840 messages/min

A single queue sits on one partition that throttles at about 30,000 request units a minute. 30 lobby servers each poll it once a second, and each read immediately returns one ticket. How many units per minute is that?

Answer

1800. 30 × 60 × 1 = 1,800 units a minute, about 6 percent of the partition. These reads return immediately, so they incur no waiting charges. Queues hit limits when many servers read very often, so poll every few seconds, or split the queue by region or skill band.

Here is where the lobby whiteboard picture stops fitting. A physical whiteboard runs out of ink gradually and never refuses a name on its own. MemoryStore enforces a hard experience-wide memory cap and automatic expiry: when the quota fills, new writes fail with TotalMemoryOverLimit, and old entries disappear whether or not anyone finished using them.

Where does it break?“The lobby whiteboard, wiped regularly” is a good picture of memorystore. Where does it stop being true?

It breaks here. Entries expire and the memory quota can reject writes, so it can never be the only copy of anything.

The true model. MemoryStore is a fast, shared, in-memory service for frequent, short-lived data. Items expire (45 days by default) and a queue read hides items for an invisibility timeout (30 seconds by default) until you remove them.

Your experience hits its MemoryStore memory quota (64 KB + 1.2 KB × users) during a traffic spike, and a lobby server tries to AddAsync a new ticket. What happens?

  1. The write fails with TotalMemoryOverLimit, which is why code must wrap calls in pcall and never treat MemoryStore as durable storage
  2. MemoryStore automatically moves older tickets into a DataStore
  3. The quota doubles for free until the spike ends
  4. The write waits silently until a player leaves
Answer

The write fails with TotalMemoryOverLimit, which is why code must wrap calls in pcall and never treat MemoryStore as durable storage. MemoryStore rejects writes that exceed the quota with TotalMemoryOverLimit, and entries also vanish when their expiration passes. Always wrap calls in pcall and keep anything durable in DataStores.

Open this step in lesson mode · Link to this step · This confused me

7Try the queue

The matchmaking queue

The matchmaking queue: a still of the simulation
Figure 7.1.

Two lobby servers, one matcher, a shared queue with an invisibility timeout and a lossy message channel. Add players, start a match, and turn on crashes and message loss.

What does the simulation show a real matchmaker must handle?

  1. Tickets that expire before a match forms
  2. A matcher that dies after reading but before removing
  3. A match-ready message that never arrives
  4. A player who leaves the lobby while waiting
  5. A DataStore write that lands twice
Answer

Tickets that expire before a match forms; A matcher that dies after reading but before removing; A match-ready message that never arrives; A player who leaves the lobby while waiting. Expiry, matcher crashes, lost messages and leavers are all queue and message cases. A double DataStore write is a different problem, handled by session locks and UpdateAsync.

Open this step in lesson mode · Link to this step · This confused me

8What studios use

Other ways pros do this

OptionWhat it isWhen pros pick itTrade-offs
MemoryStore queue plus MessagingServiceA shared queue for tickets and messages to announce matches.Most Roblox matchmaking, from simple party queues to skill bands.Best-effort messages mean you also need a polling backup; budgets to watch.
MemoryStore sorted mapTickets keyed by player, sorted by skill or join time.Skill-based matchmaking that needs to pick the closest players, not just the oldest.One partition per map; you write the matching code.
DataStore as a queueTickets as keys in a DataStore.Almost never. Very slow changes only.Slow, throttled, and last write wins; use MemoryStore for short-lived shared state.
Open Cloud and an external serviceA server outside Roblox owns the queue and calls Open Cloud to teleport.Large studios with their own matchmaking backend and analytics.You run and secure infrastructure; much more to build.

Thirty lobby servers all poll the queue exactly on the minute. What is the likely problem?

  1. A burst of requests that hits the same partition at once; add a random delay to each server's polling
  2. The queue empties itself
  3. MessagingService stops working
  4. Players are teleported twice
Answer

A burst of requests that hits the same partition at once; add a random delay to each server's polling. Synchronised polling creates spikes against one partition. A little random jitter spreads the same number of requests across the minute.

Open this step in lesson mode · Link to this step · This confused me

9Build along: a queue and a match

The m11-two-places milestone is tagged, so you can compare your work with git diff m10-memory m11-two-places.

  • src/server/QueueService.luau
  • src/server/MatchRules.luau
  • src/server/MatchService.luau
  1. In src/server/QueueService.luau, call MemoryStoreService:GetQueue(Config.QUEUE_NAME, Config.QUEUE_HIDE_SECONDS) inside pcall and add { userId = player.UserId, at = os.time() } with AddAsync when a player triggers the queue prompt.

    You should see Stepping onto the lobby queue prompt adds your ticket to Config.QUEUE_NAME with Config.QUEUE_ITEM_SECONDS expiry and shows the queued toast.

  2. Add src/server/MatchRules.luau and the match loop in QueueService.luau: every Config.MATCH_TICK_SECONDS (add a little random jitter in larger games), read up to Config.MATCH_SIZE tickets with waitTimeout 0 and call MatchRules.plan.

    You should see With enough tickets queued, QueueService.tryMatch forms a group via MatchRules.plan with a fresh ReservedServerId.

  3. Publish { serverId, userIds } to Config.MATCH_TOPIC via MessagingService:PublishAsync, subscribe in every lobby server so each teleports only players in Players:GetPlayerByUserId(userId), and call line:RemoveAsync(readId) after publishing. Studio uses MemoryStore data isolated from production1. Use two servers of the published private Lobby to verify that both servers receive the match-ready message.

    You should see In the published Lobby with two servers running, each lobby server receives the match-ready topic and calls TeleportAsync for its own players only.

  4. This step is not in the tag, so you will not find it in the diff. As a production hardening step on top of m11-two-places, write each matched userId to a MemoryStoreHashMap with a 60-second expiry and have each lobby poll for its own players every few seconds as the backup.

    You should see Hardening, not in the m11-two-places tag: even if a MessagingService message is missed, a lobby polling a short-lived hash map still finds and teleports its player.

Open this step in lesson mode · Link to this step · This confused me

10Roblox's own matchmaking, and when it is enough

Everything so far is a queue you built. Roblox also matches every player who joins from the app. It drops servers that are full, private, reserved or about to shut down, scores the rest with signals such as friends, latency, language, age, device and how full the server is, and sends the player to the best score4. On the Creator Hub, Configurations ⟩ Custom matchmaking lets you change those weights and add up to 2 custom signals per game. A signal reads an attribute you declare there: up to 5 server attributes, which your code sets with MatchmakingService:SetServerAttribute and which last only while the server runs, and up to 5 player attributes read from a data store5.

In Beacon Yard's two places, Roblox's matchmaking picks the lobby server, and the yard matches are reserved, so it never sends anyone there. The hand-rolled queue is what groups players into a drill. In Solo mode, one place with no lobby, Roblox's matchmaking is the only one, and it can drop a newcomer into the middle of a drill. A server attribute fixes that without any queue: publish the round phase, and score servers in Idle higher.

luau
-- src/server/MatchmakingPhase.luau, started after RoundService
local MatchmakingService = game:GetService("MatchmakingService")
local RunService = game:GetService("RunService")
 
local MatchmakingPhase = {}
 
function MatchmakingPhase.start()
	if RunService:IsStudio() then
		MatchmakingService:InitializeServerAttributesForStudio({ Phase = "Idle" })
	end
	local function mirror()
		local phase = workspace:GetAttribute("RoundPhase")
		if typeof(phase) ~= "string" then
			return
		end
		local ok, err = MatchmakingService:SetServerAttribute("Phase", phase)
		if not ok then
			warn("[Matchmaking] Phase not set: " .. tostring(err))
		end
	end
	workspace:GetAttributeChangedSignal("RoundPhase"):Connect(mirror)
	mirror()
end
 
return MatchmakingPhase

Build along

m14-ship

  • src/server/MatchmakingPhase.luau
  • src/server/init.server.luau
  1. On the Creator Hub, open the experience, go to Configurations ⟩ Custom matchmaking, and on the Attributes tab create a server attribute Phase with type string and default Idle.

    You should see The Attributes tab lists a server attribute named Phase, type string, default Idle.

  2. On the Configuration tab, create a configuration, add a custom signal on Phase that prefers Idle, give it a weight, save, and apply it to the place.

    You should see A configuration with a server categorical signal on Phase, scoring Idle highest, is saved and applied to the yard place, and Preview and Test shows an Idle mock server winning.

  3. Add MatchmakingPhase.luau, start it after RoundService in init.server.luau, start a drill and read the attribute back from the command bar.

    You should see In a Studio test, starting a drill prints no Phase warning, and MatchmakingService:GetServerAttribute("Phase") in the server command bar returns Active.

Beacon Yard's lobby queue needs exactly four players who all press the pad, sent together to one fresh yard server. Can a custom matchmaking configuration replace QueueService?

  1. No: matchmaking places one joining player on an existing server; forming a group and reserving a new server is still your queue's job
  2. Yes: a Phase signal can collect four players and reserve a server
  3. Yes, if the yard server is marked private
  4. No, because custom matchmaking only works in Studio
Answer

No: matchmaking places one joining player on an existing server; forming a group and reserving a new server is still your queue's job. Use Roblox's matchmaking to choose good public servers, such as Idle yards or lobbies with friends. Use your own queue when players must be grouped first and sent somewhere new.

Open this step in lesson mode · Link to this step · This confused me

11Challenges

Level 2, Builder

Challenge

Split the queue into two skill bands, with a timeout that lets the longest waiters cross over.

Start from
The game at milestone m11 (download)

Done means

  • Two queues, yard-queue-new and yard-queue-veteran, split players by drones downed
  • A match is only formed from one queue
  • A ticket that waits 60 seconds in a band is allowed to match with the other band

Hints

  1. Store dronesDowned from the profile in the ticket.
  2. Keep the wait time in the ticket: the time it was added.
  3. Reading the other queue is a second ReadAsync; mind the request units.

Level 3, Professional

Challenge

Write the pure matchmaking rule in the learner file challenges/work/capstone_lobby.luau. Start from the m14-ship tag in the game repo. The written solution is in challenges/solutions/capstone.md.

Start from
The game at milestone m14 (download)
Grade it
In Studio, press Play, then run game.ServerScriptService.RunGameTests:Invoke("capstone_lobby", "memory-form-matches") in the server command bar. Copy the pass code from Output.

Done means

  • formMatches puts full groups first, in join order
  • A leftover group of at least minPlayers also starts
  • A user id in the queue twice counts once
  • It returns two values: the list of matches, and the ids still waiting
  • It does not change the table you pass in
  • challenges/capstone_lobby.luau prints TEST PASS for every check

Hints

  1. Remove duplicates first, keeping the earliest position.
  2. Take size players at a time from the front.
  3. Whatever is left and at least minPlayers is one more match; anyone else keeps waiting.

The matcher takes 45 seconds to teleport the group, and the queue's invisibility timeout is 30 seconds. What can go wrong?

  1. The tickets reappear and another server can match the same players again
  2. The queue deletes itself
  3. The ReservedServerId changes
  4. Nothing; the timeout only matters for crashes
Answer

The tickets reappear and another server can match the same players again. After 30 seconds the tickets are visible again, so a second matcher can read them while the first is still working. Keep the work inside the timeout, remove tickets early, or choose a longer timeout when creating the queue.

Open this step in lesson mode · Link to this step · This confused me

12Recap

Retiring the analogy

You no longer need “the lobby whiteboard, wiped regularly”. MemoryStore is a fast, shared, in-memory service for frequent, short-lived data. Items expire (45 days by default) and a queue read hides items for an invisibility timeout (30 seconds by default) until you remove them.

Retiring the analogy

You no longer need “the pa system across arenas”. MessagingService publishes small messages (1 kB) to a topic and every subscribed server receives them. Nothing is stored, and Roblox says delivery is not guaranteed.

Recap

  1. Durable data goes in DataStores, short-lived shared state in MemoryStore, and one-off announcements through MessagingService, which stores nothing.
  2. A MemoryStore queue read hides the tickets for the invisibility timeout (30 s by default) and must be followed by RemoveAsync; items also expire on their own.
  3. A server can only teleport its own players, so the matcher publishes the match and every lobby teleports its own, with a polled MemoryStore record as the backup for lost messages.
  4. Roblox's own matchmaking scores existing public servers for one joining player; a server attribute such as Phase steers it, but grouping players into a new server stays your queue's job.

MemoryStore is the lobby whiteboard, wiped regularly, until entries expire and the memory quota can reject writes, so it can never be the only copy of anything.

MessagingService is the PA system across arenas, until delivery is best effort and a message can be late or lost, so it is only a hint; keep the truth in a store that servers can poll.

Next Monetization: products, passes, subscriptions, economy

Open this step in lesson mode · Link to this step · This confused me