---
title: NATS
slug: telemetry-pipeline/nats
docTags: 
createdAt: 2025-04-21T01:01:45.582Z
---

# NATS Sink&#x20;

The **NATS** sink publishes **log events** to **NATS subjects**. This guide explains **what each parameter does**, and what it means operationally for reliability, performance, and security.

## Core Destination and Routing

### url (required)

NATS server URL to connect to.

What it controls:

- Which NATS cluster/broker worker connects to&#x20;
- Which port and protocol are used (defaults to port 4222 if omitted)&#x20;

Operational considerations:

- Wrong URL or blocked port leads to publish failures and buffer growth.&#x20;
- For HA, your NATS deployment may expose multiple URLs; ensure your configuration aligns with your cluster access strategy.&#x20;

### subject (required)

The NATS **subject** to publish messages to. This supports templating, enabling per-event routing.

What it controls:

- Message routing and subscription matching in NATS (subjects act like hierarchical topics)&#x20;
- Downstream fan-out behavior based on subscriber patterns (wildcards, prefix matches)&#x20;

Operational considerations:

- If you make the subject highly dynamic (e.g., per-host, per-container, per-namespace), you can create very high “subject cardinality,” which makes subscriber management and observability harder.&#x20;
- A stable subject taxonomy (few predictable patterns) is typically easier to operate.&#x20;

## Connection Identity

### connection\_name (optional, default: vector)

A human-readable name assigned to the NATS connection.

What it controls:

- How this client appears in NATS monitoring/observability tools&#x20;
- Easier troubleshooting (identifying which worker instance is connected)&#x20;

Operational note:

- Useful when many worker agents connect to the same NATS cluster.&#x20;

## Authentication

### auth (optional)

Defines how worker authenticates to NATS.

### auth.strategy (required when auth is configured)

Selects the authentication method:

- **user\_password:** traditional username/password&#x20;
- **token:** shared token authentication&#x20;
- **nkey:** NATS NKey public/seed-based auth (cryptographic identity)&#x20;
- **credentials\_file:** JWT-based credentials file authentication&#x20;

Operational considerations:

- Choose the strategy that matches your NATS security posture:&#x20;
  - token/user-password is simpler but typically weaker operationally (rotation, leakage risk).&#x20;
  - nkey/credentials\_file are more structured for secure environments (stronger identity model, better rotation practices).&#x20;

user\_password strategy

- **auth.user\_password.user:** username&#x20;
- **auth.user\_password.password:** password&#x20;

token strategy

- **auth.token.value:** token&#x20;

nkey strategy

- **auth.nkey.nkey:** public identity (conceptually like a public key / user identity)&#x20;
- **auth.nkey.seed:** private seed (conceptually like a private key)&#x20;

Operational caution:

- Treat seed as a high-value secret. Leakage enables impersonation.&#x20;

credentials\_file strategy

- **auth.credentials\_file.path:** path to the credentials file (JWT-based auth material)&#x20;

Operational note:

- This is commonly used in secured NATS setups with operator/account/user JWTs.&#x20;

## JetStream Mode (Optional Reliability & Dedup Layer)

### jetstream (optional)

If enabled, messages are published using **JetStream**.

jetstream.enabled (optional, default: false)

When enabled:

- The **subject must belong to an existing JetStream stream**.&#x20;

Operational impact:

- Enables durability and stronger delivery patterns compared to plain core NATS publish.&#x20;
- Requires JetStream to be provisioned correctly (streams, storage, retention, limits).&#x20;

jetstream.headers (optional)

Adds NATS headers to each message (JetStream-aware use cases).

jetstream.headers.message\_id (optional)

A unique message identifier (supports templating) used for **deduplication**.

Operational impact:

- If your pipeline can re-send the same event (retries, restarts), a stable message\_id helps JetStream deduplicate.&#x20;
- If the message\_id is not stable or not unique enough, dedup may be ineffective or may incorrectly deduplicate distinct events.&#x20;

## Buffering and Backpressure

### buffer (optional)

Controls how worker buffers events when NATS is slow/unreachable.

buffer.type (optional, default: memory)

- **memory:** highest performance, but buffered data is lost on crash/restart&#x20;
- **disk:** more durable across restarts; slower and needs disk sizing/IOPS planning&#x20;

buffer.max\_size (required)

Hard cap on buffer memory/disk usage.

Operational impact:

- Too small → backpressure/drops during short outages&#x20;
- Too large → long drain times and burst load when NATS recovers&#x20;

buffer.max\_events (optional; memory only, default: 500)

Event-count cap for memory buffers.

buffer.when\_full (optional, default: block)

Behavior when the buffer is full:

- **block:** backpressure upstream (preferred when you want to avoid data loss)&#x20;
- **drop\_newest:** drop incoming events (preferred when keeping the system responsive is more important than completeness)&#x20;

## Encoding (Message Payload Format)

### encoding (required)

Controls how a log event is serialized into bytes before publishing to NATS.

### encoding.codec (required)

Selects the output format (for example: json, text, logfmt, raw\_message, etc.).

Operational considerations:

- **json**: preserves structure, best for downstream parsing—larger payloads&#x20;
- **text / raw\_message**: simplest, smallest, but less structured&#x20;
- **logfmt**: human-friendly key/value format&#x20;
- Specialized formats (CEF, GELF, Avro, Protobuf, OTLP) should be chosen only if consumers expect them.&#x20;

### Field filtering and timestamps

- **encoding.only\_fields / encoding.except\_fields:** include/exclude fields to reduce size and prevent leakage of sensitive data&#x20;
- **encoding.timestamp\_format:** standardizes timestamp representation (important when downstream systems rely on strict formats)&#x20;

##

## Request / Publish Behavior Controls

### request (optional)

Controls concurrency, retries, timeouts, and rate-limiting for outbound operations.

Key settings:

- **request.concurrency (default: none):** fixed concurrency of 1 (predictable behavior)&#x20;
- **rate\_limit\_num / rate\_limit\_duration\_secs:** caps outbound rate&#x20;
- **retry\_attempts / retry backoff / timeout\_secs:** controls how aggressively worker retries when NATS is not accepting publishes&#x20;

Operational impact:

- More retries improve survivability but can amplify duplicates (especially without JetStream dedup) and increase backlog during outages.&#x20;
- Timeouts that are too low can cause unnecessary retries; too high can stall pipeline recovery.&#x20;

## TLS (Transport Security)

### tls (optional)

Controls TLS security for the NATS connection.

Key options:

- **tls.enabled:** enables TLS&#x20;
- **tls.ca\_file:** trust roots&#x20;
- **tls.crt\_file / tls.key\_file / tls.key\_pass:** client certificate authentication (mTLS), if required&#x20;
- **tls.server\_name:** SNI override&#x20;
- **tls.verify\_certificate / tls.verify\_hostname:** certificate and hostname verification&#x20;

Operational guidance:

- Do not disable verification in production unless you fully understand the security trade-off.
