Kubernetes is the dominant deployment platform for distributed applications, and identifier strategy matters more in a multi-pod, multi-service environment than in a monolith. This guide covers how Kubernetes itself uses UUIDs, and where UUID v7 adds value in applications running on Kubernetes.

How Kubernetes Uses UUIDs

Every Kubernetes resource — Pod, Service, Deployment, ConfigMap, and more — receives a metadata.uid field assigned by the API server at creation time. This is a UUID v4 value:

apiVersion: v1
kind: Pod
metadata:
  name: my-app-7d9f8b-xyz
  uid: "550e8400-e29b-41d4-a716-446655440000"  # UUID v4, assigned by kube-apiserver
  namespace: default

These UIDs are used internally for ownership references (e.g., ReplicaSet owning Pods), garbage collection, and event correlation in the Kubernetes control plane. They are not intended to be time-sortable — Kubernetes uses creationTimestamp for chronological ordering.

The Problem with UUID v4 Correlation IDs

When an application running in Kubernetes generates a UUID v4 for request tracing, log entries across pods look like:

pod-1: INFO [a3b8c2d1-...] Payment processed
pod-2: INFO [7f4e9a0b-...] Inventory reserved
pod-3: INFO [2c6d5e8f-...] Notification sent

Three random UUID v4 values — no way to determine which happened first without a separate timestamp. Log aggregators like Grafana Loki or Elasticsearch must sort by ingestion timestamp, which introduces clock skew issues when pods are on different nodes.

UUID v7 for Correlation IDs

Using UUID v7 as the correlation ID solves this:

pod-1: INFO [018fbe3a-4c5d-7000-...] Payment processed      ← ms 1730000000000
pod-2: INFO [018fbe3a-4c5d-7001-...] Inventory reserved     ← ms 1730000000001
pod-3: INFO [018fbe3a-4c5d-7002-...] Notification sent      ← ms 1730000000002

Sorting correlation IDs lexicographically gives chronological order. A single ORDER BY correlation_id query reconstructs the event sequence across all pods without requiring clock synchronisation or a central ordering service.

Generating UUID v7 in a Kubernetes Sidecar Pattern

A common pattern is a sidecar proxy (Envoy, Nginx) that injects a UUID v7 X-Request-ID header at the ingress point:

# Envoy config snippet
http_filters:
  - name: envoy.filters.http.lua
    typed_config:
      "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.LuaPerRoute
      inline_code: |
        function envoy_on_request(request_handle)
          if not request_handle:headers():get("x-request-id") then
            -- inject UUID v7 at ingress (requires lua uuid library)
            request_handle:headers():add("x-request-id", generate_uuid_v7())
          end
        end

For most applications, application-layer generation is simpler and more portable than sidecar injection.

OpenTelemetry and UUID v7 Trace IDs

OpenTelemetry defines trace IDs as 16-byte (128-bit) random values in the W3C traceparent header. The spec does not mandate a UUID format, but UUID v7 is a valid 128-bit value that satisfies OpenTelemetry’s requirements while adding temporal ordering.

Using UUID v7 as the OpenTelemetry trace ID:

import { v7 as uuidv7 } from 'uuid';
import { context, trace } from '@opentelemetry/api';

const traceId = uuidv7().replace(/-/g, ''); // 32-char hex = 16 bytes

The 32-char hex string is the wire format OpenTelemetry uses internally. UUID v7’s timestamp prefix means trace IDs sort chronologically in any backend that stores them as strings or bytes.

Kubernetes RBAC and UUID v7 Service Identities

Some service mesh implementations use UUIDs as workload identity tokens. UUID v7 is preferable for audit logs because the timestamp in the ID allows auditors to verify when a token was issued without a separate lookup.

Frequently asked questions

What UUID version does Kubernetes use for resource UIDs?

Kubernetes assigns UUID v4 to all resources via the metadata.uid field. For application-level correlation IDs — request IDs, trace IDs, event IDs — UUID v7 is preferable because its millisecond timestamp enables chronological sorting across pods without a central sequence service. The Kubernetes UID documentation explains the resource identity model.

Can UUID v7 replace a central sequence counter in distributed systems?

For most use cases, yes. UUID v7's millisecond timestamp gives approximate cross-node ordering without any coordination. Each node generates independently, and UUIDs sort in creation order to millisecond precision. For strict global ordering you still need clock synchronisation or a coordination layer — but UUID v7 handles the 99% case where millisecond-level ordering is sufficient.

Should I use v4 or v7?

Use v7 for database primary keys (time-sortable, index-friendly) and v4 for anything where creation order could leak information, like tokens or share links.

What UUID version does Kubernetes use for resource UIDs?

Kubernetes assigns UUID v4 identifiers to all resources (Pods, Deployments, Services, etc.) via the metadata.uid field. These are generated by the API server using a CSPRNG and are not time-sortable. For time-ordered correlation IDs within application code running in Kubernetes, use UUID v7 generated by the application — not the Kubernetes UID.

How do I use UUID v7 as a request correlation ID in Kubernetes?

Generate a UUID v7 in your application at the start of each request and propagate it through HTTP headers (e.g., X-Correlation-ID) to downstream services. Because UUID v7 embeds a millisecond timestamp, log entries tagged with the correlation ID are sortable by creation time across all pods — no separate timestamp field needed. The OpenTelemetry SpanContext spec defines how trace IDs should be propagated.