UUID v1 Generator

एम्बेडेड टाइमस्टैम्प के साथ टाइम-बेस्ड UUID v1 जनरेट करें

फ़ॉर्मेट करें

संख्या:
Note:UUID v1 host MAC address और generation timestamp embed करता है, जो अधिकांश modern applications के लिए privacy concerns raise करता है। नए projects के लिए, UUID v4 recommended है जब तक specifically time-ordered, decodable identifiers की ज़रूरत न हो।

UUID v1 क्या है?

UUID v1 original UUID version है, RFC 4122 (2005) में standardised। यह generating host के MAC address के साथ high-precision timestamp combine करके unique identifiers generate करता है, plus sub-timestamp resolution handle करने के लिए short clock sequence।

क्योंकि timestamp embedded है, same host से UUID v1 values time के साथ monotonically increasing हैं — naturally ordered। यह distributed systems के लिए designed था जहाँ हर node बिना coordination के independently UUIDs generate कर सके।

आज UUID v1 largely UUID v7 (sortable, no MAC leakage) और UUID v4 (fully random, private) द्वारा superseded है। यह Apache Cassandra जैसे systems में use में रहता है।

UUID v1 की Anatomy

UUID v1 string जैसे 550e8400-e29b-11d4-a716-446655440000 छह distinct fields encode करती है:

FieldSizeDescription
time_low32 bits60-bit Gregorian timestamp का 32-bit low field (Oct 15, 1582 से 100-nanosecond intervals)
time_mid16 bits60-bit timestamp का middle 16-bit field
time_hi_and_version16 bits60-bit timestamp के top 12 bits plus 4-bit version number (हमेशा <code>1</code>)
clock_seq_hi_res8 bits6-bit clock sequence high field combined with 2-bit RFC 4122 variant marker
clock_seq_low8 bitsClock sequence के lower 8 bits
node48 bits48-bit node identifier — typically generating network interface का MAC address, या यदि MAC available नहीं तो random 48-bit value

Clock sequence field (clock_seq_hi_res + clock_seq_low) एक 14-bit counter है। यह तब increment होता है जब system clock backward move करे (जैसे NTP adjustment) या system restart हो। यह prevent करता है कि duplicate UUIDs generate हों।

UUID v1 Timestamp को Decode करना

60-bit timestamp UUID में तीन fields में scattered है। Generation time reconstruct करने के लिए:

  1. time_low (bytes 0–3), time_mid (bytes 4–5), और time_hi (bytes 6–7, version nibble minus) extract करें
  2. Reassemble: (time_hi &lt;&lt; 48) | (time_mid &lt;&lt; 32) | time_low
  3. Result October 15, 1582 से 100-nanosecond intervals की 60-bit count है (Gregorian calendar epoch)
  4. Gregorian-to-Unix offset subtract करें: 122,192,928,000,000,000 (Oct 15 1582 और Jan 1 1970 के बीच 100-ns intervals)
  5. 100-nanosecond intervals को milliseconds में convert करने के लिए 10,000 से divide करें
  6. Date object construct करने के लिए Unix millisecond timestamp के रूप में use करें
  7. Human-readable output के लिए ISO 8601 के रूप में format करें

Timestamp precision 100 nanoseconds है — UUID v7 के millisecond precision से far finer। हालाँकि, practice में ज़्यादातर operating systems sub-millisecond clock resolution expose नहीं करते।

Privacy Concerns

UUID v1 का सबसे significant drawback यह है कि यह node field में generating host का MAC address embed करता है। इसका मतलब है हर UUID v1 machine की permanent, globally unique fingerprint carry करता है।

एक adversary जो UUID v1 obtain करे वो determine कर सकता है: (1) ID generate होने का approximate time, (2) generating host का MAC address, और (3) multiple UUIDs analyze करके IDs generate होने की rate।

इस कारण, UUID v1 को कभी भी public-facing identifier के रूप में use नहीं करना चाहिए जब तक आप यह information disclose करने में comfortable न हों।

UUID v1 कब Still Appropriate है

Apache Cassandra primary keys
Cassandra UUID v1 (TimeUUID type के माध्यम से) को core design pattern के रूप में use करता है। Timestamp ordering Cassandra के storage model में naturally map होती है, efficient time-range queries enable करती है।
Legacy distributed systems
UUID v7 exist करने से पहले (pre-2024) build किए गए systems जो timestamp-ordered UUIDs पर rely करते हैं और नए format में easily migrate नहीं कर सकते।
Audit और event logs
जब generating host identity known और trusted हो, MAC address embed करना audit events के लिए additional traceability provide कर सकता है।
Internal identifiers
IDs जो controlled internal system के बाहर कभी exposed नहीं होते, जहाँ MAC address disclosure concern नहीं है।
Separate timestamp column के बिना time-range queries
Embedded timestamp को generation time के अनुसार rows filter करने के लिए decode किया जा सकता है, combined ID और timestamp के रूप में acting।
Older UUID v1 generators के साथ interoperability
External systems से UUID v1 values receive या process करते समय जो उन्हें produce करते हैं, display या analysis के लिए embedded timestamp decode करना।

UUID v1 vs UUID v7

