Lesson 5 of 5
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.
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
Step 1 of 12
Two 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.
Match each need to the service that fits it.
Step 2 of 12
MemoryStore: 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.
| In the picture | In Roblox |
|---|---|
| The whiteboard | A MemoryStore queue, sorted map or hash map |
| Writing a name on it | AddAsync or SetAsync with an expiration |
| The janitor wiping it | Items expiring |
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?
Press 1 to 4 to choose, Enter to check.
Step 3 of 12
The 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.
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?
Press 1 to 4 to choose, Enter to check.
Step 4 of 12
A 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,
})
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.
- One server reads 4 tickets and creates a match with a new ReservedServerId
- The matcher removes the tickets from the queue
- The matcher records the match and publishes a message that it is ready
- Players step on the pad; their lobby server adds tickets to the queue
- Each lobby server finds its own players in the match and calls TeleportAsync with that id
Step 5 of 12
MessagingService: 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.
| In the picture | In Roblox |
|---|---|
| The announcement | PublishAsync to a topic |
| Listening for it | SubscribeAsync on every server |
| Missing it | A server that was not subscribed at the time never hears it |
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.
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?
Press 1 to 4 to choose, Enter to check.
Step 6 of 12
Limits 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.
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?
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?
Press 1 to 4 to choose, Enter to check.
Step 7 of 12
Try the queue
The matchmaking queue
Goal Fill the queue from two lobby servers, crash the matcher before it removes the tickets, and see them come back; then drop the match-ready message and watch the polling backup teleport the stragglers.

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?
Press 1 to 5 to choose, Enter to check.
Step 8 of 12
What studios use
Other ways pros do this
| Option | What it is | When pros pick it | Trade-offs |
|---|---|---|---|
| MemoryStore queue plus MessagingService | A 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 map | Tickets 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 queue | Tickets 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 service | A 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?
Press 1 to 4 to choose, Enter to check.
Step 9 of 12
Build 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.
Build along
src/server/QueueService.luausrc/server/MatchRules.luausrc/server/MatchService.luau
In
src/server/QueueService.luau, callMemoryStoreService:GetQueue(Config.QUEUE_NAME, Config.QUEUE_HIDE_SECONDS)insidepcalland add{ userId = player.UserId, at = os.time() }withAddAsyncwhen 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.
Add
src/server/MatchRules.luauand the match loop inQueueService.luau: everyConfig.MATCH_TICK_SECONDS(add a little random jitter in larger games), read up toConfig.MATCH_SIZEtickets withwaitTimeout 0and callMatchRules.plan.You should see With enough tickets queued, QueueService.tryMatch forms a group via MatchRules.plan with a fresh ReservedServerId.
Publish
{ serverId, userIds }toConfig.MATCH_TOPICviaMessagingService:PublishAsync, subscribe in every lobby server so each teleports only players inPlayers:GetPlayerByUserId(userId), and callline: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.
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 matcheduserIdto aMemoryStoreHashMapwith 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.
Step 10 of 12
Roblox'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.
-- 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
src/server/MatchmakingPhase.luausrc/server/init.server.luau
On the Creator Hub, open the experience, go to Configurations ⟩ Custom matchmaking, and on the Attributes tab create a server attribute
Phasewith type string and defaultIdle.You should see The Attributes tab lists a server attribute named Phase, type string, default Idle.
On the Configuration tab, create a configuration, add a custom signal on
Phasethat prefersIdle, 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.
Add
MatchmakingPhase.luau, start it afterRoundServiceininit.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?
Press 1 to 4 to choose, Enter to check.
Step 11 of 12
Challenges
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
Meet the criteria above, then record your own result. No test grades this check.
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
The matcher takes 45 seconds to teleport the group, and the queue's invisibility timeout is 30 seconds. What can go wrong?
Press 1 to 4 to choose, Enter to check.
Step 12 of 12
Recap
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
- Durable data goes in DataStores, short-lived shared state in MemoryStore, and one-off announcements through MessagingService, which stores nothing.
- 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.
- 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.
- 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.
Queued for review