Channels
Named message streams with privacy modes, retention, and channel types
A channel is a named message stream. You publish messages to a channel and create subscriptions to receive them. Channels are the fundamental organising unit in npayload.
Channel types
| Type | Behaviour | Use case |
|---|---|---|
| Standard | Messages delivered to all subscribers in order | Event notifications, audit logs |
| Compacted | Key-value semantics; only the latest message per key is retained | Configuration state, inventory levels |
| Priority | Messages delivered in priority order | Task queues, alert escalation |
Standard channels
The default. Every message published is stored immutably and delivered to every active subscription.
const channel = await npayload.channels.create({
name: 'orders',
description: 'Order lifecycle events',
privacy: 'standard',
});Compacted channels
Compacted channels retain only the latest message per key. When a new message with the same key is published, the previous message is replaced. This is ideal for state that changes over time.
const channel = await npayload.channels.create({
name: 'inventory',
description: 'Current stock levels per SKU',
type: 'compacted',
});
// Later messages with the same key overwrite earlier ones
await npayload.messages.publish({
channel: 'inventory',
key: 'SKU-001',
payload: { quantity: 42 },
});Priority channels
Messages in priority channels are delivered in priority order rather than publish order. Higher priority messages are delivered first.
await npayload.messages.publish({
channel: 'alerts',
payload: { severity: 'critical', message: 'Database unreachable' },
priority: 10, // Higher = delivered first
});Privacy modes
Every channel has a privacy mode that controls who can read the message payload.
| Mode | Metadata | Payload | npayload can read? |
|---|---|---|---|
| Standard | Visible | Visible | Yes |
| Hybrid | Visible | Encrypted | No (payload only) |
| E2E | Encrypted | Encrypted | No |
Standard (default)
All features available. npayload can read payloads for routing, filtering, and schema validation.
{ privacy: 'standard' }Hybrid
Metadata (routing keys, timestamps, trace IDs) remains visible for routing and debugging. The payload is encrypted with keys that npayload does not hold.
{ privacy: 'hybrid' }E2E (end-to-end)
Zero-knowledge encryption. npayload cannot read the payload or metadata. Only the publisher and subscriber hold the decryption keys. Routing is limited to channel-level only.
{ privacy: 'e2e' }E2E mode disables payload-based filtering and schema validation because npayload cannot inspect the encrypted content.
Channel settings
| Setting | Default | Description |
|---|---|---|
retentionDays | 30 | How long messages are stored before automatic deletion |
maxMessageSize | 256 KB | Maximum payload size per message |
maxSubscriptions | 100 | Maximum number of subscriptions per channel |
const channel = await npayload.channels.create({
name: 'events',
settings: {
retentionDays: 90,
maxMessageSize: 524288, // 512 KB
maxSubscriptions: 50,
},
});Channel lifecycle
Channels have three states:
| State | Description |
|---|---|
| Active | Normal operation. Messages can be published and delivered. |
| Paused | Publishing is blocked. Existing subscriptions continue receiving queued messages. |
| Archived | Soft-deleted. No publishing, no delivery. Can be restored. |
// Pause
await npayload.channels.pause('orders');
// Resume
await npayload.channels.resume('orders');
// Archive (soft delete)
await npayload.channels.archive('orders');Cross-instance channels
When a channel spans multiple instances, npayload automatically replicates messages between them with exactly-once delivery guarantees.
Cross-instance channels enable:
- Multi-region messaging for data residency compliance
- Cross-organisation communication for B2B integrations
- Instance-to-instance routing with automatic discovery
Cross-region replication requires explicit data residency consent from both the source and destination organisations.
Next steps
- Messages to understand what flows through channels
- Subscriptions to learn how messages are delivered
- API reference for the full channels API
Was this page helpful?