LearnThatStack Ace your next interview
API Design · question
Question 40 of 92

How do you handle API documentation and ensure it stays up-to-date?

intermediate Pro
← All API Design questions

The full answer covers the core mechanics, when this pattern wins, and the trade-offs interviewers most often probe. It includes a code sample. Read it once at your own pace, then try to recall the structure from memory before the interview. Pro also includes this question's interview lens - the likely follow-up probes and what you can say in the room.

Full answer + code samples + AI explanations

Unlock to read the complete answer for this premium question.

Guided practice for API Design One question at a time. Answer out loud, get graded, see what you missed.
Related concept

Documentation: the docs come from the spec, not a hand-written copy

Hand-written docs are a second copy of what the code does, and copies go out of date. A spec that generates the reference, clients and checks cannot go out of date.

For this question · chapters 1 and 2 of 3

1/3 Two copies, and only one runs
documentationTwo copies, and only one runsthe page nobody checkswrong on the page3checks that read it0unchanged. still nonewhat runs/v1/users/{id}v1.5iduuidemailstringnamestringcreated_attimestamprenamedavatar_urlurlremoveddisplay_namestringnewwhat they readtyped in by handdocs.acme.com/usersstill v1.4iduuidemailstringnamestringcreatedtimestampwrong nameavatar_urlurlstill listeddisplay_namenot listedwhat runs on that commitunit412 passintegration38 passdeployv1.5 is livethe reference pagenothing runs itsomeone else's codeacme-checkoutwritten on day 9every line of it came off the pagePATCH /v1/users/8842avatar_url: ...400 unknown field: avatar_urlGET /v1/users/8842read user.createdundefinedno error at allit reaches you as ticket 4471one call failed loudly. the other returned undefined and shipped
documentationTwo copies, and only one runswrong on the page3checks that read it0still nonewhat runs/v1/users/{id}v1.5emailcreated_atrenamedavatar_urlremoveddisplay_namenewwhat they readtyped in by handdocs.acme.com/usersstill v1.4emailcreatedwrong nameavatar_urlstill listeddisplay_namenot listed3 checks passthe page, no checksomeone else's codeacme-checkoutwritten on day 9PATCH avatar_url400 unknown fieldGET user.createdundefined

Two copies, and only one runs

  1. The same API shape is written down twice, but only the copy in the handler code runs. A person typed the reference page from that code some time ago. Nothing links the reference page to the handler. Every documentation problem you have ever had starts with these two unlinked copies.
  2. No line of code refers to the hand-written docs page. So release v1.5 changes only the handler. The handler renames the field created to created_at, removes avatar_url, and adds display_name. The docs page stays the same. So the page is now wrong in three places: one field renamed, one field removed, and one new field it never mentions.
  3. The commit that made the docs page wrong passes the unit tests and the integration tests. The deploy then ships v1.5 on that same commit. There is no fourth check for the docs page, so zero checks read it. Nothing you own reads that page.
  4. A partner has only the hand-written docs page, so the partner trusts it. Nine days later, the partner's integration sends avatar_url and reads the created field. The partner never learns that display_name exists. Now someone who does not work for you is doing your testing.
  5. Two calls fail in two different ways, and the quiet failure is worse. The write gets a 400 response that names the field, so the bug gets fixed within an hour. The read returns undefined with no error, so the code that makes that call ships. Both failures reach you as a support ticket, the slowest way you have to find a bug.
Chapter 1 · step 1 of 5

The same API shape is written down twice, but only the copy in the handler code runs. A person typed the reference page from that code some time ago. Nothing links the reference page to the handler. Every documentation problem you have ever had starts with these two unlinked copies.

1 of 5 Use ← → or swipe See the concept: all 3 chapters in it

© LearnThatStack - diagrams may not be republished without permission.

Want a quick review of the fundamentals? See the API Design cheatsheet.

← Back to all API Design questions
Pro · $10/mo

74 of 92 API Design answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime