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

De-duplicate getSeed generation in high throughput scenarios #1186

Merged

Conversation

ikraamg
Copy link
Contributor

@ikraamg ikraamg commented Mar 14, 2025

Adds a counter that increments with each call to getSeed()
This ensures that even if multiple calls happen at the exact same timestamp,
they will receive different seed values due to the incrementing counter.

Reasons for this solution:

  • Isomorphic compatibility (No external dependencies)
  • Simple but effective
  • The implementation is lightweight and doesn't introduce significant overhead.
  • Using % Number.MAX_SAFE_INTEGER ensures the counter stays within JavaScript's safe integer bounds

Adds a counter that increments with each call to getSeed()
This ensures that even if multiple calls happen at the exact same timestamp,
they will receive different seed values due to the incrementing counter.

Reasons for this solution:
- Isomorphic compatibility
- No external dependencies
- Simple but effective
- The implementation is lightweight and doesn't introduce significant overhead.
- Using `% Number.MAX_SAFE_INTEGER` ensures the counter stays within JavaScript's safe integer bounds
@ikraamg ikraamg marked this pull request as ready for review March 14, 2025 22:54
@absorbb
Copy link
Contributor

absorbb commented Mar 17, 2025

Thank you.
Just curious. We have two Math.random() calls in randomId method
Do you have some cases when it is not enough?

@ikraamg
Copy link
Contributor Author

ikraamg commented Mar 17, 2025

I am not exactly sure why because theoretically it seems we should not have an issue.

During some load tests (millions of events in a short timeframe) from a server to these endpoints :url/api/s/:event_type, we had duplicates when we relied on the Jitsu. Solved by passing in an externally generated UUID per request.
It is probably also also caused by having hashString the same for all events we sent.

@ikraamg ikraamg changed the title De-duplicate messageID generation in high throughput scenarios De-duplicate getSeed generation in high throughput scenarios Mar 17, 2025
@absorbb absorbb merged commit 8e83235 into jitsucom:newjitsu Mar 23, 2025
0 of 3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants