zalando-nakadi / nakadi-producer-spring-boot-starter

Nakadi event producer as a Spring boot starter
MIT License
13 stars 8 forks source link

Support for compacted event types #154

Closed ePaul closed 1 year ago

ePaul commented 1 year ago

Background / Status quo

Currently this library does not support submitting events to compacted event types, as it is missing the partition_compaction_key in the metadata object.

This is justified by these paragraphs in the README:

Be aware that this library does neither guarantee that events are sent exactly once, nor that they are sent in the order they have been persisted. This is not a bug but a design decision that allows us to skip and retry sending events later in case of temporary failures. So make sure that your events are designed to be processed out of order (See Rule 203 in Zalando's API guidelines). To help you in this matter, the library generates a strictly monotonically increasing event id (field metadata/eid in Nakadi's event object) that can be used to reconstruct the message order.

Unfortunately this approach is not compatible with Nakadi's compacted event types – it can happen that the last event submitted (and thus the one which will stay after compaction) is not the last event which was actually been fired. For this reason, the library currently also doesn't provide any access to Nakadi's partition_compaction_key feature.

There are some cases where the out-of-order submission is less critical – e.g. when you have occasionally have groups of events for different entities (and thus different compaction keys), and a long time in-between those groups. Here is it quite unlikely that events for the same entity are submitted out of order, and compaction is also quite useful.

Possible workarounds for this situation:

Suggestion

  1. Make it possible to provide the compaction key when producing events with this library (of course optional, and in a compatible way so old code doesn't break)
  2. Still keep a warning similar to the one above in the README (and in the javadoc of this feature), so people are not surprised when they still get the not-last event in their compacted event type.
ePaul commented 1 year ago

Implementation plan

For the compatible API, I see these options here:

In addition, we need this:

ePaul commented 1 year ago

So I built two variants of this:

We tried this out in an internal service, and it the second way looks cleaner, so I'd suggest to go for this way.

ePaul commented 1 year ago

164 was merged already half a year ago (and released in 21.0.0), so I guess we can close this now as completed.