ContentsThe library

Designing an Interface to Call

There Are Only Two Questions Worth Asking About Any Operation, and Neither of Them Is What It Is Called

Last timeNaming the Things

Classifying every operation by whether it changes anything and by what repeating it does, why that classification decides who may retry, and what to do with the operations that fail both tests.

The two questions

An operation has a name, and the name is the least informative thing about it.

Two questions tell you nearly everything you need to know.

Does it change anything observable. If not, it is safe, and a caller may run it

freely, a proxy may cache it, and a crawler may follow it.

Does running it twice leave the state the same as running it once. If so, it is

repeatable. This is the question that matters, and it is independent of the

first: everything safe is repeatable, but plenty of things that change the

world are repeatable too.

FIG 1Common operations, classified
saferepeatablea caller may retry freelneeds a key to be repeat
read one thing1110
replace a thing entirely0110
delete a thing0110
create a thing, server c0001
add an amount to a balan0001
set a status to shipped0110
send a confirmation mess0001
The second and third columns are identical, which is the point of the lesson: repeatability is exactly the property that decides whether a caller may retry. Note the second and third rows, which change the world substantially and are still repeatable, because the state after two calls is the state after one.

Two entries on that list are worth examining. Replacing a thing entirely is

repeatable because the second call writes the same bytes over the same bytes.

Adding an amount is not, because the second call adds again, and the

difference between the two is not how dangerous they are but whether the

operation describes a destination or a movement.

Deleting is repeatable even though the second call finds nothing there. The

state afterwards is the same either way, which is all repeatability asks. The

common objection, that the second call returns a different answer, confuses the

response with the state, and the property is about the state.

Why it decides who may retry

The reason to care is the one thing every network does, which is fail to tell

you what happened.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Every Awkward Interface You Have Ever Used Was Awkward for the Same Reason, and the Reason Was Decided in the First Half Hour
  2. 02There Are Only Two Questions Worth Asking About Any Operation, and Neither of Them Is What It Is Calledyou are here
  3. 03Your Error Message Is Read by a Program First and a Human Second, and Almost Every Interface Gets That Order Backwardsopening only
  4. 04The Second Call Is Not a Mistakeopening only
  5. 05Counting From the Start Versus Remembering the Placeopening only
  6. 06A Limit Is Only Useful If Somebody Can Obey Itopening only
  7. 07Hand Back a Receipt, Not an Answeropening only
  8. 08Add, Migrate, Then Removeopening only

Read alongside