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.

20 properties
Schema

Properties

PropertyTypeModeDescriptionRequired
sequenceNamestring
stored

Unique identifier for this sequence

Example: "user_id_sequence"

Required
currentValuebigint
stored

Current value of the sequence

Required
incrementByinteger
stored

Value to add for each sequence increment

Optional
minValuebigint
stored

Minimum allowed value for the sequence

Optional
maxValuebigint
stored

Maximum allowed value before cycling or error

Optional
startValuebigint
stored

Initial value when sequence was created

Optional
isCyclicboolean
stored

Whether to wrap around to minValue after reaching maxValue

Optional
cacheSizeinteger
stored

Number of values to pre-allocate for performance

Optional
cachedUntilbigint
stored

Last value in the current cache block

Optional
prefixstring
stored

String prefix to add to generated values

Example: "USR"

Optional
suffixstring
stored

String suffix to add to generated values

Optional
paddingLengthinteger
stored

Minimum length with zero padding

Example: 10

Optional
formatstring
stored

Format pattern for generated values

Example: "USR-{YYYY}-{######}"

Optional
lastAllocatedAtDateTime
stored

When a value was last allocated from this sequence

Optional
allocationCountbigint
stored

Total number of values allocated

Optional
lastResetAtDateTime
stored

When the sequence was last reset

Optional
isLockedboolean
stored

Whether the sequence is locked for maintenance

Optional
descriptionstring
stored

Purpose and usage notes for this sequence

Optional
lastModifiedAtDateTime
stored

Last time the sequence configuration changed

Required
versioninteger
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
}