<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/the-perils-of-uuid-primary-keys-in-sqlite-8u2vugae7" -->

---
title: The perils of UUID primary keys in SQLite | daily.dev
description: Using random UUID4s as primary keys in SQLite causes significant insert performance degradation — up to 14-16x slower than integer primary keys — due to random...
canonical: https://daily.dev/posts/the-perils-of-uuid-primary-keys-in-sqlite-8u2vugae7
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: The perils of UUID primary keys in SQLite | daily.dev
og:description: Using random UUID4s as primary keys in SQLite causes significant insert performance degradation — up to 14-16x slower than integer primary keys — due to random...
og:url: https://daily.dev/posts/the-perils-of-uuid-primary-keys-in-sqlite-8u2vugae7
og:image: https://api.daily.dev/og/posts/8U2vUGAe7.png
og:image:alt: The perils of UUID primary keys in SQLite
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# The perils of UUID primary keys in SQLite

**[Lobsters](https://daily.dev/sources/lobsters)** · 5 min read · 0 upvotes · 0 comments

## Summary

Using random UUID4s as primary keys in SQLite causes significant insert performance degradation — up to 14-16x slower than integer primary keys — due to random B-tree insertions forcing constant rebalancing. Benchmarks across 100 million rows compare four approaches: integer rowid (baseline ~1M inserts/sec), UUID4 WITHOUT ROWID (14-16x slower), UUID7 WITHOUT ROWID (time-ordered, nearly as fast as baseline), and UUID4 WITH ROWID (better than UUID4 WITHOUT ROWID but still slow due to random secondary index writes). The key takeaway: if you need UUID primary keys in SQLite, prefer time-ordered UUID7 to avoid B-tree thrashing.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://andersmurphy.com/2026/06/05/the-perils-of-uuid-primary-keys-in-sqlite.html>

## Similar posts on daily.dev

- [Avoid UUID Version 4 Primary Keys](https://daily.dev/posts/avoid-uuid-version-4-primary-keys-5pot7xhqf) · Hacker News · 79 upvotes · 10 comments
- [PostgreSQL 18: 23x Faster Inserts With UUID V7](https://daily.dev/posts/postgresql-18-23x-faster-inserts-with-uuid-v7-nc2q5uwx2) · Planet PostgreSQL · 19 upvotes · 1 comments

---

Tags: [#database](https://daily.dev/tags/database), [#sqlite](https://daily.dev/tags/sqlite), [#clojure](https://daily.dev/tags/clojure)

[View this post on daily.dev](https://daily.dev/posts/the-perils-of-uuid-primary-keys-in-sqlite-8u2vugae7)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"The perils of UUID primary keys in SQLite","url":"https://daily.dev/posts/the-perils-of-uuid-primary-keys-in-sqlite-8u2vugae7","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/the-perils-of-uuid-primary-keys-in-sqlite-8u2vugae7"},"datePublished":"2026-06-06T21:16:44.255Z","dateModified":"2026-06-06T21:17:06.495Z","description":"Using random UUID4s as primary keys in SQLite causes significant insert performance degradation — up to 14-16x slower than integer primary keys — due to random...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/fb1972ac739d2cb632889fc573e4823d?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/fb1972ac739d2cb632889fc573e4823d?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Lobsters","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Lobsters","logo":"https://media.daily.dev/image/upload/s--tl8v_Fku--/f_auto,t_logo/v1698841318/logos/lobste.jpg","url":"https://daily.dev/sources/lobsters"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/the-perils-of-uuid-primary-keys-in-sqlite-8u2vugae7","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"database,sqlite,clojure","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Lobsters","item":"https://daily.dev/sources/lobsters"},{"@type":"ListItem","position":3,"name":"The perils of UUID primary keys in SQLite"}]}
```

