mercadona / postoffice

A dispatching service implemented in Elixir. Communicate services or sent api calls to yourself to process anything later
Apache License 2.0
23 stars 7 forks source link

Post messages with different topics in bulk #140

Open jonasae opened 3 years ago

jonasae commented 3 years ago

There are cases in which a group of use cases happens at the same time and eventual consistency must be guaranteed. For each one of these use cases, an event is published for different topics. An example would be the validation by scanning in dispatch, where the following events might happen and therefore be published:

If an error occurred in the middle, database would rollback, but events would have been published.

Furthermore, each request to postoffice adds latency and it could be reduced to just one call.

A purpose would be to expose an endpoint that would allow us to send messages of different topics in bulk.

Postoffice already exposes POST /bulk/messages/ but it's only for messages with the same topic. I think it's misleading, as the topic belongs to the message.

In order to don't break the current API, our proposal is to expose an endpoint like POST /bulk//multitopic-messages/ which would accept a body like:

{
  'messages': [
    {'topic': 'a-topic', payload: {...}},
    ...
  ]
}