Client vs Server – Client Side or Server Side Calculations?

clientserver

I was wondering about client side vs server side calculations regarding websites that provide some convenience type service. For example, an online website where you input a certain date and the website tells you how many days between today and that date. Or a website that tells you steps to solve the inputted math equation. Do these types of websites warrant server side calculations of any kind?

Best Answer

There is no simple answer to this question. There are many different software architecture/deployment strategies that can achieve this. It all depends on how complex your application is and how complex can it become some day.

Let's start with a simple MVC type of architecture. Here you treat your client side code as mainly a view, your server as a controller, and transfer the model (i.e., your data) between the view and the controller. This allows you to keep all the logic in one place and serve multiple views (e.g., phone apps, websites, or even text prompt interfaces!). So far so good.

However, when you set out to do this, you will find yourself defining multiple MVCs inside your view itself. Delegating every single controller to the server side is going to complicate your design and/or degrade the performance (do you do 2+2 on the server side or the client side?). So at some point you have to stop building controllers on the server side. The art is in knowing where to stop.

Three simple guidelines can help. First, if a calculation/algorithm is a constant of the world and unrelated to the "business" logic of the application then you can generally code it on the client side. Second, you may not want to do so if the algorithm is complex (needs a lot of data from other/your own servers, needs a lot of CPU that your typical user won't have etc.). Third, you may not want to ship logic on client side that gives you a proprietary edge for the fear of someone reverse engineering your logic.

Let's take the equation breakdown problem. It is non trivial, can change for there are multiple ways to solve a given problem (including trivial step additions to simplify existing steps), and costly to build (so you may not want someone to steal your hard earned algorithm).

Related Topic