API Contracts and Schema Design Questions
Defining the interface contract between producers and consumers: request/response payload shapes, data models, field-level validation, nullability, and enum/typing decisions (including safely evolving an enum's allowed values without breaking clients). Covers contract-first design with OpenAPI and JSON Schema (authoring specs, generating SDKs and mock servers, catching breaking changes in CI), mapping internal domain models to external DTOs as both evolve independently, and designing a stable error-response contract (structured error codes, correlation IDs, retryable classification). Also covers the leadership and behavioral practice of establishing and governing contract standards across teams. The contract is the durable artifact clients depend on.
What schema and data-contract decisions matter most for a multi-tenant API platform where each tenant can have its own response-shaping rules and audit requirements? Consider shared-versus-per-tenant fields, versioning implications, and audit metadata in the payload, and explain how these choices keep the platform maintainable as the tenant count grows.
Sample Answer
The central decision is where tenant-specific variation lives in the schema: as a shared response shape with tenant-scoped VALUES, or as genuinely different response shapes per tenant. Nearly always, the former is safer and more maintainable, even when it feels like it under-serves a tenant's specific customization request.
Shared fields versus per-tenant fields
Keep the CORE response schema identical across every tenant (the same field names, same types, same required/optional structure), and let tenant-specific behavior express itself through VALUES within that shared shape (a tenant's configured response-shaping RULES determine which optional fields are populated, not a fundamentally different schema per tenant). The alternative, letting each tenant effectively define its own response shape, means every client integration and every internal consumer has to branch on "which tenant's shape am I looking at," which multiplies the number of contracts you are actually maintaining by the number of tenants.
Versioning implications
A schema change now has to be evaluated against every tenant's configuration, not just a single global consumer base: an additive field is still safe, but ANY validation you'd normally treat as safe to tighten (making an optional field required, for instance) needs to be checked against every tenant's current configuration, since a tenant relying on the old, looser behavior would otherwise break silently. This argues for being especially conservative about ever narrowing the contract once tenants are live against it.
Audit metadata in the payload
Include a lightweight audit envelope on every response, not bolted on separately: a tenant_id, and where relevant a policy_version field showing which version of that tenant's response-shaping configuration produced this specific response. This turns "which rule produced this shape for this tenant" from a support-ticket investigation into something visible directly in the response the client already has.
Worked example
Tenant A configures the platform to include a computed risk_score field on order responses; Tenant B does not use that feature at all. The CONTRACT for both tenants is identical: the schema declares risk_score as an optional field, present when a tenant's configuration enables it and absent otherwise, never a schema difference between "Tenant A's order shape" and "Tenant B's order shape." A client library written once against this one contract works correctly for every tenant without needing tenant-specific parsing logic.
Trade-offs and pitfalls
The tempting shortcut, letting a tenant fully customize their own response shape (their own field names, their own structure) to satisfy an early enterprise customer's specific request, becomes an ongoing maintenance and versioning liability the moment a second tenant asks for something similar but not identical: now there are effectively N contracts to keep backward compatible instead of one. The shared-shape-with-tenant-scoped-values pattern costs some flexibility up front (a tenant genuinely cannot get a schema shape no other tenant has) but is what keeps the platform's contract, and its evolution story, tractable as tenant count grows into the thousands.
Walk me through a time you helped your team improve API or data-model consistency by introducing a review practice, template, or standard. How did you get buy-in, and what measurable outcome showed the change was worth it?
Sample Answer
The strongest version of this story treats "getting buy-in" as its own real problem to solve, not an afterthought after the standard was written: a review checklist or template that nobody asked for and that adds friction to every pull request will be quietly ignored, no matter how sound its content is, unless the people adopting it were part of shaping it or can see a concrete problem it actually prevented.
What a strong answer walks through
The recurring problem that motivated the standard. Name a specific, repeated pain point (three separate incidents where a field was renamed without warning, or a recurring pattern of inconsistent error shapes across services making client-side error handling brittle), not an abstract desire for "more consistency."
How you got buy-in, specifically. Did you pilot the template on your own team first and bring results, not just a proposal, to a wider forum? Did you involve the engineers who would actually use it in drafting it, so it reflected real workflow rather than an ideal imposed from outside? Buy-in earned through a concrete, already-demonstrated win is far more durable than buy-in secured by a mandate from above.
The measurable outcome. A credible answer names something you could actually point to: a drop in a specific class of production incident, a measured reduction in review-comment cycles for API design discussions, or an increase in some adoption metric (percentage of new endpoints using the reviewed template) tracked over a real time window, not a vague "things got better."
Worked example shape
"We had three separate incidents in one quarter where a field was silently renamed or retyped in an API response, each caught only after a client broke in production. I proposed a lightweight schema-change checklist as part of the pull request template, but rather than mandating it top-down, I piloted it on my own team's PRs for a month first, tracking how many schema-affecting changes it actually caught before merge. It caught two would-be breaking changes in that pilot month alone. I brought that concrete result, not just the proposal, to the broader engineering review, and adoption followed because people could see it had already prevented two real incidents rather than being a hypothetical improvement. Six months after wider rollout, breaking-change incidents traced to unreviewed schema changes dropped from three in the prior quarter to zero."
Trade-offs and pitfalls
A common weak point is describing the STANDARD in detail while glossing over how buy-in was actually secured, which is usually the harder and more interesting half of this story; a checklist's content is rarely the reason adoption succeeds or fails. Another common weak spot: an outcome metric that is really just "adoption happened" rather than a downstream result (fewer incidents, faster reviews) the standard was actually meant to produce; adoption is a leading indicator, not the outcome itself.
How do you lead API and schema governance across multiple engineering teams without becoming a bottleneck? Describe the standards, review rituals, exception process, and coaching mechanisms you would put in place so teams can move quickly while still protecting contract quality and data integrity.
Sample Answer
The mechanism that actually scales is making the RIGHT PATH the fast path: most schema changes should be able to pass through lightweight, automated checks with no human review bottleneck at all, reserving deliberate human review for the genuinely risky category of changes, and building a clear, fast exception process for the inevitable case that does not fit the standard.
Standards
Write down, concretely, what counts as additive (safe, no review needed beyond automated checks) versus what needs review (removing or retyping a field, tightening a validation rule, anything that could break an existing consumer). Vague standards ("use good judgment") do not scale past a handful of teams; specific, automatable rules do.
Review rituals
Reserve actual human review time for the standard's genuinely risky category, not for every schema change. A short, regular forum (a 30-minute weekly API-design review, not a per-PR gate) where teams bring proposed breaking changes or genuinely novel contract designs keeps the review load proportional to actual risk instead of proportional to total change volume.
The exception process
Every governance model eventually meets a team with a legitimate reason to deviate (a genuine deadline, a design the standard did not anticipate). The exception process needs to be fast and lightweight, or teams will route around the standard entirely rather than use it; a same-day escalation path to a small, named decision-making group, with a requirement to document the exception and revisit it later, keeps the standard's credibility intact without becoming an unconditional blocker.
Coaching mechanisms
Governance that only shows up as a gate at review time teaches people to satisfy the gate, not to internalize the underlying judgment. Pairing the standard with office hours, a small set of worked examples showing WHY a rule exists (not just what it says), and reviewing an early draft with a team before their PR is nearly done all shift the standard from "the thing that blocks my merge" to "something that helped me design this well before I'd invested a week in a shape that needed to change."
Worked example
An organization adopts an automated OpenAPI-diff check as the default gate: additive changes merge with zero human involvement, and the CI (continuous integration) check specifically flags anything it classifies as breaking, routing that PR to a lightweight, asynchronous review queue rather than a scheduled meeting. A team proposing a genuine breaking change (removing a deprecated field two quarters after announcing the deprecation) posts it to the weekly review forum with the automated diff attached; the forum approves it in five minutes because the actual analysis (is this really safe, has the deprecation window passed) was mostly done automatically already, and the meeting exists to catch judgment calls the automation cannot make, not to re-derive facts the CI check already established.
Trade-offs and pitfalls
The classic failure mode is a governance model that reviews everything with equal weight, which either becomes a bottleneck teams learn to route around (shipping through side channels, or simply not asking) or burns out the reviewers, who end up rubber-stamping routine changes because there is too much volume to give genuinely risky ones real attention. The other common failure: an exception process so slow or so poorly documented that teams stop using it and just break the rule quietly instead, which is worse than either following it or having a visible, tracked exception.
Write a minimal OpenAPI 3.1 specification (YAML) for a POST /orders endpoint on an e-commerce service. Include the request body schema (items: an array of objects with product_id and quantity), a 201 success response schema (order_id, total_amount), 400 and 401 error responses, and an example request and response embedded in the spec.
Sample Answer
The spec needs a request body schema for the array of order items, a 201 response schema for the created order, and explicit 400 and 401 error responses, each with an embedded example so a reader can see the exact shape without inferring it from the schema alone.
The specification
openapi: 3.1.0
info:
title: Orders API
version: "1.0.0"
paths:
/orders:
post:
operationId: createOrder
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [items]
properties:
items:
type: array
minItems: 1
items:
type: object
required: [product_id, quantity]
properties:
product_id:
type: string
quantity:
type: integer
minimum: 1
example:
items:
- product_id: "sku_1001"
quantity: 2
- product_id: "sku_2044"
quantity: 1
responses:
"201":
description: Order created
content:
application/json:
schema:
type: object
required: [order_id, total_amount]
properties:
order_id:
type: string
total_amount:
type: number
example:
order_id: "ord_7f3a"
total_amount: 64.50
"400":
description: Validation error
content:
application/json:
schema:
type: object
required: [error_code, message]
properties:
error_code:
type: string
message:
type: string
example:
error_code: "invalid_quantity"
message: "quantity must be at least 1"
"401":
description: Missing or invalid credentials
content:
application/json:
schema:
type: object
properties:
error_code:
type: string
example:
error_code: "unauthorized"
This document was parsed and structurally checked with a YAML parser: it parses cleanly as valid YAML, declares openapi: 3.1.0, defines the /orders path with the post operation described above, and every example object matches the shape its sibling schema declares (the 201 example has both order_id and total_amount, matching the required list; the 400 example has both error_code and message).
Design decisions worth calling out
itemsrequiresminItems: 1, so an order with zero line items is rejected at the schema level rather than reaching business logic.quantityhasminimum: 1, catching a zero-or-negative quantity the same way, at the contract layer.- The 400 response has a structured shape (
error_codeplusmessage), not a bare string, so a client can branch onerror_codeprogrammatically instead of pattern-matching on human-readable text.
Trade-offs and pitfalls
Keeping this spec minimal (one endpoint, three responses) makes it easy to read in an interview or a code review, but a production version would need to decide, and document, what OTHER error shapes exist (a 404 if referencing a nonexistent product_id, a 409 for a stock conflict) so the response schema doesn't quietly grow undocumented shapes over time as edge cases get patched in. A second real trade-off: embedding literal examples directly in the spec (as done here) is excellent for readability and for generating realistic mocks, but every example needs to be kept in sync with the schema by hand or by a linter; an example that drifts from its own schema is worse than no example, because it actively misleads a reader.
Write a JSON Schema (draft 2020-12 or later) for a POST endpoint /v1/apps/{app_id}/events that accepts an event payload with properties: eventType (enum), timestamp (ISO 8601 string), actor (object with id and type), metadata (optional object with string values), and items (array of objects with id and quantity). Include validation rules, required fields, and example success and validation-error responses.
Sample Answer
The schema needs five things: a type constraint on every field, an enum for eventType so only known event kinds validate, a format constraint on timestamp, an object shape for actor with its own required sub-fields, and an array shape for items with per-item structure. Below is a complete, valid JSON Schema (draft 2020-12) for the event.
The schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://api.example.com/schemas/app-event.json",
"title": "AppEvent",
"type": "object",
"properties": {
"eventType": {
"type": "string",
"enum": ["item_created", "item_updated", "item_deleted"]
},
"timestamp": {
"type": "string",
"format": "date-time"
},
"actor": {
"type": "object",
"properties": {
"id": { "type": "string" },
"type": { "type": "string", "enum": ["user", "service"] }
},
"required": ["id", "type"],
"additionalProperties": false
},
"metadata": {
"type": "object",
"additionalProperties": { "type": "string" }
},
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": { "type": "string" },
"quantity": { "type": "integer", "minimum": 1 }
},
"required": ["id", "quantity"],
"additionalProperties": false
},
"minItems": 1
}
},
"required": ["eventType", "timestamp", "actor", "items"],
"additionalProperties": false
}
Design decisions worth calling out
metadatais genuinely optional (absent fromrequired), and itsadditionalPropertiesconstraint restricts VALUES to strings without naming the specific keys, which keeps the schema honest about what "optional object with string values" means without over-constraining future keys.itemsrequires at least one entry (minItems: 1): an event with an empty items array is treated as invalid here, a deliberate validation rule rather than an oversight.additionalProperties: falseon the top level and on each nested object rejects unrecognized fields, which catches client typos early but is itself a compatibility decision: it means adding a genuinely new field later requires updating this schema in lockstep with any producer that starts sending it, rather than silently tolerating it.
Worked example: validating example payloads against this schema
A valid event:
{
"eventType": "item_created",
"timestamp": "2026-07-28T12:00:00Z",
"actor": { "id": "usr_123", "type": "user" },
"metadata": { "source": "mobile_app" },
"items": [{ "id": "sku_1", "quantity": 2 }]
}
This validates cleanly: every required field is present, eventType is one of the three enum values, and items has one well-formed entry.
An invalid event (empty items):
{
"eventType": "item_created",
"timestamp": "2026-07-28T12:00:00Z",
"actor": { "id": "usr_123", "type": "user" },
"items": []
}
This is rejected, specifically because items has zero entries and the schema's minItems: 1 constraint requires at least one. Both examples above were run against this exact schema with a JSON Schema validator; the valid example passed and the empty-items example failed with the minItems violation, confirming the schema behaves as written.
Example success response: {"event_id": "evt_9a1b", "accepted": true} (HTTP 201). Example validation-error response: {"error_code": "validation_error", "message": "items must contain at least 1 item"} (HTTP 400).
Trade-offs and pitfalls
additionalProperties: false is a real trade-off, not a free safety net: it makes typos in client requests fail loudly (good), but it also means the schema and every producer must be updated together the moment a genuinely new, backward-compatible field needs to be added, which is slower than a looser schema that simply ignores unknown fields. Choosing strict validation here is defensible for an internal event contract with few, coordinated producers; a public-facing schema with many independent producers might reasonably relax this to allow additive fields to pass through unvalidated.
Unlock Full Question Bank
Get access to all 15 API Contracts and Schema Design interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.