Description
At this moment we have hardcoded logic for generating new eid value - link
There are following advantages for this solution:
- We have a guarantee that every event sent from this application (or rather, using this same eventlog table/eid sequence) has only one unique eid. If we republish this event it will be republished with the same eid.
- Sequential eid generation – the eid can be used as an ordering key to restore the event creation order.
But also we have some disadvantages:
- The ID generated here is formatted as an UUID (as this is how the field is declared at Nakadi), but actually doesn't provide the uniqueness guarantees expected from UUIDs
- If you have multiple producers (with separate databases) submitting to the same event type, each has their own sequence running in parallel, which will produce duplicates.
In some cases it topics with multiple producers are needed (or at least very nice to have), and we should have a uniqueness guarantee of eids at least per event type for them.
I see the these possible solutions:
-
Based on configuration, use different strategy for
convertToUUID
method: current (by default) or UUID.randomUUID().
The main changes are needed in mapToNakadiEvent and tryToPublishBatch.
But in this case we lose all advantages of the current solution with randomUUID generation. -
Add additional
eid
column with generated eid to event_log table.
Before persisting the event, event generaterandomUUID
in createEventLog and persist theEventLog
entity with already generated eid.
When we try to send event to nakadi, we can choose the different strategy based oneid
field. If there is data there, then useeid
field, if not, thenid
with default strategy. (Again don't forget about failed events resolving in tryToPublishBatch).
In this case we have guarantee for repulishing, but lose sequential eid generation logic (possibly we can usespanCtx
and addid
field as key here).