You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A high-performance, distributed Snowflake ID generator bundle for Symfony applications. This bundle implements Twitter's Snowflake algorithm to generate unique, time-ordered, 64-bit IDs for distributed systems. It is designed for scenarios requiring globally unique IDs under high concurrency.
40
+
A high-performance, distributed Snowflake ID generator bundle for Symfony applications. This bundle implements
41
+
Twitter's Snowflake algorithm to generate unique, time-ordered, 64-bit IDs for distributed systems. It is
42
+
designed for scenarios requiring globally unique IDs under high concurrency.
9
43
10
44
## Features
11
45
12
46
- Generates 64-bit unique IDs based on [godruoyi/php-snowflake](https://github.com/godruoyi/php-snowflake) library
13
47
- Built-in Redis sequence resolver to ensure uniqueness in high-concurrency environments
14
48
- Auto-generates WorkerId based on hostname for distributed scenario support
15
49
- Zero configuration required for basic usage
16
-
- Fully compatible with Symfony 6.4/7.1+
50
+
- Fully compatible with Symfony 7.3+
51
+
- Graceful fallback from Redis to RandomSequenceResolver when Redis is unavailable
17
52
- Autowiring support for easy integration with Symfony services
18
53
- Thread-safe ID generation
19
54
- Time-ordered IDs for efficient database indexing
@@ -23,7 +58,7 @@ A high-performance, distributed Snowflake ID generator bundle for Symfony applic
23
58
### Requirements
24
59
25
60
- PHP >= 8.1
26
-
- Symfony >= 6.4
61
+
- Symfony >= 7.3
27
62
- Redis (recommended for distributed sequence safety)
28
63
29
64
### Install via Composer
@@ -113,17 +148,20 @@ This ensures different server instances generally get different WorkerIds withou
113
148
114
149
### Redis-Based Sequence Resolver
115
150
116
-
When `snc/redis-bundle` is installed and configured in your application, the Snowflake bundle automatically uses Redis for sequence distribution, which provides:
117
-
151
+
When Redis is available, the bundle automatically uses `RedisSequenceResolver` for:
118
152
- Enhanced uniqueness guarantees under high concurrency
119
153
- Improved resistance to clock drift
120
154
- Better distribution of IDs across multiple instances
121
155
156
+
When Redis is unavailable, it gracefully falls back to `RandomSequenceResolver` to ensure service availability.
157
+
122
158
## Configuration
123
159
124
160
For basic usage, no extra configuration is required. The bundle works with sensible defaults.
125
161
126
-
### Advanced Configuration
162
+
## Advanced Usage
163
+
164
+
### Custom Sequence Resolver
127
165
128
166
For more advanced scenarios, you may extend the `ResolverFactory` to provide a custom sequence resolver:
129
167
@@ -151,19 +189,31 @@ Then register your custom factory in your service configuration.
151
189
152
190
-**Redis in Production**: Always use Redis in production environments for sequence distribution
153
191
-**Clock Synchronization**: Ensure your server clocks are synchronized with NTP
154
-
-**Worker ID Management**: For large distributed deployments, consider implementing a centralized WorkerId assignment mechanism
155
-
-**ID Storage**: Store Snowflake IDs as `BIGINT` in databases (or strings if your DB doesn't support 64-bit integers)
192
+
-**Worker ID Management**: For large distributed deployments, consider implementing a centralized WorkerId
193
+
assignment mechanism
194
+
-**ID Storage**: Store Snowflake IDs as `BIGINT` in databases (or strings if your DB doesn't support
195
+
64-bit integers)
156
196
-**Benchmarking**: Test performance in your environment as high throughput may require tuning
157
197
158
198
## Potential Pitfalls
159
199
160
200
-**Clock Moving Backwards**: If server time moves backward due to NTP adjustments, duplicate IDs might be generated
161
-
-**Worker ID Conflicts**: In very large deployments, hostname-based WorkerId generation might lead to conflicts
201
+
-**Worker ID Conflicts**: In very large deployments, hostname-based WorkerId generation might lead to
202
+
conflicts
162
203
-**Performance without Redis**: Without Redis, high concurrency might lead to duplicates under extreme circumstances
163
204
205
+
## Changelog
206
+
207
+
### 0.0.x
208
+
- Initial release with Snowflake ID generation support
209
+
- Redis-based sequence resolver with graceful fallback
210
+
- Automatic WorkerId generation based on hostname
211
+
- Full Symfony 7.3+ integration with autowiring support
212
+
164
213
## Contributing
165
214
166
-
Issues and pull requests are welcome! Please visit the [GitHub repository](https://github.com/tourze/symfony-snowflake-bundle) to contribute.
215
+
Issues and pull requests are welcome! Please visit the
216
+
[GitHub repository](https://github.com/tourze/php-monorepo) to contribute.
0 commit comments