Validations & Transformations
How controllers check and reshape incoming data before it reaches business logic, why the backend must never trust the frontend, and where each step fits in the MVC flow.

Flow of MVC architecture for APIs
User using the View (Frontend Application UI) sends request to the Controller (Backend API).
Controller receives the request, deserializes data to compatible format and validates the data and convert it to model object, it also transforms the data if needed.
Controller calls service and passes the model object to the service.
Service performs the business logic and calls repository to save the data to database with model that is compatible with database.
Repository saves the data to database and returns the result to the service which is also a model that service understands.
Service returns the result to the controller with cleaned data model
Controller converts the model to serialized data and sends the response to the user with appropriate status code.
What is Validations ?
Validation is process of verifying that the data is in correct format and can be used for further processing.
The idea behind validation and transformation is all the input data received in the form of query parameters, body parameters, path parameters, headers, cookies, etc should be validated and transformed before using it for further processing so that its in correct format and can be directly used in business logic.
Example: user input value is is string of numbers only, is start with 7,8,9 and can be valid phone number.
Flow of validations:
User request data received by controller
Request is routed to appropriate controller
Controller validates the data A. if validation fails, controller responds with appropriate error message. B. if validation passes, controller calls service and repository to perform the business logic and responds with the result.
Service tries to perform the business logic and saves the data to database. A. if something goes wrong, controller responds with appropriate error message. B. if everything goes well, controller responds with the result.
Controller again validates and transforms the data before sending the response to the user.
User receives the response.
Type of validations:
Syntactical validations where data follows the format and rules.
Semantical validations where data is valid and meaningful.
Type validations where data is of expected type.
Most common validations are:
Required fields in user input data like name, email, phone, dob number are required.
Data type validations like name email, phone number are of type string and dob is of type date.
Data length / size validations like name is 50 characters long, email is 100 characters long.
Data format and pattern validations like email and phone number is in valid format.
Data range validations like dob is between 01-01-1900 to 31-12-2099.
Valid data values like given username is valid and available.
Validations are responded with 4XX error code which indicate the client error.
What is Transformations ?
Transformation is process of converting the input data into valid / expected format so that it can be used for further processing directly.
Example: user input is date which need to in format dd/mm/yyyy, so we need to convert the date into dd/mm/yyyy from dd-mm-yyyy format or other format.
Generally transformations are performed after the request validation to create the data needed before the business logic and response creation to sanitize the response.
Why and where to use Validations and Transformations ?
In any API based backend services, validations and transformations are written in Controllers
Controller are responsible for receiving the request data from the client and sending back appropriate response to the client.
Controllers validate and transform the data so that service and repository can directly use the pre-validated and transformed data and while responding no data goes outside unintentionally.
Before starting any business logic, controllers validate and transform the data in expected format.
Validations and Transformations code and logics are tied together so everything related stays in one place and easy to maintain and in case of modification or addition changes are easy to be made and debugging is easy in case of error. Validations and Transformations are written in Controllers so that they are reusable and can be used in multiple controllers.
Validations and Transformations errors are handled in Controllers and return descriptive error messages to client so that client can understand the error and fix it.
Validations and Transformations error messages are logged in the application logs so that they can be monitored and fixed in case of error and should not reveal any sensitive information like passwords, tokens, etc or internal server information.
Frontend Validations and Transformations vs Backend Validations and Transformations
Frontend and backend validations and transformations are different and should always be handled separately.
Frontend validations and transformations are done for user experience, and to make things faster and easier for the user before sending the request to the backend.
Backend validations and transformations are done for security and data integrity, which prevents the invalid and errors data to used in the applications business logic and getting saved to the database.
In some cases, frontend is not there or loosely do validations and transformations, in that case backend will get data is buggy and invalid. So backend should always strongly validate and transform the data before using it in the business logic.
Validations and transformations transformations logics are lightweight and should not be too complex, so even if they are repeated at multiple stages it does not hamper the performance heavily.
About the author
- My journey started as a Computer Engineering student with a deep curiosity about how software systems are built from the ground up. During college, I dove into web development, databases, and machine learning — shaping a strong foundation in problem-solving and software engineering. I graduated with a Grade A+ and went on to publish research on a KNN-based recommendation system I built as part of my final-year project. After college, I started out building UI dashboards integrated with Microsoft Dynamics 365, improving data visualization by 40% and cutting decision-making time by 25%. I then grew into a Full Stack role — developing a payment gateway serving 66 million users with 125,000 daily transactions, and a real-time analytics dashboard powered by Apache Kafka and Pinot that reduced query latency by 76%. Outside of work, I enjoy building personal projects — from a neighbourhood e-commerce platform to a URL shortener and a video streaming service. I'm driven by clean architecture, real-world performance, and the satisfaction of shipping systems that actually work under pressure.
Comments
Join the discussionNo comments yet. Be the first to comment.
First Principles of Backend Engineering
An in-depth article series deconstructing the core mechanics of backend systems. Moving beyond frameworks and trendy tools, this series explores the fundamental building blocks of the web—from network protocols and reverse proxies to database architecture and server security—helping you understand exactly how and why scalable systems work from the ground up.





