Where to run complex algorithms? Sever side or Client side?


I am trying to develop an social networking android application which contains huge database of users. I am very new to Android App development and trying to understand the concepts behind the app development. I am using following technology :

1) MYSQL + PHP (RESTful Web Services) 2) Android Studio (Java)

In the application, I have to run some complex algorithms for ranking users collecting data from different tables from database stored in cloud server.

My question is "where to run this algorithms?". Should I write code in PHP to make the algorithms run in server side and then send this data to client (or) Should I write the code in JAVA (Android Studio) using data collected from server.

How will the performance of my app differs in both cases?

Edit : Thanks for all your responses.

I have idea on Async Tasks and Multi Threading.

This doubt came to me as ranking is common for all my users, there is a difference. If I put raking algorithm in server side, even though the results are same for all users, the same algorithm has to run for several times (say if there are 10000 users, the same algorithm runs for 10000 times on server side). But if I do put in client side, I may over come this. But need expert solution on this.

Show source
| java   | php   | android   | mysql   | performance   2017-01-03 10:01 6 Answers

Answers ( 6 )

  1. 2017-01-03 10:01

    Run algorithms on server for best results otherwise it will degrade performance of your application.

    While running long computations on application, the application get freezed and ultimately gets crashed.

  2. 2017-01-03 10:01

    It is always recommended to run algorithms on the server side as putting your business logic in client side application create threat for the security of the application. On the other, it decrease the performance of the application due to long running task, not acceptable for good user experience and if later on you create for multiple platform e.g web, iOS etc. you have to write the same logic again Totally wastage right ? Put to algorithms in server side and call use Rest APIs.

  3. 2017-01-03 10:01

    For your situation, run it on the server side, then you neednot to trans all the date to you client but with the sample result. This not only reduce the bandwidth and also raise the user feeling. In the server side, run it on the bachground to make the request can response in a very few time. When computing finish, refresh the client status. You also use queue to store the calculate tasks, do the calculation each time a few.

  4. 2017-01-03 10:01

    This question may be somewhat opinion-based, but I think there are a few design rules which you can use as guidelines:

    • When a computation needs lots of data, do it as close to the data as possible. This is often on the database itself. Transferring large amounts of data is resource-intensive and not a good idea over a slow link (e.g. between the server and the client).
    • If the computation needs to deal with private data, the bounds how far the data can travel for computation purposes is also set. Not displaying the data in the client is not protection of private data!
    • When a computation is resource-intensive can be cached, is valid for many users, and maybe even computable in advance, do it on the server and cache the result.
    • If the computation needs little data but is computation-intensive, ask yourself if the server can scale well enough to sustain all clients making concurrent requests. Having the client compute such operations can lead to a much more stable performance overall, despite the limited resources of the client (which nowadays is still pretty usable!).
  5. 2017-01-03 10:01

    It really depends on what you mean by Complex.

    If Complex means lots of maths and calculations etc on not a lot of data.

    I might do this on the client. Moving compute-hungry processes off to your clients could greatly improve your overall responsiveness. You are effectively using your clients as a compute engine and that can often be a good thing.

    If Complex means lots of data being analysed with little actual maths involved.

    You should keep the distance large amounts of data moves to a minimum. Handle it as close to your DB server as possible. If you can, put some of it in the database itself.

  6. 2017-01-03 10:01

    We are also developing similar kind of web app using Java Springs. To perform ranking of users based on the performance metrics, you have run it on back-end (php) as it effects your application performance. That said, it is advisable if you know that you have run these algorithms periodically (say monthly/weekly/daily) then it is better to a assign a cron job which performs the operations and stores the results without having to interfere with your application.

◀ Go back