Dis.Uuid 1.1.0

Dis.Uuid

NuGet Downloads License

A high-performance .NET library for generating UUID version 7 (UUIDv7) identifiers with time-ordering capabilities.

๐ŸŽฏ What is UUID v7?

UUID version 7 is a time-ordered UUID variant that combines:

  • 48-bit timestamp (millisecond precision)
  • 12-bit random data for sub-millisecond ordering
  • 62-bit random data for uniqueness

This design ensures:

  • โœ… Chronological ordering - newer UUIDs are lexicographically greater
  • โœ… Database performance - excellent for primary keys and indexes
  • โœ… Global uniqueness - collision-resistant across distributed systems
  • โœ… Thread safety - safe for concurrent use

๐Ÿš€ Installation

dotnet add package Dis.Uuid

Or via Package Manager Console:

Install-Package Dis.Uuid

๐Ÿ“– Usage

using Dis.Uuid;

// Generate a new UUID v7
Guid id = UuidV7.New();
Console.WriteLine(id); // e.g., 018f-4230-1234-7000-abcdef123456

// Use in your models
public class Order
{
    public Guid Id { get; set; } = UuidV7.New();
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    // ... other properties
}

๐Ÿ”ง Features

  • High Performance: Uses Span<byte> and ThreadLocal<RandomNumberGenerator> for optimal performance
  • Thread Safe: Concurrent generation across multiple threads
  • Memory Efficient: Zero heap allocations during UUID generation
  • Standards Compliant: Follows RFC 4122 UUID v7 specification
  • .NET 8+ Optimized: Takes advantage of latest .NET performance improvements

๐Ÿ“Š Performance

UUID v7 generation is extremely fast and efficient:

// Benchmark example
var sw = Stopwatch.StartNew();
for (int i = 0; i < 1_000_000; i++)
{
    var uuid = UuidV7.New();
}
sw.Stop();
Console.WriteLine($"Generated 1M UUIDs in {sw.ElapsedMilliseconds}ms");

๐Ÿ”„ Time Ordering

One of the key benefits of UUID v7 is natural time ordering:

var id1 = UuidV7.New();
await Task.Delay(1); // Small delay
var id2 = UuidV7.New();

// id2 will always be lexicographically greater than id1
Assert.True(string.Compare(id1.ToString(), id2.ToString()) < 0);

๐ŸŽฏ Use Cases

Perfect for:

  • Database Primary Keys - Better performance than traditional UUIDs
  • Distributed Systems - Global uniqueness with time ordering
  • Event Sourcing - Natural chronological ordering of events
  • Logging Systems - Time-ordered log entries
  • Microservices - Consistent ID generation across services

๐Ÿ”’ Thread Safety

The library is fully thread-safe and can be used concurrently:

// Safe to use across multiple threads
var tasks = Enumerable.Range(0, 10)
    .Select(_ => Task.Run(() => 
    {
        var ids = new List<Guid>();
        for (int i = 0; i < 1000; i++)
        {
            ids.Add(UuidV7.New());
        }
        return ids;
    }));

var results = await Task.WhenAll(tasks);
// All generated UUIDs will be unique

๐Ÿงช Testing

The library includes comprehensive tests covering:

  • Uniqueness validation
  • Time ordering verification
  • Thread safety testing
  • Performance benchmarks

Run tests:

dotnet test

๐Ÿ“‹ Requirements

  • .NET 8.0 or higher
  • Compatible with all .NET 8+ workloads (Console, Web, Desktop, etc.)

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if needed
  5. Submit a pull request

๐Ÿ“„ License

This project is licensed under the BSD 3-Clause License - see the LICENSE.txt file for details.

๐Ÿ”— References


Made with โค๏ธ for the .NET community

No packages depend on Dis.Uuid.

v1.1.0: Added compatibility with .NET Standard 2.0 (supports .NET Core 2.0+, .NET Framework 4.6.1+)

.NET 6.0

  • No dependencies.

.NET 8.0

  • No dependencies.

Version Downloads Last updated
1.1.0 6 04/24/2026
1.0.0 3 04/24/2026