← Integrations without dramaIntegrations without drama · #3

Frontend or backend? Where each rule belongs

If a rule only lives in the form, webhooks, APIs, and imports skip it. A simple way to decide where each change belongs.

It's a question almost every team runs into. A change comes in ("the phone number must be valid", "no bookings on Sundays") and someone asks: does this go in the frontend or the backend?

The quick answer is usually "in the form, it's faster". And it works… until the data arrives some other way.

Your screen isn't the only way in

As soon as there are integrations, data comes in through many paths that never touch your form:

  • Webhooks from a CRM, an ad platform, or WhatsApp.
  • The API used by a mobile app, another team, or a partner.
  • Imports from CSV files, migration scripts, and nightly jobs.
  • Anyone who opens the browser console and calls your API directly.

Every one of those paths skips the form's validation. If it only lives in the frontend, it's not a rule. It's a suggestion.

A simple rule of thumb

Before deciding where a change goes, ask yourself: does this help the user, or does it protect the data?

  • Helps the user → frontend. Flagging an empty field right away, formatting a phone number while it's typed, disabling a button. It improves the experience, but nothing breaks if it fails.
  • Protects the data → backend. Required formats, permissions, prices, limits, duplicates. If it fails, junk gets into the system or someone does something they shouldn't.
  • Both → in both places. An email can be checked in the frontend for quick feedback, but the backend always checks it again.

The hard part: not duplicating logic

Validating in both places has a catch: writing the same rule twice and watching the two drift apart over time. The frontend accepts a phone number the backend rejects, and whoever fills in the form gets an error they can't make sense of.

  • One source of truth: the business rule lives in the backend. The frontend only runs a light version to help.
  • Share the schema: if both sides use JavaScript or TypeScript, a schema library (Zod, Yup, JSON Schema…) lets you use the same definition on both.
  • Errors you can display: have the backend return which field failed and why, not a generic 500.
{ "error": "validation", "field": "phone", "message": "The phone number must include the country code" }
Watch out for calculations: if the frontend works out a price, a discount, or a score and the backend saves it as is, anyone can send whatever number they like. The backend recalculates; the frontend only displays.

Checklist before deciding where a change goes

  • Which paths can this data come through, besides my screen?
  • If someone skips the frontend, what breaks?
  • Is it a help for the user or a business rule?
  • Where does the official version of the rule live?
  • Does the backend return errors the frontend can show clearly?

The frontend makes it easy to do it right. The backend makes it impossible to do it wrong.

This article is part of Integrations without drama: a new pattern every week.