saleor / saleor

Saleor Core: the high performance, composable, headless commerce API.
https://saleor.io
BSD 3-Clause "New" or "Revised" License
20.64k stars 5.46k forks source link

Add ordering keys to webhook events #14925

Open patrys opened 10 months ago

patrys commented 10 months ago

Problem

When events are delivered to systems that want to process them in order but also concurrently, there needs to exist a mechanism to tell which events are related to the same object (and thus need to be processed one after another), and which ones are unrelated (and thus can be processed at the same time).

A typical use case is delivering messages to an ordered Google Pub/Sub queue or an SQS FIFO queue as those have built-in support for ordering keys and ordered processing. A less obvious case is delivery to an HTTP endpoint that then relays the message to a system that implements ordered processing.


1. General Assumptions

Every async event should have an ordering key. Events related to the same object should share the same ordering key, preferably the GraphQL ID of the object (or, even better, a combination of Saleor's PUBLIC_URL and the object ID in case a system was to process events from multiple Saleor instances, which will definitely happen for some payment apps).

Acceptance Criteria

2. API changes

Types

interface Event {
  # …
  orderingKey: String!
}

3. Database changes

4. UML diagrams

5. To Do list

timuric commented 10 months ago

how about adding resource versioning instead so it is also useful for reads

patrys commented 10 months ago

Resource versioning does not solve the problem described in the first comment (parallel processing with ordering guarantees).