We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Data Governance Compliance
Free preview: the first 2 parts of this 7-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Data Governance Compliance
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
Your API accepts a JSON body to create a user. The frontend team sends { "name": "Roni", "email": "roni@example.com", "age": 28 }. Works perfectly. Then a mobile developer sends { "name": "", "email": "not-an-email", "age": "twenty-eight" }. Your API crashes because it tried to do math on the string "twenty-eight."
You could add individual checks: if (typeof age !== 'number') throw error. But with 50 API endpoints, each accepting 5 to 15 fields, that is hundreds of manual checks. Miss one, and bad data gets through. Worse, your TypeScript types say age: number but nothing at runtime enforces it. The types lie.
Schema validation replaces ad-hoc checks with a formal definition of what valid data looks like. You define the schema once: "name is a required non-empty string, email matches an email pattern, age is a number between 1 and 150." The validation library checks every request against it. One schema, total coverage, consistent error messages.
This is not a theoretical concern. In 2022, a fintech startup had a production incident where a partner API sent amounts as strings instead of numbers. Their TypeScript types said amount: number, but the runtime accepted whatever JSON.parse produced. The result: negative balances, incorrect transaction records, and a week of manual data cleanup. A single Zod schema would have caught it at the API boundary.
| Approach | Where Schema Lives | Strengths |
|---|---|---|
| Zod (TypeScript) | In code, alongside your types | Type inference: one schema gives you both validation AND TypeScript types |
| JSON Schema | Standalone JSON document | Language-agnostic: same schema validates in Python, Java, Go, JavaScript |
| Protobuf/ | .proto files | Binary serialization + validation + code generation for any language |
| OpenAPI | YAML/JSON API specification | Documents the API AND validates requests/responses |
| Database DDL | CREATE TABLE statements | Enforced at the storage layer, impossible to bypass from application code |
Schema validation in a typical request lifecycle:
The schema handles "is this well-formed data?" Business logic handles "is this valid for our domain?"