How do I create a best-selling system?

I want to create a best-sellers list in my game and sort the items accordingly, but I’m not sure how to store the data and set up the system. What are your suggestions? Actually, I tried storing data day by day using MemoryStoreService, but I couldn’t find an true method.

This simplest way is look at your analytics and hardcode it :melting_face:

The challenge of using any centralized data source is scaling it infinitely. Pretty sure there’s limits on updates on any one key.

You could go with some leader election solution to have a single server be responsible for updating the count to ensure you don’t hit rate limits, but unless you expect the best selling item to change frequently, hardcoding it is probably the way to go

Yes, but I think there should still be an easier method.

I guess realistically people wouldn’t be making a ton of purchases so you could get away with using a single data source.

What’s wrong with what you proposed in the original post, i.e. increment a number upon purchase?

OrderedDataStore seems like a reasonable fit for this scenario.

Each item id gets its own key in the OrderedDataStore. For each purchase, increment the key’s value.

When fetching the most popular item, just get the first item of the first page of the OrderedDataStore, and that’s your most popular item id.

However, how will I make it decrease after a certain period, for example, if I want to do it based on sales from the last 2 weeks?

The easiest way to do that is to use a different scope/data store name based on a 2 week window, so that every 2 weeks it starts with a fresh set of data.

But if you want a rolling window that doesn’t have hard resets, then I guess you’d have to either split it across multiple OrderedDataStores or use a regular data store and store all purchases in a single key by day. When fetching most popular purchases, fetch each key for the last 2 weeks and add up the values.

That ends up being a lot of fetches (14 for two weeks), so you could consider consolidating into larger time windows and storing multiple days within a single time window. (e.g. store by Week instead of by Day, but still have the day it was purchased as a value in the table for that key)

So for example, you can keep it in ordered data stores like so:

week 1 OrderedDataStore name could be purchaseCounts_2025_01_01_to_2025_01_07
it can contain data like
item1: 100
item2: 57
item3: 21

week 2 OrderedDataStore name could be purchaseCounts_2025_01_08_to_2025_01_15
it can contain data like
item2: 128
item1: 63
item3: 18

Then to get the last two weeks, calculate what the names would be for the last two weeks based on the current date, fetch both ordered data stores’ first page, and aggregate the counts for each item id. Pick the one with the most purchases

When a purchase is made, calculate the name for the current week based on the current date, and increment the value for key matching the purchased item id

probably, i will do manually but thanks

Yes, I thought of this too, but too many requests and optimization problems may occur. Doing it manually seems the most logical right now.