Overview
Curated: · Written: · Reviewed:
Working with APIs & Technical Specs
In one line
A technical spec is an executable contract at the wire boundary. Review whether it states what each side sends, accepts, retries and rejects, and whether it can change without breaking a real consumer. Reach for this check whenever an endpoint has more than one consumer or a mutation can be retried after an ambiguous failure.
Key definitions
- Safe: the client does not request a state change. It says nothing about retries or authorization.
- Idempotent: repeating the same intended request has the same intended effect. A PUT that sets a value qualifies; a POST that appends a row does not.
- Idempotency key: a client-chosen key the server stores with the first result, so a repeat returns that result instead of acting again.
- Object-level authorization: a check that this principal may act on this object, not only that the token carries a scope.
- Breaking change: any change a real consumer's code or data assumptions reject, such as a removed or renamed field, a changed type, units, requiredness, enum meaning or error semantics.
Formulas and complexity
Hmm
How it works
- The validator checks the document against OpenAPI and JSON Schema rules. It never sees a server response, so a passing run proves only that the document is well formed.
- A contract is enforced at three points: the document, the producer's response tests and each consumer's deserializer.
- A retry is safe only when the operation is idempotent or carries a key the server stores and checks against the first attempt.
- Drift enters through unknown fields, unknown enum values and numbers sent as strings. Decide per consumer whether each is tolerated or rejected.
When to use and when not to
| Situation | Do | Avoid |
|---|---|---|
| Mutation with an ambiguous timeout | Idempotency key in a shared store; same key returns stored response | Blind retry with no key |
| Large, fast-changing collection | Keyset cursor on (created_at, id) | Offset paging |
| Business failure such as a card decline | 4xx with a stable code and retryable flag | 5xx, which SDKs retry |
| Long-running import or export | 202 with a status resource; client polls to a terminal state | Treating any 2xx as done |
| Internal high-volume RPC | gRPC: binary protobuf over HTTP/2 with persistent, multiplexed connections | Browser-facing or cacheable public reads |
| Per-key rate limit | Token bucket or sliding window | Fixed window, which can admit up to twice the limit across a boundary |
Traps interviewers probe
- "The validator passed, so the server is right." Fix: validation proves only that the document is well formed. Test real responses against the schema with response-validation and consumer contract tests.
- "Retries are fine, it's a PUT." Fix: a PUT that sets a value is idempotent, but a POST that appends a transfer is not. Add an idempotency key to the POST and store its first result.
- "Adding an optional field is non-breaking." Fix: strict deserializers reject unknown properties. Jackson 2.16 with default settings fails on them, so run the change against each representative consumer before release.
- "A valid token means the caller can read it." Fix: check the object's tenant or owner against the token claims on every read. Return 404 for objects outside the caller's tenant.
- "Offset paging is fine." Fix: when rows are inserted at the head, offset pages repeat rows already shown. Use a keyset cursor with a unique tie-breaker.
Interview tips
Open with: "I'd check the contract at three points: the document, the producer's real responses and each consumer's deserializer. Then I'd walk the failure cases: timeout after commit, retry, unknown enum and an old client against the new server."
Expect these follow-ups:
- How do you add a field or enum value without breaking old clients?
- What is your retry budget, and where does the deadline come from?
- How do you stop a cross-tenant read when the token is valid?
- Why would you pick gRPC here, and what do you give up?
- How does a client know an asynchronous job has finished?
30-second answer outline:
- Name the consumers and whether the operation is safe and idempotent (5 s).
- State the wire contract: status codes, error codes with a retryable flag, typed schemas with requiredness (10 s).
- Walk one failure: timeout after commit, retry with the same key, stored response returned (10 s).
- Name the test that catches drift: response validation plus a consumer contract test (5 s).
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.