Write contention on DataStore:Update. Does it scale?

I’m working on a stupid game that wants to use DataStores as a database instead of a per user key value store.

Basically there will be a giant table of trivia questions with stats. Basically a huge array of objects that look like this:

local question {
id = createGuid(),
text = "Test Question",
timesShown = 0,
timesCorrect = 0

This array might be huge, so in the case that it’s bigger than 200kb (the DataStore max value size), it will be broken up across multiple “pages” (different sequential keys).

So the first key I would save is the page table:

local pages {
totalPages = 0,
lastPageSize = 0

I’m really worried about write contention between servers with this design. Since the blobs are so big, every time I want to update my table, I need to blast 200kb to the DataStore and it will be very chatty. What happens if multiple servers want to update the table at once? Do I need to handle locking? The docs say that on write contention the Update will retry. I imagine this queue is only so deep?

I’ve also thought about a message passing scheme where if I have 100 servers of the game running, one of them is authoritative and handles all database writes and the others funnel their updates to that server via message passing. It sounds very clunky.

I could also save each question as it’s own key/value pair but then it is really hard to sort my table based on how hard questions are (timesCorrect / timesShown). It’s also more difficult to fetch random questions if I allow for deletions (i.e. I’ll end up with a giant index of IDs stuffed in a table anyways).

Can this be made to work with the current DataStore API?


If you’re going limitless, then I think the best solution to your problem is going to be:

  1. Individual key / value pairs for each question saved to DataStoreService
  2. One lookup table value in the DataStore to track page count
  3. Use OrderedDataStore for sorting questions by their difficulty, or any additional property in parallel

You’ll probably have to cut some corners for the flexibility of your queries either-way.

As for the limits of global UpdateAsync queues… I don’t think it has been documented anywhere :joy:
I would sure be interested to know myself.