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 generate randomUUID in createEventLog and persist the EventLog entity with already generated eid.
When we try to send event to nakadi, we can choose the different strategy based on eid field. If there is data there, then use eid field, if not, then id 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 use spanCtx and add id field as key here).
At this moment we have hardcoded logic for generating new eid value - link
There are following advantages for this solution:
But also we have some disadvantages:
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
convertToUUIDmethod: 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
eidcolumn with generated eid to event_log table.Before persisting the event, event generate
randomUUIDin createEventLog and persist theEventLogentity with already generated eid.When we try to send event to nakadi, we can choose the different strategy based on
eidfield. If there is data there, then useeidfield, if not, thenidwith 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 use
spanCtxand addidfield as key here).