glhd/bits
Generate unique 64-bit IDs in PHP for distributed systems. Create Twitter Snowflake, Sonyflake, or custom bit-sequence identifiers. Configure worker/datacenter IDs and a custom epoch to avoid collisions across servers.
Strengths:
WHERE id > X to fetch recent records), reducing the need for separate created_at columns.HasSnowflakes), Livewire synthesizers, and Query Builder compatibility, reducing boilerplate.Weaknesses:
BITS_WORKER_ID/BITS_DATACENTER_ID per server, which complicates dynamic scaling (e.g., serverless/Lambda) or ephemeral environments (e.g., Kubernetes pods). Misconfiguration risks ID collisions.SequenceResolver (e.g., Redis-backed) for high-volume systems.Number.MAX_SAFE_INTEGER, forcing string serialization for frontend use cases.HasSnowflakes trait (replaces HasUuids). Supports casting IDs to Snowflake objects for type safety.Query\Expression, enabling direct use in WHERE clauses (e.g., time-range filtering).setTestNow() to mock timestamps, but does not inherit Carbon’s setTestNow, which may require refactoring existing test suites.BIGINT (8 bytes), but indexing performance may vary by DB (e.g., PostgreSQL’s BIGINT vs. MySQL’s UNSIGNED BIGINT).ALTER TABLE users CHANGE id BIGINT).worker_id/datacenter_id assignment (e.g., duplicate IDs across servers) or sequence exhaustion. Mitigation: Use Redis-backed sequence resolvers and validate configs in CI/CD.firstForTimestamp() for safe queries.setTestNow() and design tests to avoid epoch conflicts.worker_id management.)travel())? (Epoch conflicts possible.)worker_id/datacenter_id in IDs.)worker_id management.BIGINT support), MySQL 8.0+ (with UNSIGNED BIGINT).BIGINT indexing in older versions).| Phase | Action | Risk | Mitigation |
|---|---|---|---|
| Assessment | Audit existing ID usage (UUIDs, auto-increments, custom). | High (migration complexity). | Document all ID sources. |
| Pilot | Replace non-critical IDs (e.g., audit logs, temporary entities). | Medium (limited impact). | Use dual-writes during transition. |
| Core Migration | Replace primary keys (e.g., users.id). |
High (schema changes). | Backfill existing IDs via ETL. |
| Query Rewrite | Update time-based queries (e.g., WHERE created_at > X → WHERE id > snowflake_for_timestamp(X)). |
Medium (logic changes). | Write migration tests. |
| Frontend Sync | Update APIs to return IDs as strings for JS compatibility. | Low (API contract change). | Deprecate integer IDs gradually. |
BIGINT scans).illuminate/support (for Eloquent/Livewire), nesbot/carbon.predis/predis (for Redis sequence resolver).BITS_WORKER_ID and BITS_DATACENTER_ID per server (use environment variables orHow can I help you explore Laravel packages today?