All posts
uuidnanoiddatabases

UUID vs NanoID: Choosing IDs for APIs and Databases

Compare UUID v4, UUID v7, and NanoID for uniqueness, sortability, URL safety, and index performance.

SR

Suhail Roushan

June 20, 2026

·
1 min read

What you're really optimizing for

Primary keys need uniqueness first. After that, teams argue about length, sort order, and whether IDs should be guessable. There is no single winner — pick based on your storage and exposure model.

Quick comparison

Use this as a starting point:

  • UUID v4 — ubiquitous, random, not time-sortable; fine for most apps
  • UUID v7 — time-ordered, better B-tree locality for recent inserts
  • NanoID — shorter, URL-friendly alphabet; great for public slugs
  • Avoid sequential integers for public IDs if enumeration is a risk

Generate both on code.live

Generate bulk UUID v4 lists, try UUID v7 when you need sortable ids, or switch to the NanoID Generator when you want shorter public tokens. Copy what you need and move on — no SDK install required for a quick experiment.

Related posts

Written by Suhail Roushan — Full-stack developer. More posts on AI, Next.js, and building products at suhailroushan.com/blog.

Get in touch