glhd/bits
Generate unique 64‑bit IDs for distributed systems in PHP. Create Twitter Snowflake, Sonyflake, or custom bit-sequence identifiers with configurable worker/datacenter IDs and epoch for compact, time-ordered, collision-resistant IDs across multiple servers.
Unified ID Strategy for Microservices: Replace inconsistent UUID/ULID implementations across services with a standardized 64-bit ID system, enabling seamless cross-service relationships (e.g., orders, events, users) while reducing API payload sizes and improving traceability. Critical for event-driven architectures where IDs must be sortable and globally unique.
Database Optimization & Query Performance:
Achieve 50% storage savings (64-bit vs. 128-bit UUIDs) and enable time-based queries without joins. The toCarbon() method allows direct filtering by creation time (e.g., User::where('id', '>', firstForTimestamp(now()->subHour()))), reducing database load for analytics and reporting.
Multi-Region & Multi-Worker Scalability: Built-in support for worker/datacenter IDs ensures collision-free ID generation across 1,024+ servers (5-bit datacenter + 5-bit worker). Ideal for global deployments (e.g., Laravel Vapor, Kubernetes clusters) where traditional UUIDs introduce latency or scaling bottlenecks.
Real-Time ID Generation for Frontend/Backend Sync:
Native Livewire synthesizers (SnowflakeSynth) enable real-time ID generation in components without backend roundtrips. Useful for collaborative features (e.g., shared dashboards, live comments) where IDs must be generated client-side but remain globally unique.
Cost-Effective Alternative to PaaS IDs: Avoid vendor lock-in with self-hosted Snowflake/Sonyflake IDs (e.g., AWS Snowflake vs. custom implementation). Reduces dependency on third-party services while maintaining scalability.
Time-Travel & Testing Support:
Custom setTestNow() method (instead of Carbon’s) ensures consistent ID generation in tests, preventing edge cases where time manipulation breaks UUID/ULID behavior.
Hybrid ID Formats for Flexible Use Cases: Support for Snowflake (Twitter-style) and Sonyflake (Sony-style) formats allows teams to choose based on scale, distribution, or metadata needs (e.g., Sonyflake’s 16-bit machine ID for finer-grained tracking).
Avoid if:
BITS_WORKER_ID/BITS_DATACENTER_ID across environments.Consider alternatives if:
Number max is 53 bits; strings required).For Executives: "Bits lets us replace bloated UUIDs with compact, sortable 64-bit IDs—saving storage costs, improving query performance, and enabling seamless cross-service data relationships. For example, an order ID can now double as a timestamp for analytics, reducing database load by 50%. It’s a scalable, self-hosted alternative to PaaS IDs, future-proofing our architecture for global growth."
For Engineers: *"This is a drop-in replacement for UUIDs/ULIDs in Laravel, with built-in support for:
id > firstForTimestamp(now()->subHour())).For Data Teams:
"Bits enables native time-based filtering on IDs, so we can replace WHERE created_at > X with WHERE id > snowflake_id_for_timestamp(X). This cuts database load for time-range queries (e.g., daily active users) by avoiding joins and indexing created_at separately."
How can I help you explore Laravel packages today?