node.js – What is a good way to ensure that the local Redux Store in a React Native app is up-to-date with every mutation between devices?


I have a working React Native app that retrieves data from the backend using the Node-created REST API and stores it in the local Redux store. Consider two scenarios for a game application with a leaderboard that illustrates the problem:

  1. Player A was number 1 in the world, but now Player B claimed that title. A's local cache now needs to be updated to show # 2 instead of # 1.
  2. A player plays on the same device on the same device, and each time a device reaches a new high score, the cache needs to be updated on other devices.

For an app, I suppose that simple Firebase would be a viable option. A Firebase-style solution does not fit with my project because the backend logic is a bit more complicated. The current solution is to overhaul data and, in some particularly painful and problematic cases, set an interval for retrieving new data. I am looking for an optimal solution to this problem that minimizes the amount of data going back and forth between frontend and backend and (ideally) maximizes cost efficiency.

What I have in mind is the GraphQL API (which will be developed soon), with a real-time connection that passes status updates to the clients when relevant data is mutated. I am personally new to GraphQL and have only a basic understanding of it. I have not tried the real-time function yet, so maybe I'm missing a few details.

The next problem is, as we can see, if an update is needed on the backend page. One implementation I can imagine is a redis store that maps every data point that can be updated to a list of connected devices that have cached that data. It does not seem like a terrible solution to me, but it's a bit of extra work and a bit of potential to do things wrong. So I can not help wondering if there is an existing solution that can help solve this problem in a simpler way, as this seems to be a naturally occurring problem.

Google was not very helpful, it just shows intro tutorials on React, React Native, Redux and Apollo. Perhaps there is an existing term to describe this problem of which I have no knowledge.

TO UPDATE:

Seems Prisma is exactly what I'm looking for, unfortunately it does not seem to support DynamoDB, which we use as a database.