The outcome of this feature is for consuming services to receive notification when a change in the data occurred. This will be implemented using webhooks which involves:
Defining events in the system that can be subscribed to
Defining a mechanism for [un]subscribing webhooks
Persisting the subscribed webhooks
For simplicity, there will only be a single generic change event in this service for any change in the data models that occur. The mechanism for [un]subscribing webhooks will be a YAML file that will be persisted on disk. This should be suitable given the small scale. To ensure serializability of changes, subscriptions will be queued in a change that a worker will consume batching the changes and writing the file back to disk.
A service can subscribe themselves by sending PUT request to the /hooks/:secret endpoint. Where :secret should be a sufficiently complex string that cannot be guessed or have potential collisions. A good choice would be a random UUID. Subsequent PUT requests are idempotent and persisted.
PUT /hooks/a7c63bc1837a8d8d70e
Content-Type: application/json
{
"url": "http://myserver.com/data-models",
"events": ["change"]
}
Unsubscribing is simply sending a DELETE request to the same endpoint.
The outcome of this feature is for consuming services to receive notification when a change in the data occurred. This will be implemented using webhooks which involves:
For simplicity, there will only be a single generic
change
event in this service for any change in the data models that occur. The mechanism for [un]subscribing webhooks will be a YAML file that will be persisted on disk. This should be suitable given the small scale. To ensure serializability of changes, subscriptions will be queued in a change that a worker will consume batching the changes and writing the file back to disk.A service can subscribe themselves by sending PUT request to the
/hooks/:secret
endpoint. Where:secret
should be a sufficiently complex string that cannot be guessed or have potential collisions. A good choice would be a random UUID. Subsequent PUT requests are idempotent and persisted.Unsubscribing is simply sending a DELETE request to the same endpoint.
Note, this requires the consumer to persist the secret key used in the URL so they can update or delete the hook later if necessary.