awesome-everything RU
↑ Back to the climb

APIs

Status codes: multiple-choice review

Crux Multiple-choice synthesis across the status-code unit: picking the right code per scenario, the 4xx/5xx ownership split, Retry-After, and the idempotency trap.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 13 min

Six scenarios, each one a status code you choose under real conditions. Not “what does 404 mean” — but which code makes the caches, dashboards, and retry loops downstream do the right thing.

Goal

Confirm you can pick the correct status for a given situation and defend it — connecting the 2xx nuances, the 4xx vocabulary, the 4xx/5xx ownership split, and the retry/idempotency rules the unit built toward.

Quiz

A POST /orders endpoint validates the order, writes it to the DB synchronously, and the resource now exists. What status, and what else must the response carry?

Quiz

An endpoint accepts a request, enqueues it to Kafka, and returns immediately; a worker processes it seconds later. What status is honest?

Quiz

A request arrives with valid JSON, all required fields present and well-typed, but quantity is -3 — a business-rule violation. Which class and code fit best?

Quiz

A reverse proxy forwards a request to an upstream service, which is up but returns a garbled, truncated response the proxy cannot parse. What status does the proxy return to the client?

Quiz

A client is rate-limited and the server returns 429 with `Retry-After: 30`. The client also runs generic exponential backoff with jitter. What should it do?

Quiz

A non-idempotent POST /charge times out as 504 with no idempotency key sent. The charge may or may not have run. What is the correct client behaviour?

Recap

The through-line: the first digit is a machine instruction, and the precise sub-code carries real contract information. 2xx splits into 201 (+Location) for a synchronous create, 202 for accepted-but-async, 204 for deliberately empty success. The 4xx vocabulary tells the client what to fix — 400 (syntax) vs 422 (values) vs 409 (state). The 5xx sub-codes attribute blame — 500 your bug, 502 a bad upstream, 503 intentional unavailability, 504 a timeout where the work may secretly have completed. Retry 5xx and 429, honour Retry-After before backing off, and never blindly retry a non-idempotent request after a timeout — reach for an idempotency key instead.

Continue the climb ↑Status codes: free-recall review
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources2
expand
  1. 01
  2. 02

Trademarks belong to their respective owners. Editorial reference only.