UUID v7 time-ordered identifiers के लिए UUID v1 का modern successor है। यहाँ direct comparison है:

AspectUUID v1UUID v7
Epoch / Time BaseGregorian epoch (Oct 15, 1582)Unix epoch (Jan 1, 1970)
Precision100 nanoseconds1 millisecond
Node IdentifierMAC address (host identity leak करता है)Random (private)
PrivacyMAC address और generation timestamp leak करता हैकोई host information embedded नहीं
DB index performanceGood — per host sequentialExcellent — सभी generators में k-sortable
StandardRFC 4122 (2005)RFC 9562 (2024)

नए projects के लिए, UUID v7 UUID v1 के लिए recommended replacement है। यह similar time-ordering guarantees provide करता है बिना host MAC address embed करने के privacy implications के।

Code Examples

UUID v1 generation browsers या Node.js में natively available नहीं है। uuid npm package use करें:

JavaScript (browser)
// Generate a UUID v1 using the Web Crypto API
function generateUuidV1() {
  const buf = new Uint8Array(16)
  crypto.getRandomValues(buf)

  const ms = BigInt(Date.now())
  const gregorianOffset = 122192928000000000n
  const t = ms * 10000n + gregorianOffset

  const tLow   = Number(t & 0xFFFFFFFFn)
  const tMid   = Number((t >> 32n) & 0xFFFFn)
  const tHiVer = Number((t >> 48n) & 0x0FFFn) | 0x1000  // version 1

  const clockSeq    = (buf[8] & 0x3F) | 0x80  // variant 10xxxxxx
  const clockSeqLow = buf[9]

  const hex  = (n, pad) => n.toString(16).padStart(pad, '0')
  const node = [...buf.slice(10)].map(b => b.toString(16).padStart(2, '0')).join('')

  return `${hex(tLow,8)}-${hex(tMid,4)}-${hex(tHiVer,4)}-${hex(clockSeq,2)}${hex(clockSeqLow,2)}-${node}`
}

// Extract the embedded timestamp from a UUID v1
function extractTimestamp(uuid) {
  const parts = uuid.split('-')
  const tHex = parts[2].slice(1) + parts[1] + parts[0]
  const t = BigInt('0x' + tHex)
  const ms = (t - 122192928000000000n) / 10000n
  return new Date(Number(ms))
}

const id = generateUuidV1()
console.log(id)                      // e.g. "1eb5e8b0-6b4d-11ee-9c45-a1f2b3c4d5e6"
console.log(extractTimestamp(id))    // e.g. 2023-10-15T12:34:56.789Z
Python
import uuid
from datetime import datetime, timezone

# Generate UUID v1 (uses MAC address by default)
uid = uuid.uuid1()
print(uid)

# Extract embedded timestamp
# uuid.time is 100-ns intervals since Oct 15, 1582
GREGORIAN_OFFSET = 122192928000000000  # 100-ns intervals
ts_100ns = uid.time
ts_ms = (ts_100ns - GREGORIAN_OFFSET) // 10000
dt = datetime.fromtimestamp(ts_ms / 1000, tz=timezone.utc)
print(dt.isoformat())   # e.g. "2023-10-15T12:34:56.789000+00:00"
Go
package main

import (
    "fmt"
    "time"

    "github.com/google/uuid"  // go get github.com/google/uuid
)

func main() {
    id, _ := uuid.NewUUID()  // UUID v1
    fmt.Println(id)

    // Extract timestamp from UUID v1
    // uuid.Time is 100-ns ticks since Oct 15, 1582
    t := id.Time()
    sec  := int64(t)/1e7 - 12219292800  // convert to Unix seconds
    nsec := (int64(t) % 1e7) * 100
    ts   := time.Unix(sec, nsec).UTC()
    fmt.Println(ts.Format(time.RFC3339Nano))
}

अक्सर पूछे जाने वाले प्रश्न

क्या मैं UUID v1 से timestamp decode कर सकता हूँ?
हाँ। Generation timestamp UUID v1 string से fully recoverable है। यह tool exactly वही करता है — कोई भी UUID v1 paste करें और यह decoded UTC timestamp display करेगा।
क्या MAC address UUID v1 में हमेशा present होता है?
ज़रूरी नहीं। RFC 4122 implementations को MAC address के लिए randomly generated 48-bit value substitute करने की permission देता है। Browser-generated UUID v1 values हमेशा random node value use करती हैं।
UUID v1 timestamp 1582 को epoch के रूप में क्यों use करता है?
Gregorian calendar reform October 15, 1582 को effective हुई। 60-bit timestamp field की range approximately 3400 AD तक unique रहने के लिए sufficient है।
UUID v1 vs UUID v7 — मुझे अभी भी v1 कब use करना चाहिए?
UUID v1 use करने का primary reason existing systems के साथ compatibility है — particularly Apache Cassandra जो v1 को अपना TimeUUID type के रूप में use करता है। सभी नए systems के लिए, UUID v7 strictly better है।
क्या UUID v1 values collide कर सकती हैं?
Theory में, अगर same MAC address same 100-nanosecond interval में दो UUIDs generate करे और clock sequence identical हो। Clock sequence precisely इसे prevent करने के लिए exist करता है। Correctly implemented systems में collisions extremely rare हैं।