Tutorial: Building with CleaveDB
Webhooks for Change Data Capture (CDC)
In event-driven architectures, downstream systems often need to react instantly to database updates. Instead of deploying complex external CDC infrastructure (like Apache Kafka, Debezium, or polling workers), CleaveDB includes native HTTP WEBHOOK event dispatch built directly into the storage engine.
Registering a webhook
Register an event trigger with SHAPE WEBHOOK, naming the webhook, binding it to a target bucket, and specifying the trigger action and HTTP endpoint:
SHAPE WEBHOOK "user_created" ON users WHEN action = "POUR" POST TO "https://api.example.com/hooks"Whenever a document is inserted into the users bucket via POUR, CleaveDB dispatches an asynchronous HTTP POST payload containing the affected document and session metadata directly to your webhook handler.
Trigger actions
Webhooks can be hooked into any write-phase mutation lifecycle:
| Action | Example registration | Event trigger |
|---|---|---|
| POUR | WHEN action = "POUR" | New document creation |
| CHANGE | WHEN action = "CHANGE" | Field updates and document modifications |
| DRAIN | WHEN action = "DRAIN" | Document deletion or recycling to rubbish |
Listing registered webhooks
Audit all registered webhooks using SHOW WEBHOOKS:
SHOW WEBHOOKSReturns a list of all active listeners, target endpoints, and bound event filters: {"count": 1, "data": [...]}.
