Skip to content

Use separate webhook per configuration, instead of shared endpoint #725

@krzysztofwolski

Description

@krzysztofwolski

The problem I would like to address:

Duplicated email delivery when one of the configurations fails.

Consider setup:

  • User has multiple configurations: two SMTP and two Sendgrid. It's not uncommon to have separate configurations for different channels
  • Saleor sends event webhook
  • One of the configurations time outs or was misconfigured

Currently:

  • all configurations share the same webhook endpoint, for example /api/webhooks/order-created
  • some of the configurations will send an email successfully
  • one of the configurations will throw an error, resulting in non 200 response to the Saleor
  • webhook will retry, causing duplicated email deliveries

Solution:

  • each configuration should have a dedicated endpoint for each event: /api/webhooks/$PROVIDER/$CONFIGURATION_ID/order-created
  • webhooks are dynamically created/removed when the configuration is: created, removed, activated, event is enabled/disabled
  • now, failure of the single configuration will have no impact on others

Additional pros of the proposed solution:

  • we'll be able to modify the payload for every configuration in the future (add/remove keys)
  • less data fetching for each of the webhooks (fetch dedicated configuration instead of all the providers)
  • less complicated code for webhook management - no need to check all the configurations from all providers to determine if webhook would be removed or not
### Tasks
- [ ] create WebhooksServiceV2, which uses the described approach
- [ ] webhooks in the API are distinguished by their name, which should now contain the provider, configuration ID, and event name (`sendgrid.1234.order-created`)
- [ ] Prepare migration script, which will migrate old webhooks to the new ones

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions