Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lost events as Kafka groupIdPrefix has high likelihood of collisions in large deployments #37

Open
simbo1905 opened this issue Oct 21, 2024 · 0 comments

Comments

@simbo1905
Copy link

simbo1905 commented Oct 21, 2024

In the following code:

groupId: `${groupIdPrefix}-${Math.ceil(Math.random() * 9999)}`,

The probability of collisions in the generation of unique groupIdsuffers from a high likelihood of collisions like The Birthday Paradox problem. When you have 200 subscriptions you get an 87% probability that two graphic subscriptions have the same groupId for their kafka topic subscription. Only one browser will get the kafka event. Kafka will round robin events between the overlapping subscriptions.

The fix would be to add something like a static variable in the class as a counter. Then print that counter into the groupId rather than use a random number which is problematic.

In our case we use kubernetes, we injected into each NodeJS the pod name which is unique, then we implemented a module static count, and add that to the pod name to generator our groupIdPrefix. That way we are sure to get a unique kafka groupId per browser subscription. This is a workaround. If the bug is fixed we can simply use the pod name as a groupIdPrefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant