kra8/laravel-snowflake
Generate distributed, time-ordered Snowflake IDs in Laravel with kra8/laravel-snowflake. It offers configurable worker and datacenter IDs, sequence handling, and an Eloquent trait, giving models unique 64-bit IDs without extra services or coordination.
kra8/laravel-snowflake provides a drop-in Eloquent trait/cast that generates 64-bit Snowflake IDs (timestamp + worker/machine ID + sequence) at insert time. This is a build-vs-buy decision you can make once and reuse: buying it off the shelf removes a week or two of engineering on clock-skew, worker-ID assignment, and sequence-rollover edge cases.id > ? cursor pagination without an extra created_at index or tie-breaker.BIGINT, 8 bytes) instead of UUID's 16 bytes — relevant to storage-cost and index-bloat trade-offs.Caveat for planning: Snowflake IDs leak approximate creation time and embed the worker ID, and correctness depends on disciplined worker-ID assignment across all app instances. Treat worker-ID provisioning as a first-class operational decision, not an afterthought.
Adopt when:
AUTO_INCREMENT incrementally: the BIGINT column type means existing schema and FKs stay compatible.Look elsewhere when:
HasUuids/HasUniqueStringIds, or symfony/uid.BIGSERIAL/identity columns with sequences, or you need IDs to survive database-level generation (Snowflake IDs are app-generated, so raw-SQL inserts must supply their own ID).Release-specific vetting before adoption: v2.5.0 is a compatibility and housekeeping release — Laravel 13 support (via an automated Laravel Shift PR), a nesbot/carbon bump to 2.72.6, and league/commonmark to 2.7.0. There are no new features, no deprecations, and no breaking changes, so upgrading from v2.4.1 is low risk. Verify two things in your own CI rather than trusting the changelog: (1) that the Laravel 13 support is validated against the version you will actually run (automated compatibility PRs can land ahead of a stable framework release), and (2) that the Carbon bump is compatible with any code pinning Carbon 3.x — Carbon 2 is past end-of-life, so if your app is on Carbon 3 this dependency constraint may hold you back.
To executives — one paragraph: We need a reliable way to generate unique record IDs as we scale beyond a single database. Rather than build one, we can adopt a small existing library that plugs directly into our Laravel models and costs nothing to license. It lets us split data across multiple databases without ID collisions, keeps our primary keys compact (8 bytes versus 16 for UUIDs, which matters at millions of rows), and keeps IDs sortable by time for faster pagination. The newest release (v2.5.0) adds support for Laravel 13, so adopting it does not create a blocker for our next framework upgrade. Decision required: approve it as a low-risk, isolated dependency, with the caveat that it is maintained by a single author, so we should plan to vendor/fork it if it ever becomes critical-path.
To engineering — the short version: kra8/laravel-snowflake v2.5.0 gives us Snowflake ID generation through an Eloquent trait/cast, and it now supports Laravel 13. It is a pure compat + dependency-bump release: no API changes, no breaking changes, safe upgrade from v2.4.1. It solves client-side ID generation on BIGINT columns so we can run multiple writers and shards without a central sequence. Costs we accept: we must own worker-ID assignment per instance (misconfiguration risks collisions), IDs embed a timestamp and worker ID, and raw-SQL inserts bypass generation. Note the Carbon 2.x pin — check it against any Carbon 3 work. Alternative we evaluated: UUIDv7 via Laravel's built-in traits, which has no worker-ID burden but costs twice the storage and needs ordered-UUID support in the database. Recommendation: adopt for new high-write, sharded tables; keep auto-increment for small, single-node tables; budget a fork-and-own contingency given the single-maintainer risk.
How can I help you explore Laravel packages today?