feat(indexing): implemented a two-stage Kafka processing architecture with event aggregation#890
Merged
feat(indexing): implemented a two-stage Kafka processing architecture with event aggregation#890
Conversation
SvitlanaKovalova1
approved these changes
Feb 2, 2026
|
vgema
approved these changes
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Purpose
Address ordering and deduplication issues in instance indexing by implementing a two-stage Kafka processing architecture. This PR introduces a re-emission pattern where instance-level events are published to Kafka with
instanceIdas the key, ensuring all changes for the same instance are ordered within a single partition. The consumer then aggregates these events before querying the database, reducing database load and preventing race conditions.Problem Statement
Previously, when multiple updates affected the same instance (e.g., holding changes, item updates), each update triggered an immediate database query and OpenSearch indexing operation. This caused:
Solution Approach
Implemented a two-stage Kafka processing architecture with event aggregation:
Stage 1: Event Re-emission
handleInstanceEventsreceives resource events (instance, holding, item, bound-with)instanceIdfrom each eventIndexInstanceEventto Kafka withinstanceIdas keyStage 2: Event Aggregation & Indexing
handleIndexInstanceEventsconsumes batched eventsinstanceIdwithin each batchinstanceId(instance + holding + item join)Architecture Changes
New Classes
ProducerRecordBuilder
InstanceEventMapper
Refactored Classes
KafkaMessageListener
handleInstanceEventsfrom 30+ lines to 3 linesResourceService
indexInstancesById,indexInstancesByIdNew)indexInstanceEventsmethod for cleaner APIInstanceFetchService
fetchInstancesFromRepositoryChanges Checklist
ResourceEventtoIndexInstanceEventfor instance indexing flowRelated Issues
MSEARCH-1157
Technical Details
Event Flow
Kafka Message Format
{tenant}.search.index.instanceinstanceId(ensures partitioning)IndexInstanceEvent(tenant, instanceId)