Why We Shifted Away from Database-Generated IDs to 64‑Bit Integer IDs

The article explains how decoupling persistence from a specific database engine and moving ID generation to the domain layer using 64‑bit integer identifiers—leveraging the Twitter Snowflake algorithm and the IdGen library—improves scalability, reduces coupling, and avoids the storage overhead of UUIDs.

High Availability Architecture
High Availability Architecture
High Availability Architecture
Why We Shifted Away from Database-Generated IDs to 64‑Bit Integer IDs

The team building a SQL Server‑based data catalog needed to decouple the system, adhering to two core principles: preventing linear growth of complexity as features increase, and prioritizing customer needs, performance, query patterns, and business changes so components can be swapped as requirements evolve.

Inspired by the protoactor‑go motto "software should be composed, not built," they examined the impact of persistence coupling.

To avoid tying state persistence to a specific database engine, they decided not to pass persistence concerns to the domain layer; instead, persistence should appear in domain events, leading to varied storage requirements that can be addressed with patterns such as CQRS and DDD aggregates.

Relying on database‑generated auto‑increment keys couples the business layer to the storage system, making it hard to switch databases or scale horizontally, especially in distributed environments where different databases use different ID strategies.

The solution is to let the domain layer generate identifiers, representing them as unsigned 64‑bit integers. Domain consumers can choose how to serialize these IDs (e.g., as strings for client consumption), eliminating the need for database‑generated IDs.

While UUIDs are convenient, they incur higher storage and indexing costs. A 64‑bit integer generated via the Twitter Snowflake algorithm offers a more efficient primary‑key type for distributed systems. The team uses the open‑source IdGen library (Rob Janssen) for .NET to implement this approach.

References: Twitter ID documentation and the IdGen GitHub repository.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Distributed SystemsBackend ArchitectureID generation64-bit integerdatabase decoupling
High Availability Architecture
Written by

High Availability Architecture

Official account for High Availability Architecture.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.