Rishi
2 min readSep 24, 2023

How much logic do you want to keep in the backend or frontend?

Developers always have a question, especially when building scalable applications: where to keep business logic? Should everything be in the backend, everything in the frontend, or a mix of both for a better user experience, along with security and scalability?

Why keep everything in the frontend:
It helps make the user experience faster and smoother because there aren’t many backend calls happening. However, it comes with significant security risks and creates a slower experience as data starts to increase.

Why keep everything in the Backend:
It helps developers control everything and allows them to make changes at any time without system downtime or user intervention. However, it adds delays in backend logic execution and sends responses from the backend to the frontend.

So, a safer bet is to keep some in the frontend and some in the backend.
But how much?

It boils down to a system design question:

How much data and logic do you want to keep in the frontend and backend?

There are a few examples that can help you understand and design your system accordingly.

For instance, let’s say you want to provide sorting and searching features. Both can be done exclusively in the backend or frontend, but it’s not a correct design approach. The recommendation is, if you have a smaller dataset, perhaps around 2000 records, to do everything in the frontend. However, if you have a larger dataset, consider using both frontend and backend, such as providing server-side search and pagination. It may not be as fast as the frontend alone, but it will scale for any number of records.

Another example is when you need to write logic that requires a highly secure dataset. As a developer, you have both options: you can bring that data and write it in the frontend, but it may expose the secure data. Alternatively, you can write everything in the backend and send the final result to the frontend. In the latter case, the secure data remains unknown to anyone outside.

The best design is to strike a balance between user experience and data security.

What has been your experience with this?

Rishi
Rishi

Written by Rishi

A passionate and business oriented technology leader with over 15+ of experience. I love to build products and grow to millions.

No responses yet