Skip to content

Use monotonic ULIDs as the default node ID generator #318

Description

@johannesmutter

Currently, Session.generate_id() falls back to crypto.randomUUID() when no custom generate_id function is provided.

I think monotonic ULIDs would be a better default.

Why?

Svedit treats node IDs as opaque strings, but all the applications I have built on top of Svedit store nodes as standalone records rather than as a single document JSON. In those systems, documents are simply arrays of node IDs, and nodes such as quotes, tasks, or figures become first-class objects that can be viewed/ searched independently.

Using monotonic ULIDs provides a few nice properties at essentially no cost:

  • IDs are lexicographically sortable by creation time.
  • Creation order can be recovered without requiring a separate createdAt field.
  • Simpler implementation of views like "All Quotes", "Recently Created Blocks", etc.
  • Better database index locality compared to random UUIDs.
  • Shorter IDs (26 characters vs. 36 for UUIDs).

Monotonic ULIDs (vs. regular ULIDs) also preserve ordering when multiple IDs are generated within the same millisecond.

Downsides

  • Requires a small ULID implementation (either via the ulid package or an embedded implementation).

Migration

  • Existing applications could override generate_id if they want to keep the old uuid

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions