Skip to content

Conversation

CyberDrudge
Copy link

@CyberDrudge CyberDrudge commented Feb 19, 2025

Currently ID string generated by IDGenerator has a specific format (with date time, nodeId and nonce encoded in ID).

These generated IDs can be parsed back to the exact DateTime (including millisecond precision) and nonce. In future, we aim to support more formats of IDs (specifically placement of date time (granularity of timestamp), nodeId and nonce components).

This PR aims at adding a type to the generated ID (additional two characters will be used as suffix for this) in order to allow flexibility in future for multiple formats.

Why suffix and not prefix ?

Currently ID Generator allows calling client to provide a prefix of arbitrary length. This prefix is attached to the base format. There is no restriction on length of this prefix and hence adding type as a prefix would be ambiguous during parsing.

Will suffix work in all scenarios ?
A fundamental assumption is taken that any ID generated by ID Generator today is using the Default Formatter (This should always be the case). This formatter uses exactly 22 characters (and starts with a numeric value). Prefix is expected to be alphabetical. Under these assumptions, adding a two-char suffix would work deterministically. If the prefix contains numeric characters as suffix, this implementation would break the parsing logic.

One such use case is to reduce granularity of time to second (in order to pre-generate IDs in a pool and cache them in memory). Sample PR for this -#61.

@santanusinha
Copy link
Contributor

Please explain the changes @CyberDrudge .. I have zero context

@r0goyal r0goyal changed the title Add Parser Registry Add Type Registry for IDs Jun 9, 2025
@santanusinha santanusinha merged commit 073c34d into appform-io:main Jun 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants