Webhook lab
Design retries, degradation, and recovery
When signature optional in staging config accidentally shipped to prod, the system must degrade on purpose without widening blast radius.
1Try it yourself
Decision drill
Webhook lab
Webhooks push events — polling pulls. Verify signatures before acting.
1/3Nightly index job finished.
2Learn the idea
Read
Classify and bound retries
Map failure classes for POST /webhooks/batch-index: retryable vs fatal vs needs-human. Retries need budgets, jitter, and idempotency rules aligned to verify HMAC signature + timestamp skew ≤ 5m; enqueue idempotent by event_id. The chapter’s signature failure — signature optional in staging config accidentally shipped to prod — must take a deliberate branch, not a generic catch-all.
Read
Containment path
Implement the degrade/rollback/refuse behavior indexer worker waiting on provider batch.completed callbacks needs when HOOK-SIG-OFF-16 repeats. Prefer scoped controls (one flag, one weight, one tenant, one secret version) over fleet-wide restarts. Preserve evidence; do not delete logs to “clean the demo.”
Read
Implementation artifact
if abs(time.time() - ts) > MAX_SKEW_S:
raise HTTPException(401, "stale_timestamp")
Read
Verify harm reduction
After containment, check webhook_accept_total and duplicate_suppressed_total moves in the safe direction and watch for retry amplification. Write the stop condition that ends the incident response for this lab.
Read
Stage depth
Chaos note: inject only one fault class at a time and restore fixtures after. Watch for dual failures — dependency down and retry amplifier — which is how signature optional in staging config accidentally shipped to prod becomes an outage. Customer communication templates (even if only for the drill) beat silence. If you queue deferred work, define poison-message handling. Budget documents should state the maximum extra spend allowed during retries. Close the loop by linking the containment action to a dashboard panel for webhook_accept_total and duplicate_suppressed_total.
Read
Field notes for `webhook-lab` / `failure-handling`
Draw a state diagram for degrade modes and put it in the repo as ASCII if needed. Cap concurrent retries across the process, not only per request. Ensure cancellation propagates to downstream HTTP clients. When failing closed, choose a user-visible message that does not leak internals. Practice the single command that flips the kill switch or weight to zero. After recovery, drain or inspect deferred work before declaring green. In this chapter the product is FastAPI receiver for batch-index completion events → durable queue, the human stakeholder is indexer worker waiting on provider batch.completed callbacks, and the incident id you design against is HOOK-SIG-OFF-16. Re-state the oracle in your notes — valid event → 202 + one queue message; replay same event_id → 202 no duplicate work — and keep the invariant visible: verify HMAC signature + timestamp skew ≤ 5m; enqueue idempotent by event_id. Track webhook_accept_total and duplicate_suppressed_total as the scoreboard. Surface under change control: POST /webhooks/batch-index. If you only have forty minutes, finish the fixture for signature optional in staging config accidentally shipped to prod before polishing UI. Promotion language stays ternary: promote, hold, or roll back based on evidence, not hope.
Go deeper
Before you start
Why this matters
Assume signature optional in staging config accidentally shipped to prod is happening right now. Write the first safe action, the signal that confirms containment, and the action you will not take (infinite retry, broad restart, deleting evidence). Tie the plan to invariant: verify HMAC signature + timestamp skew ≤ 5m; enqueue idempotent by event_id.
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.