I implemented Global Trading for my RPG

Hey everyone! I’m working on Path of Magic, an RPG centered on wizards and spellcasting. I wanted a way for players to trade rare items, but I personally find the standard Roblox trading approach, which usually requires that both players are online and in the exact same server, to be really tedious.

Think of it like a global marketplace. If I have 20 Iron Ore I want to sell, I put in a Sell Order. The system escrows those items and puts them on the market. Later, an offline or online player from any server can put in a Buy Order. A matching algorithm automatically pairs the orders based on price priority and facilitates the trade.

If folks are interested, I might write up a lower level tutorial, but here is the high level architecture I used to make it robust and scalable:

  • DataStore/ProfileStore acts as the source of truth for persisting player market listings and escrowed assets.
  • MemoryStoreService handles the live global order books. It makes heavy use of SortedMap to guarantee First-In-First-Out matching, using a composite of Price and Timestamp as the sort key.
  • Order book keys in MemoryStoreService are sharded (appending a random 1-5 suffix). This allows parallel querying and helps avoids rate limits for high volume items.
  • Cross server messaging using ProfileStore:MessageAsync to deliver fulfilled items and gold directly to a player’s inbox, even if they are offline.
  • A dead letter queue that uses standard DataStoreService as a safety net to catch and save any failed cross-server deliveries, ensuring zero item loss during server crashes.

Would love to hear any feedback or thoughts on this!

1 Like