Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I process a JSON in the frontend or Backend, which is faster? [closed]

I am getting a response from an API as a json response. I am coding in python for backend.

The frontend team needs information from the raw json response for populating a UI so we have to order the json and make it more easier for them to fetch information.

Now I can order the json in a specific format and push to the frontend team or I can pass the raw json response*to the frontend team and let them handle ordering the json and further use for their UI.

Remember my json file size is 15MB.

Which is faster and a better design principle?

Process in the backend then push to frontend or process in the frontend?

like image 287
Danish Xavier Avatar asked Feb 18 '20 05:02

Danish Xavier


1 Answers

As others have noted, there are quite a few good reasons to prefer processing on the back end:

  • if you can remove all unnecessary data from the JSON being sent to the front-end, it will reduce load on the end-user device both in terms of transfer but also in parsing time
  • it may be possible to cache the remote API call, so you don't need to make as many calls out to the remote APIs (which will usually be very slow compared to cache retrieval). You can also potentially cache the after-processing data, so you can just serve that up repeatedly
  • You can detect errors that happen in processing the JSON, whereas that is less visible if it is happening on the client device

One other big advantage to processing the API response on the back-end is that you can choose the structure you send to the front end. That way, if the API you are consuming changes over time (or you change which service you're using to retrieve data) you can handle that change on the back end without it ever affecting the front-end code.

like image 63
SimeonJM Avatar answered Sep 19 '22 13:09

SimeonJM