I am currently creating an Android application and I have the following questions:

We have a server which provides data for the app in form of a REST-JSON-API. The App is following the MVVM architecture. Now my question is: When should we fetch data from that server? We could fetch all data at once when the user reaches the first data related screen or we could make mulitple fetch calls over the lifespan of the application.

Also when we are posting user-generated data to the server, should we gather all the data first and then make one post request or make multiple requests by sending as soon as the partial data is ready?

What's your opinion on this issue and can you provide me with any guidelines on this topic?

  • It's unlikely that you would want to fetch all of the data you could possibly need at once. Since you can't predict what path your user will take through your application, you can't predict what specific data they're going to need. So usually, you fetch what you need, when you need it. – Robert Harvey Aug 20 at 20:44

You'll hate my answer, but here it is - it depends on the use case.

While syncing with the server, you generally, want to achieve two things:

  • have the latest data state at all paries as soon as possible (server, client)
  • have the smallest number of requests and transferred data

To achieve this, you must familiarize yourself with your business requirements, i.e.:

  • how often your data changes?
  • do you need to support offline mode?
  • what data is crucial for correct usage?
  • will users be happier with old data but served immediately or it's crucial to show only fresh data?
  • who depends on user-generated content and what is thair tolerance time for fresh data?

For example, if your app needs to support offline mode and there are some actions that are relying on some data available, you'll probably need to fetch all that data at soon as possible. For other apps, that do not have those kinds of sensibility - it's an overkill and bad usage of resources.

So, the decision of when to sync data is a business decision more than a technical one. If I were you, I would require those answers from the product owner, and only after that, you can start thinking about technical implementation.

Very often, in the fear of looking bad or not skilfull enough, we programmers avoid asking crucial questions from our business teams and instead search for those answers in design patterns, practices, etc. But patterns are useful only after we know the business case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.