Prerequisites
- A service contract in OpenAPI 3.0, 3.1, or 3.2
- Stable
operationIdvalues for operations referenced by HCL effects - Familiarity with dependencies and effects
- A Simile service configuration or HCL module in which to add the examples
Understand the three-layer model
Simile represents webhooks in three layers. Each layer answers a different question and has a different source of authority.- The webhook contract defines the outbound HTTP method and request-body schema. OpenAPI is authoritative when it contains this information. A minimal HCL contract can fill a documented omission.
- The webhook occurrence records that a committed effect caused one instance of that contract. It supplies the payload, destination, causal dependencies, and any explicit delay.
- The delivery policy defines service-wide ordering, signing, concurrency, and retry semantics. It never overrides a hard causal dependency.
Define the outbound contract
Use OpenAPI for a webhook that has a published payload shape. Simile imports callbacks from OpenAPI 3.0, 3.1, and 3.2, and imports the top-levelwebhooks map from OpenAPI 3.1 and 3.2.
Top-level webhooks
A top-level webhook describes an event whose destination is independent of any one incoming operation:operationId is its stable Simile name. Otherwise, Simile
derives a name from the OpenAPI webhook or callback key. Use an explicit operationId when an HCL
effect will reference the webhook; it is clearer and survives unrelated contract reorganization.
Callbacks
An OpenAPI callback additionally describes where the service obtains the destination. This example reads the URL submitted in the operation body:{$request.body#/callback_url} and
{$response.body#/links/webhook}. The planner currently executes body-pointer expressions. Supply
a to override in HCL when the destination comes from a header, query, path, or composed OpenAPI
runtime expression.
HCL fallback contracts
When the selected API contract omits a webhook, declare the missing public message with a singularwebhook block:
method defaults to POST, and content_type defaults to application/json. The fallback body
remains unconstrained because HCL supplies no schema. It provides naming and wire metadata.
OpenAPI adds payload proof through a reusable schema. Names imported from OpenAPI remain
authoritative and reject HCL redefinition.
Attach occurrences to an effect
A webhook contract says what may be sent. Aneffect says that a particular committed operation
result causes it. The compact maps below let one effect emit several related occurrences:
The compiler resolves every webhook name, rejects duplicate or unknown occurrences, and rejects
self-dependencies and dependency cycles. At runtime, Simile renders each payload from the validated
request and committed response. When the contract came from OpenAPI, the rendered payload must
satisfy the webhook request-body schema before the occurrence can enter the plan.
after encodes a hard causal dependency. In the example, order.paid always follows
payment.succeeded. receipt.available is independent: its two-second delay affects its scheduled
time, and its relative delivery order remains available to the service-wide policy.
Request and response projections also act as applicability guards. If the selected error response
omits a required projection such as response.payment_event, Simile treats the effect as
inapplicable and preserves the public error response.
Configure ordering and inspect the result
Webhook infrastructure commonly processes independent deliveries concurrently. Model that once at service scope:best_effortpermits an eligible independent occurrence to overtake another.concurrencyis the modeled delivery capacity. Reordering requires a value of at least2.out_of_order_probabilitycontrols how often an otherwise eligible pair overtakes.reorder_windowprevents occurrences far apart in scheduled time from being compared for reordering.
Sign delivery attempts
The optionalsigning block applies one service-wide HMAC-SHA256 policy. Simile serializes the JSON
body, signs TIMESTAMP.BODY, and sends:
simile describe service
reveals only whether signing is configured and which signature header is used.
Use strict ordering only when the emulated provider guarantees it:
--verbose includes each planned webhook’s rendered body, resolved
destination when available, delay, and hard prerequisites:
Delivery lifecycle
An operation commit writes every applicable occurrence to the service outbox alongside synchronous Stack state. The worker leases a bounded batch, restores hardafter dependencies, applies the
service ordering policy to independent occurrences, and sends each HTTP request. Any 2xx response
acknowledges the item.
Transport failures and non-2xx responses release the item with an exponential delay. A process
restart restores the outbox and retry count from redb. Exhausted deliveries move to dead-letter
storage. Hard dependencies use durable completion markers, so a later occurrence cannot cross its
prerequisite after a retry or restart. Waiting for that marker consumes no delivery attempt.
Dead letters can be returned to the outbox through the service redelivery API. A dedicated
operator-facing dead-letter CLI remains to be designed.
Local delivery proves the behavior of the compiled emulator. Production throughput, provider retry
windows, private signing rotation, and receiver acceptance remain separate evidence.
Related resources
- HCL language specification - Exact
webhook,webhooks, andeffectsyntax - Dependencies and effects - How operation consequences enter an effect plan
- Durable work - Checkpoint, lease, retry, and crash-recovery semantics
- Describe a service - Inspect the public meaning of a compiled service
- Capabilities and limits - Current webhook support and service-emulation boundaries