Skip to main content
CREDEBL uses NATS as its inter-service message bus. Every microservice connects to NATS as a queue-group subscriber identified by its service name. The API Gateway connects as a client to dispatch requests, and each downstream service processes messages from its own named queue. The platform also uses NATS JetStream for durable event streams (aggregate events and DID notifications).

NATS server setup

The repository ships a minimal nats-server.conf:
nats-server.conf
The no_tls: true setting is suitable for local development and private networks. In production, configure TLS termination at a load balancer or enable TLS directly in nats-server.conf.

Docker Compose

Run a NATS server alongside the platform services:
docker-compose.yml
Set the corresponding environment variables to point services at the container:
.env

Authentication types

The auth type is controlled by NATS_AUTH_TYPE. The same value applies to every microservice unless overridden by NOTIFICATION_NATS_AUTH_TYPE for the notification service.
Each service authenticates with its own NKey seed. This is the recommended method for production deployments.
.env
The getNatsOptions helper in libs/common/src/nats.config.ts encodes each seed with TextEncoder and passes it to nkeyAuthenticator.
NKey seeds are private credentials. Generate a unique seed per service and rotate them if any seed is ever exposed.

Reconnection behavior

The platform configures automatic reconnection via the NATSReconnects enum (defined in libs/enum/src/enum.ts). The getNatsOptions function applies:

Service-to-subject mapping

Each microservice registers on NATS as a queue group using its service name constant from CommonConstants. The API Gateway acts as the sole publisher; services consume from their respective subjects.

JetStream configuration

JetStream provides durable, at-least-once delivery for event streams. Configure the stream names and consumer behavior with the following variables.
string
Name of the JetStream stream that carries aggregate domain events. Default: aggregate.
string
Name of the JetStream stream for DID creation notifications. Default: did-notify.
string
Name of the durable pull consumer attached to the streams above. Default: hub-pull-consumer.
number
How long (in nanoseconds) JetStream waits for an acknowledgement before redelivering a message. Default: 10_000.
number
Maximum number of delivery attempts before a message is considered dead-lettered. Default: 4.

Example JetStream environment block

.env

Notification service override

The notification service can use a different NATS auth type than the rest of the platform. This is useful when the notification pathway connects to a separate NATS cluster.
.env
When ENABLE_NATS_NOTIFICATION=false (the default), the NATS notification pathway is disabled regardless of NOTIFICATION_NATS_AUTH_TYPE.

How the API Gateway connects

The API Gateway bootstrap in apps/api-gateway/src/main.ts connects to NATS as a microservice transport:
apps/api-gateway/src/main.ts
getNatsOptions selects the authenticator based on NATS_AUTH_TYPE and assembles the server list from NATS_URL. Multiple NATS URLs (for clustering) are supported as comma-separated values.