TL;DR
Using random UUIDs as primary keys in SQLite can significantly degrade performance due to their unordered nature, causing excessive B-tree re-balancing. Alternatives like UUID7 or using rowid can mitigate these issues but come with trade-offs.
Recent performance tests reveal that using random UUIDs as primary keys in SQLite can cause severe slowdowns, with insert times increasing by up to 16 times compared to integer keys, raising concerns for developers relying on UUIDs for distributed systems.
Benchmarks conducted in June 2026 show that inserting 10 million rows with UUID4 primary keys takes significantly longer than with integer primary keys—up to 16 times slower. The primary cause is the unordered nature of UUID4, which forces SQLite to constantly rebalance its B-tree structure, leading to increased I/O and processing overhead. Using UUID7, which is time-ordered, improves performance but remains slower than integer keys. When UUID4 is used with the default rowid, the performance is better than without rowid but still not optimal, due to the additional index overhead. These findings highlight a performance trade-off for developers choosing UUIDs for distributed or unique identifiers in SQLite databases.
Why It Matters
This matters because many developers adopt UUIDs for their uniqueness in distributed systems, but may not be aware of the performance costs in SQLite. Slow insert performance can impact application scalability and responsiveness, especially with large datasets or high throughput requirements. Understanding these pitfalls enables better database design decisions, such as opting for UUID7 or other strategies to optimize write performance.

Mastering SQLite with Python: From Basics to Advanced Techniques
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Background
UUIDs are widely used as primary keys in databases for their uniqueness, especially in distributed applications. In SQLite, the default primary key is a 64-bit integer rowid, which is sequential and efficient. However, many developers prefer UUIDs for their global uniqueness, often choosing UUID4 for randomness. Prior to these benchmarks, the performance implications of UUID randomness in SQLite were not well quantified, leading to potential unnoticed bottlenecks in production systems. Recent tests confirm that random UUIDs can cause significant performance degradation due to the way SQLite manages B-tree structures and clustered indexes.
“The unordered nature of UUID4 causes SQLite to constantly rebalance its B-tree, leading to performance penalties.”
— source author
“Switching to UUID7 or using rowid-based primary keys can mitigate some of these performance issues, but trade-offs remain.”
— database performance analyst
UUID7 generator hardware
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What Remains Unclear
While benchmarks clearly demonstrate performance issues with UUID4, the impact may vary depending on hardware, dataset size, and specific workload. The long-term effects of using UUID7 or other time-ordered UUID variants in different database configurations are still being evaluated, and real-world applications may experience different bottlenecks.
high performance database primary keys
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
What’s Next
Developers should consider testing their own workloads with alternative UUID versions or primary key strategies. Future updates may include optimized UUID implementations or database features to better handle unordered keys. Ongoing research will clarify best practices for balancing global uniqueness and performance in SQLite and other embedded databases.
SQLite indexing and clustering tools
As an affiliate, we earn on qualifying purchases.
As an affiliate, we earn on qualifying purchases.
Key Questions
Why do UUID4 primary keys cause slowdowns in SQLite?
Because UUID4 is random and unordered, it causes frequent rebalancing of the B-tree index, leading to increased I/O and slower inserts.
Can switching to UUID7 improve performance?
Yes, UUID7 is time-ordered, reducing the need for rebalancing, which improves insert speeds, though it may still be slower than integer primary keys.
Are there alternatives to UUIDs that maintain uniqueness without performance loss?
Using sequential or time-ordered UUIDs like UUID7, or relying on the default rowid primary key, can help balance performance and uniqueness.
Does this issue affect other databases besides SQLite?
Yes, the performance implications of random UUIDs extend to other databases that use clustered indexes, especially when UUIDs are used as primary keys.
Source: Hacker News