Highlights

Contents

Part VII
07

Case study: one API end to end

We assemble the public request and its delayed consequences. A useful API explains what is known after each response and what the client should do next. We will trace a correction, its uncertain reply, downstream publication, and the limits that keep the whole flow operable.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Resource modeling andHTTP methods2Pagination, filtering andsorting3Versioning andidempotency keys4Auth, validation and APIgateway5Monoliths andmicroservices6Sagas and distributedtransactions7Case study: one API endto end

#Section 28One accepted correction has several identities

A scorer opens m7 at revision 7 and sends correction K conditional on that revision. The public request contains caller identity, resource identity, command identity, and observed resource version. Each answers a different question. A service name or connection identifier cannot replace any of them.

The gateway admits the bounded request and forwards trusted caller context. The score service verifies the scorer assignment, then executes a local transaction. It inserts scoped command K, checks revision 7, updates the score to revision 8, stores K’s outcome, and writes event E to the outbox. A conflicting use of K is rejected; a duplicate with the same meaning retrieves K’s stored outcome.

FOUR IDENTITIES, FOUR JOBS: CALLER, RESOURCE, COMMAND, OBSERVATIONFOUR IDENTITIES, FOUR JOBS: CALLER, RESOURCE, COMMAND, OBSERVATIONcallerscorer anamay she?resourcematch m7who owns it?commandkey Kis this a retry?observationsaw rev 7is it still true?event E names the committed correction (rev 7 → 8)
Figure 10.33Illustrative command K and event E remain stable while state changes from revision 7 to 8.

Read the response precisely

A successful response proves that the authoritative correction committed under the selected database contract. It does not prove every replica, cache, or subscriber has revision 8. Heron can return the committed revision and a suitable read link, letting the client request an observation at least as new as its command result where supported. Derived views can report their own applied revision.

If the reply is lost, the scorer retries K without changing the payload or inventing another key. The service returns K’s result at revision 8 even if another command has since created revision 9. As promised in Part III, operation recovery and current-state observation are separate. A later fresh read can describe revision 9 without rewriting K’s history.

#Section 29A failure matrix is more useful than a generic retry flag

The same HTTP timeout can occur before admission, during execution, or after commit. A failure matrix lists observable states, what can already have happened, and the safe next action. It turns ‘retry on error’ into a contract that a client can implement.

Observation Possible authoritative state Next action
Shape rejected No command effect Correct input
Permission refused No permitted effect Resolve permission
Capacity refused before acceptance No accepted work Retry within policy
Version conflict recorded Earlier observation is stale Read and reconcile
Reply lost K may have committed Recover using K
Derived view behind Score can already be current Read suitable authority or wait
THE RIGHT RECOVERY DEPENDS ON WHICH BOUNDARY THE FAILURE CROSSEDTHE RIGHT RECOVERY DEPENDS ON WHICH BOUNDARY THE FAILURE CROSSEDwhat happenedwhat is knownnext actionbad shapeno effectfix the inputconflictold observationre-read, reconcilereply losteffect possiblerecover with Kview behindeffect committedwait or read authorityretry is not one universal operation
Figure 10.34An observed failure determines a recovery path only when the acceptance boundary is known.

The server should not claim no effect after an uncertain database commit. It can expose a pending operation or require recovery through the stable key. Conversely, clients should not keep retrying a deterministic invalid request. Classifying refusal, conflict, uncertain acceptance, and delayed observation reduces wasted work and accidental duplicate commands.

Error responses are versioned too

A client can depend on a machine-readable error code, the availability of a recovery link, and whether a retry retains identity. Changing a version-conflict error into an automatic overwrite changes semantics even if the success JSON stays the same. Test error and timeout flows in the contract suite, not just successful responses.

#Section 30Count the contract’s retained and induced work

K’s durable record enables recovery but consumes storage. Assume, purely for this sizing exercise, every peak-rate request is a command and that peak lasts the full illustrative day. At 1,000 commands per second, the day contains 86,400,000 command records. At an assumed 300 bytes per record, that is 25,920,000,000 payload bytes before indexes, replication, and cleanup overhead. This deliberately differs from Heron’s average workload to test a stated worst-case scenario.

B=λTbB = \lambda T b

Read this as retained payload bytes BB equal command rate λ\lambda times retained seconds TT times bytes per command record bb. Each input is an explicit assumption. Increase retention for long-lived retries and storage increases proportionally. A shorter retention policy must also shorten the supported recovery promise or preserve a smaller tombstone proving that the effect already happened.

1,000 COMMANDS/S × 86,400 S × 300 B = 25,920,000,000 B OF COMMAND RECORDS1,000 COMMANDS/S × 86,400 S × 300 B = 25,920,000,000 B OF COMMAND RECORDSone day at peak: 86,400,000 records25.92 GBB = λ × T × b: longer retry support means proportionally more storageindexes, replicas and cleanup are extra
Figure 10.35Illustrative full-day peak scenario. Payload storage and recovery support share a retention decision.

Count induced downstream work separately. A 20-command batch with five dependent reads per command creates 100 reads. A local rate limit on HTTP requests cannot see that amplification unless the operation has a cost rule. A subscriber that retries every failed event adds load beyond the original command rate. Capacity checks need units that match the resource they protect.

#Section 31Defend the complete API without naming products

At the whiteboard, start with the user’s intended operation and the invariant it changes. Draw the authority, the local transaction, the recovery identity, and any delayed view. Only then select protocols and deployment boundaries. That explanation works for a new domain because it follows state and uncertainty rather than memorized boxes.

Heron’s correction contract supports an atomic resource precondition and durable command recovery. Its service boundary keeps match state and event intent local. The outbox publishes E to independently progressing readers. Admission limits bound induced work, and the client distinguishes a committed correction from delayed media and search updates. Each component now has an observable job.

A REQUEST KEEPS ITS MEANING FROM INTENTION TO RECOVERABLE RESULTA REQUEST KEEPS ITS MEANING FROM INTENTION TO RECOVERABLE RESULTintentionK, saw rev 7authorityassigned scoreratomic effectrev 8 + outbox Erecoverable resultK → stored replyderived views can lag behind the committed intention
Figure 10.36The complete contract connects intention, authority, effect, observation, and recovery.

This chapter does not decide every token format or rate-limiting algorithm. Security and rate limiting have their own chapters because their details change the trust and admission guarantees. The reliability chapter next follows the same request through dependency failure and recovery budgets. Carry K, its authoritative result, and its retained progress into that discussion.