Card 08/ 09

ExerciseDifficulty: Advanced1 min

Practice: An Asynchronous Video Export API

Design the request, the 202, the status resource, a signed webhook and the receiver's checks for a video export.

Designing an asynchronous API means choosing the acceptance, the status resource, the event and the checks that make it trustworthy. A video editing service exports a project to an MP4 file, which takes between one and twenty minutes. Clients are web apps that poll and back-end services that want a webhook. Design:

  1. The request that starts an export, and its response.
  2. The status resource and its states.
  3. The webhook sent when an export ends.
  4. The receiver's checks, in order.
Show a solution
The export API's requests and responses
StepRequest or eventResponse or content
StartPOST /projects/12/exports with Idempotency-Key202 Accepted, Location /exports/88
CheckGET /exports/88200, status queued or running, progress, Retry-After 30
DoneGET /exports/88303 See Other, Location /files/501
FailedGET /exports/88200, status failed, a problem details error
WebhookPOST to the registered URLevent export.succeeded, event id, export link, signed with timestamp

The receiver's checks, in order: read the timestamp and signature, refuse a timestamp more than five minutes old, compute the HMAC over the timestamp and raw body, compare in constant time, skip an event id already processed, store the event, answer 200, and fetch /exports/88 to act on its current state.