vincenzocorso / spring-outbox-example

A sample implementation of the Outbox Pattern for microservice architectures.
6 stars 1 forks source link

Outbox message deletion #1

Open jaybi4 opened 1 year ago

jaybi4 commented 1 year ago

Hi Vincenzo,

I stumbled upon this repo looking for a reference to implement the outbox pattern. You really did a good job here👍

Getting an issue in this repo might sound weird but I just wanted to give you some insight on something. I see that when you store the messages to the outbox persistence you perform it like this (in the publishers):

OutboxEvent savedOutboxEvent = this.outboxEventRepository.save(outboxEvent);
this.outboxEventRepository.delete(savedOutboxEvent);

While understanding why you delete them, I think it would be better not to. There are two main reasons for this:

Let me know your thoughts.

Thanks!

vincenzocorso commented 1 year ago

Hi,

Sorry if I reply only now, but I've been a bit busy.

You are right. You can keep messages in the outbox table, instead of deleting them. However, there are some considerations to do. Retain all the messages sent can be very costly, but you can accept some tradeoff. For example an alternative implementation might allow to set the maximum retention period or the maximum number of messages to keep.

This is similar to the strategy adopted by Kafka, which has a default max retention period of seven days.

jaybi4 commented 1 year ago

Fair points! And I like the alternative you present when the outbox gets too big.

Many thanks for your thoughts,