Handle as Primary Identifier for APIs and Other Resources #438
malinthaprasan
started this conversation in
General
Replies: 1 comment
-
|
Why do we need an ID and UUID both? Both the ID and UUID are system generated and uneditable, so they are very similar. In general, we will use the handle to access resources through our API. So there doesn't seem be to be enough justification to maintain both an ID and a UUID. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Using UUIDs as URL Identifiers
Currently, UUIDs are used as identifiers in REST API URLs. This causes several issues:
URLs don't look nice: UUIDs like
550e8400-e29b-41d4-a716-446655440000are not user-friendly or memorable.Immutability limits flexibility: Users may want to rename or reorganize resources, but UUIDs cannot change. User-provided identifiers should be mutable.
Difficult lookup: Users cannot easily lookup resources using a human-readable identifier they provided.
Client integration complexity: External systems and API clients benefit from predictable, human-readable identifiers rather than opaque UUIDs.
Why Not Just Replace UUID with Handle?
We cannot simply replace the current UUID with a user-provided handle because:
The Three Identifier Problem
This leads to having three identifiers per resource:
This raises questions about which identifier to use in each layer and how to handle conversions between them.
Solution
Adopt a handle-first approach where:
handle,uuidinstead ofid)Types of Identifiers
There are three types of identifiers for each resource:
1. ID (Integer)
2. UUID
Example Use Case:
When API analytics data is published to an external system, events include both
uuidandhandle. Even if the handle changes later, the external system can still uniquely identify the API using the immutable UUID.3. Handle
Naming Conventions
REST API Layer
The
{id}in URL paths is interpreted as the handle.Resource Operations
Sub-Resource Operations
Resource Model
{ "id": "my-resource", "orgId": "my-org", "name": "My Resource" }Sub-Resource Model
{ "id": "my-sub-resource", "resourceId": "my-resource", "orgId": "my-org", "name": "My Sub Resource" }Backend Code Conventions
From the service layer onwards, use explicit variable names to avoid confusion:
id(ambiguous)handleoruuid(explicit)apiIdapiHandleorapiUUIDresourceIdresourceHandleorresourceUUIDSample SQL Schema
Layer-Specific Patterns
Repository Layer
The repository layer works with handles for resource identification:
Service Layer
The service layer provides handle-based operations as the primary interface:
Handle-Based Core Pattern
All primary operations use handles directly:
UUID-to-Handle Resolution Pattern
UUID-based service methods should resolve the UUID to handle once, then delegate to handle-based methods:
Sub-Resource Operations
For sub-resources, the same pattern applies. Handle-based operations are core, UUID-based operations resolve to handles first.
Repository Layer
Service Layer
Handle-Based Core Pattern
UUID-to-Handle Resolution Pattern
Beta Was this translation helpful? Give feedback.
All reactions