# PacketId

**Kind:** Interface

**Source:** [`packages/microservices/interfaces/packet.interface.ts`](https://github.com/nestjs/nest/blob/master/packages/microservices/interfaces/packet.interface.ts#L1)

**Part of:** [Microservices](subsystem-packages-microservices)

`PacketId` defines the minimal identifier shape for a microservice packet. It provides a string `id` field that can be used to correlate packets, route responses, and track requests across transport boundaries.

## Properties

| Property | Type |
|---|---|
| `id` | `string` |

## Diagram

```mermaid
graph LR
  Client[Client or Service] --> Packet[Packet]
  Packet --> PacketId["PacketId<br/>id: string"]
  Packet --> Transport[Microservice Transport]
  Transport --> Handler[Message Handler]
```

## Usage

```ts
import type { PacketId } from './interfaces/packet.interface';

function createPacketId(id: string): PacketId {
  return { id };
}

const packetId: PacketId = createPacketId('request-8f4c2a');

console.log(packetId.id);
// request-8f4c2a
```

## AI Coding Instructions

- Use `PacketId` whenever a packet requires a stable string identifier for correlation or tracking.
- Generate IDs that are unique within the relevant transport or request lifecycle, such as UUIDs or trace IDs.
- Preserve the original `id` when forwarding, retrying, or responding to a packet unless a new correlation scope is intended.
- Do not add packet payload or routing fields to `PacketId`; compose it with other packet interfaces or types instead.
