Skip to content

Conversation

@prosdev
Copy link
Contributor

@prosdev prosdev commented Jan 11, 2026

Summary

Implements Issue #4 - Hash-based sequencer for consistent partition routing.

Changes

  • Sequencer Protocol: Pluggable interface for routing strategies
  • HashSequencer: Python's built-in hash() with priority-based routing
    • Priority: userId → anonymousId → eventId
    • Configurable partition count (default: 16)
    • Handles edge cases (empty strings, unicode, very long IDs)
  • Comprehensive Tests: 18 tests covering:
    • Consistency (same identity → same partition)
    • Range validation (0 to N-1)
    • Distribution quality (even spread, no odd/even bias)
    • Priority fallback logic
    • Edge cases

Implementation Notes

  • Uses Python's built-in hash() (simple, fast, good distribution)
  • Production CDPs often use Murmur3 for better distribution (future upgrade path)
  • No XOR folding or memoization (YAGNI for v1)
  • ~70 lines of production code + 200 lines of tests

Test Coverage

  • 100% coverage on sequencer.py
  • Distribution tests validate even spread across 10,000 events
  • No odd/even bias (validates hash quality)

Closes #4

@prosdev prosdev merged commit 3bd2fee into main Jan 11, 2026
1 check 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.

Sequencer (Hash-Based Routing)

2 participants