UserManagementSequence
Provides atomic sequence generation for creating unique identifiers across the user management system, ensuring no duplicates even under high concurrency. This entity implements database sequences at the application level, critical for generating unique values like user IDs, session tokens, or invoice numbers in distributed systems where auto-increment fields aren't reliable. Each sequence maintains a current value and increment step, with atomic operations guaranteeing that no two requests get the same value even when thousands of requests arrive simultaneously. The entity supports different sequence strategies: monotonic increasing (like traditional auto-increment), cyclic (wrapping around after reaching max value), and cached sequences for performance (pre-allocating blocks of numbers). Caching is particularly important for high-throughput systems - instead of hitting the database for every ID, the application can reserve a block of 100 IDs and distribute them from memory. This entity also handles overflow scenarios, supports custom formatting (like adding prefixes or padding), and maintains audit information about sequence usage. It's essential for maintaining referential integrity and ensuring unique constraints are never violated, especially in systems that need to generate IDs across multiple application servers or during database migrations.
Properties
| Property | Type | Mode | Description | Required |
|---|---|---|---|---|
| sequenceName | string | stored | Unique identifier for this sequence Example: | Required |
| currentValue | bigint | stored | Current value of the sequence | Required |
| incrementBy | integer | stored | Value to add for each sequence increment | Optional |
| minValue | bigint | stored | Minimum allowed value for the sequence | Optional |
| maxValue | bigint | stored | Maximum allowed value before cycling or error | Optional |
| startValue | bigint | stored | Initial value when sequence was created | Optional |
| isCyclic | boolean | stored | Whether to wrap around to minValue after reaching maxValue | Optional |
| cacheSize | integer | stored | Number of values to pre-allocate for performance | Optional |
| cachedUntil | bigint | stored | Last value in the current cache block | Optional |
| prefix | string | stored | String prefix to add to generated values Example: | Optional |
| suffix | string | stored | String suffix to add to generated values | Optional |
| paddingLength | integer | stored | Minimum length with zero padding Example: | Optional |
| format | string | stored | Format pattern for generated values Example: | Optional |
| lastAllocatedAt | DateTime | stored | When a value was last allocated from this sequence | Optional |
| allocationCount | bigint | stored | Total number of values allocated | Optional |
| lastResetAt | DateTime | stored | When the sequence was last reset | Optional |
| isLocked | boolean | stored | Whether the sequence is locked for maintenance | Optional |
| description | string | stored | Purpose and usage notes for this sequence | Optional |
| lastModifiedAt | DateTime | stored | Last time the sequence configuration changed | Required |
| version | integer | stored | Version for optimistic locking on updates | Optional |
Examples
Example 1
{
"@type": "UserManagementSequence",
"sequenceName": "user_id_sequence",
"currentValue": 1547823,
"incrementBy": 1,
"minValue": 1000000,
"maxValue": 9999999,
"startValue": 1000000,
"isCyclic": false,
"cacheSize": 100,
"cachedUntil": 1547923,
"prefix": "USR",
"paddingLength": 7,
"format": "USR{#######}",
"lastAllocatedAt": "2024-03-15T14:30:45Z",
"allocationCount": 547823,
"isLocked": false,
"description": "Main sequence for generating unique user IDs",
"lastModifiedAt": "2024-01-01T00:00:00Z",
"version": 5478
}Example 2
{
"@type": "UserManagementSequence",
"sequenceName": "session_token_counter",
"currentValue": 9999887,
"incrementBy": 1,
"minValue": 0,
"maxValue": 9999999,
"startValue": 0,
"isCyclic": true,
"cacheSize": 1000,
"cachedUntil": 9999999,
"paddingLength": 7,
"lastAllocatedAt": "2024-03-15T14:31:00Z",
"allocationCount": 85643219,
"lastResetAt": "2024-03-15T00:00:00Z",
"isLocked": false,
"description": "Cyclic counter for session token generation, resets daily",
"lastModifiedAt": "2024-03-15T00:00:00Z",
"version": 856
}