Non-Sequential Identifiers are used in APIs to reference resources in a way that does not expose the internal database sequence or imply the number of resources. This approach enhances security, minimizes information leakage, and helps in maintaining a flexible architecture.

Details

Non-Sequential Identifiers (often referred to as UUIDs or GUIDs) replace predictable, sequential numeric identifiers (like incremental integers) typically used in database indexing. By using a non-sequential format, APIs make it harder for malicious users to infer information about the database or other resources. UUIDs, for instance, are 128-bit numbers that are practically unique and do not reveal the count or order of creation.

Common Pattern Names/Synonyms

  • UUIDs (Universally Unique Identifiers)
  • GUIDs (Globally Unique Identifiers)
  • Randomized Identifiers

Common Use Cases

  1. Secure Reference: Used in systems where exposing the count or sequence of database records could pose a security risk or violate privacy.
  2. Distributed Systems: Ideal for systems where resources need unique identifiers that must be generated independently across different systems without collision.
  3. Microservices Architectures: Helps in maintaining loose coupling between services by avoiding reliance on sequential IDs generated by a central authority.

Mermaid Sequence Diagrams

Below is a Mermaid diagram illustrating the process of generating and using non-sequential identifiers in an API request flow:

sequenceDiagram
    participant Client
    participant API
    participant Database

    Client->>API: Request to create new resource
    API->>Database: Generate non-sequential ID
    Database-->>API: Non-sequential ID created
    API-->>Client: Return resource with non-sequential ID

    Client->>API: Request resource by non-sequential ID
    API->>Database: Query resource by ID
    Database-->>API: Return resource details
    API-->>Client: Display resource details

Examples

  1. API Response with Non-Sequential ID:
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "type": "user",
  "attributes": {
    "name": "Jane Doe",
    "email": "jane.doe@example.com"
  }
}
  1. Generating a UUID in Java:
import java.util.UUID;

public class Main {
    public static void main(String[] args) {
        UUID newUserId = UUID.randomUUID();
        System.out.println("New User ID: " + newUserId.toString());
    }
}

Updated: