1

Hello all,

I'm building a 'complex' social english vocabulary 'game' in React/Redux and GraphQL/GraphCool

Is it a best practice to save all the state only to redux while the app is active, and only dispatch the user/game state to the backend in like 5 / 10 minute intervals, and / or when the user quits the app ?

It feels like mutating every state change might be spawning to many requests unnecessarily ?

Am I thinking in the right direction here ?

Thanks!

2 Answers2

1

Great question.

It depends on what your trying to achieve with your app. It boils down to how often the user is leaving the app, and how often you want to save it.

If the user leaves the app within the 5-10 minute interval, and your site doesn't happen to save it, that will be fairly poor UX since that user will come back to find that they lost track of their place in the game. So the trick is to find the balance of how much you can batch at a time and how often, wherein your user doesn't feel like his/her actions are not being saved if at any given time they close the app.

Hope this helps!

vince
  • 1,904
  • 1
  • 12
  • 17
  • 1
    I agree, although there should be something I can use like "Are you sure you want to leave this site ?" and use that specific time as a 'lifecycle' to send the data to the backend. Or something similar. Thanks for the response :) – Michiel Nuyts Apr 25 '17 at 07:19
  • Yep, you can try persisting the data on an `onLeave` basis :) – vince Apr 25 '17 at 17:41
1

Interesting idea, I think you can definitely make it work. However, I think you might find that those request are quite cheap anyway, and that you should delay optimization until you see that it is needed. If its not necessary then the time spent on this will be a waste.

I would worry that you might keep running into complications that arise from trying to throttle calls without limiting usability, in more ways than you initially expect.

Unless you have planned everything before you start programming, go with (1) make it work, (2) make it right, (3) make it fast, where the last step would include any cost-reducing optimizations.

ArneHugo
  • 6,051
  • 1
  • 26
  • 47
  • Thanks for the reply, I already implemented loading the initial data from the backend to the redux store, I feel this is probably going to be the easiest to work with in the long run, Redux is a fun developing experience . And with this approach my components don't get cluttered up with GraphQL queries. Al tough I'll try the Apollo approach as well with a few components and see what works best. – Michiel Nuyts Apr 25 '17 at 09:26
  • 1
    I just want to stress the importance of focusing on the core value first and delaying optimizations until you really need it. Often when working a new system you find that your users will steer it down a different path than you originally planned. Early optimizations will slow you down in this process and ultimately result in a worse product. This is the entire premise of Graphcool - validate quickly and evolve your product together with your users. – sorenbs Apr 26 '17 at 09:05