Is this a good approach to a cross server marketplace?

First of all, a lot of this will be pseudo-code because I am mostly looking for feedback on the approach to the cross server marketplace for an RPG game. Mostly, this is based on the auction house in World of Warcraft.

What I want to do:

  • User can list an item (such as a piece of armor)
    • When listing the item, it shows all other listings of that item on the UI
    • You can then list the item for as much or as little Gold as you want.
    • If they list the item, the item is removed from their inventory and a MemoryStore is sent.
  • User can browse the marketplace
    • Search for an item they want, and if they see it at a good price they can purchase it with gold.
  • After an item is purchased, a memory store is sent.
  • When memory stores are processed, the gold will be sent to the seller and the item will be sent to the player via an in-game mail system. Items/gold can be sent to players in a mailbox no matter what server they’re in or if they’re offline. This is also a fallback in case they use gold to try and buy an auction that was delisted; it simply mails back their gold.

My approach to this:

I am using a DataStore for the auction data storage. It contains a dictionary of all the auctions, and the current JobId as well as a ping os.time() to determine the last time it was alive. On server close, it sets the JobId to nil.

  • If the server’s JobId is equal to where it’s currently loaded and locked to, it processes the MemoryStoreService queue.
  • If it does not, it simply updates the auction dictionary on the server to display items to the player.
  • If the server’s JobId doesn’t exist (meaning it’s dead) or the last update time was several minutes, that means the server was closed or crashed, so the current server loads/takes over the auctions parsing.

Is this a good approach, and should I just be fully using MemoryStore service purely for this? I was a bit concerned of using MemoryStore purely due to all of the limitations, but if anyone could describe a way to do this better, or give feedback on any edge cases that’d be great.

As I said this is pseudo-code as I don’t need help coding what I described, I have it working properly as I described on a test place. I am mostly looking for review on the system design in general.

Your approach of using a DataStore for auction data storage and MemoryStoreService for processing the queue has some benefits and drawbacks.

One benefit is that DataStore can handle large amounts of data, which is useful for storing all the auctions. MemoryStoreService is also designed for high throughput and low latency, making it suitable for processing the MemoryStore queue.

However, there are also some drawbacks to this approach. For example, using DataStore and MemoryStoreService together can be expensive, especially if you have a large number of auctions and frequent updates to the MemoryStore queue. Additionally, using a single server to process the MemoryStore queue can create a bottleneck and reduce the overall performance of your system.

A better solution might be to use a distributed database and a distributed message queue. For example, you could use a NoSQL database like MongoDB or Cassandra to store the auction data, and a message queue like RabbitMQ or Apache Kafka to handle the MemoryStore queue.

Using a distributed database or cache would allow multiple servers to access the auction data simultaneously, improving scalability and reducing the load on individual servers. Using a distributed message queue would allow you to process the MemoryStore queue across multiple servers, improving performance and avoiding bottlenecks.

To further optimize your system, you could also use caching to reduce the number of database queries needed. For example, you could use Redis or Memcached to cache frequently accessed auction data.

To ensure durability, you should implement backups and disaster recovery procedures. This could include regularly backing up your database to a secondary location, using redundant servers, and implementing automated failover procedures to ensure that your system remains available even in the event of a server failure.

So, using a distributed database and a distributed message queue, along with caching and backups, would provide a more efficient and scalable solution for your cross-server marketplace.

1 Like