Skip to content

replace snowflaked to avoid conflicts#117

Draft
gallone2000 wants to merge 1 commit into
masterfrom
alessandro/replace-snowflaked
Draft

replace snowflaked to avoid conflicts#117
gallone2000 wants to merge 1 commit into
masterfrom
alessandro/replace-snowflaked

Conversation

@gallone2000

Copy link
Copy Markdown
Contributor

Replace snowflaked crate with custom implementation

Overview

This PR removes the external snowflaked dependency and replaces it with a custom, lock-free snowflake ID generator implementation. The new implementation maintains full behavioral compatibility with snowflaked 1.0.3 while providing equivalent or improved performance characteristics.

Key Changes

  • Removed dependency: Moved snowflaked from production to dev-dependencies (used only for testing/oracle validation)
  • Custom generator: Implemented a deterministic, thread-safe snowflake generator using atomic CAS operations with Relaxed ordering
  • Bit layout: Maintains the exact same 42/10/12 bit partitioning (timestamp/instance/sequence) as the original crate
  • Behavior parity: Clock rollback handling, sequence overflow with millisecond wait, and timestamp extraction match the oracle exactly

Test Coverage

I implemented comprehensive test suites to ensure robustness and guard against future regressions:

Deterministic Tests

  • Single and multi-threaded uniqueness and monotonicity
  • System time extraction and Unix epoch alignment
  • Millisecond boundary transitions
  • u63 boundary handling
  • JSON serialization roundtrips
  • Model-based scripted state transitions with controlled clock

Oracle-Based Tests

  • Bit-for-bit packing equivalence with snowflaked::Snowflake::from_parts
  • Failure mode validation: both implementations panic identically on clock rollback

Property-Based Tests

  • Generated with proptest to explore large input spaces automatically
  • Roundtrip pack/unpack preservation of components
  • Boundary-biased strategies covering edge cases (0, max, near-max values)
  • Monotonicity and uniqueness under varying sample sizes
  • u63 boundary behavior for all valid input combinations

Includes CI-friendly seed control via PROPTEST_SEED env var for deterministic property test execution.

Performance

Benchmark suite included for regression detection.

Rationale

The custom implementation:

  1. Eliminates an external dependency while maintaining full compatibility
  2. Provides transparent behavior through extensive oracle testing
  3. Reduces operational risk via property-based testing of edge cases
  4. Scales equally or better under concurrent load

@gallone2000 gallone2000 requested a review from isomorpheme July 7, 2026 15:05
@gallone2000 gallone2000 self-assigned this Jul 7, 2026
@gallone2000 gallone2000 requested a review from Qqwy July 7, 2026 15:06
@gallone2000 gallone2000 force-pushed the alessandro/replace-snowflaked branch from 1e0c92a to 7ab6003 Compare July 7, 2026 15:09
@gallone2000 gallone2000 force-pushed the alessandro/replace-snowflaked branch from 7ab6003 to a6bc90b Compare July 7, 2026 15:24
@gallone2000 gallone2000 requested a review from ReinierMaas July 8, 2026 09:55
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.

1 participant