In a web app with a React frontend and an API, where should input validation happen, and why?
What the interviewer wants to hear
- Client-side validation is for fast feedback and better UX
- Server-side validation is required because clients can be bypassed
- Database constraints are the last line of defense
- Sharing one schema keeps rules consistent across tiers
- Return clear field-level errors the UI can display
Model answer
I validate in three places, each for a different reason. In the browser I validate for user experience, so people see mistakes immediately without a round trip. On the server I validate every request again, because anyone can skip the form and call the API with curl or a script; the server is the real security boundary. Finally, the database has constraints like NOT NULL, UNIQUE, foreign keys and CHECK rules, which protect data even if a bug slips through the application code. In a TypeScript project I like to define one schema, for example with Zod, and use it in both the form and the API handler, so limits and messages never drift. When validation fails the API returns a 400 or 422 with field-level errors, and the form shows each message next to the right input.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Full Stack Developer questions
- What happens, step by step, when a user types your app URL into the browser and presses Enter?
- Design the REST API endpoints for a simple blog with posts and comments. What URLs, methods and status codes would you use?
- What is the difference between authentication and authorization? Give an example from a web app.
- You are starting a new e-commerce app. Would you choose a SQL or a NoSQL database, and why?
- Explain client-side rendering, server-side rendering and static site generation. When would you use each?
- A page loads data from your API. How do you handle loading, empty and error states so users are never left confused?
- How do you manage configuration and secrets across development, staging and production for a full-stack app?
- How would you explain a database index to a junior developer, and how do you decide which columns to index?
- Describe the Git and code review workflow you follow when building a feature on a team.