nestjs-integration-patterns
Step 6 of the pipeline (WORKFLOW.md), for the edges of a NestJS service that the module-and-DTO basics do
not cover. The sections are independent. They share one premise: each edge has its own error channel,
its own lifecycle and its own idea of "done", and the HTTP defaults of Nest do not carry over. A filter
written for HTTP is skipped by a message handler; a request that ends does not end the work started for it;
a global setting does not reach a connected microservice. Every section states the principle, then the Nest
mapping. It extends nestjs-node-conventions (layout, DTOs), nestjs-reliability (idempotency, outbox,
resilience), nestjs-di-traps (injection) and api-design (contract rules).
When
- A handler is reached by a broker, a socket, an event stream or a webhook rather than an HTTP request.
- The API gets a second version, an OpenAPI document, or an endpoint is being retired.
- A reusable module takes options, scans providers for metadata, or loads on demand.
- A queue, a limiter, or a search index is added and its failure behaviour has not been decided.
- Request logs have to carry an id across the service.
Steps
Read only the sections the task meets.
| § |
Covers |
Read it when |
File |
| 1 |
Microservice transports, WebSocket gateways, Server-Sent Events |
a handler is not an HTTP route |
01-transports.md |
| 2 |
Versioning, OpenAPI document and types, CLI plugin limits, deprecation signals |
the API surface or its documentation changes |
02-http-surface.md |
| 3 |
Dynamic modules, discovery, lazy loading |
a module takes options, scans metadata or loads late |
03-module-composition.md |
| 4 |
Outgoing and incoming webhooks |
a service sends or receives signed callbacks |
04-webhooks.md |
| 5 |
Queue retention and stalls, limiter failure policy, search-index dual write |
a queue, a rate limit or an index is introduced |
05-queues-limits-indexes.md |
| 6 |
Structured logging with request context |
logs must be correlated and safe |
06-request-logging.md |
Output / checkpoint
Each rule's edge was exercised, not read: a handler error was thrown on each channel and the caller saw the
intended answer (§1), the generated document was read after a change (§2), the module was built once with
sync and once with async options (§3), a signature was verified against a body altered by one byte and a
delivery was replayed (§4), a job was left to finish and to fail and the Redis footprint checked (§5), and a
request's id appeared on every line it produced (§6). A diff verified only through the happy HTTP path is
not verified.
Guardrails
- Never throw an HTTP exception from a transport handler and expect the caller to see it: use the
channel's own exception (§1.1, §1.4).
- Never verify a webhook signature on a re-serialised body (§4.5).
- Never leave finished queue jobs to the default retention in a long-lived service (§5.1).
- Never let a limiter's storage failure decide your availability by accident: choose open or closed per
route, on purpose (§5.3).
- Never log request payloads by default; redact (§6.4).
- The Nest packages for webhooks and outbox are described from the documentation only, and their minimum
versions and release status were not verified; check before relying on a mapping. Nothing here was
installed or run.
- Dependencies named here are named, not installed: whoever adds one runs the install, with the project's
package manager.
- Shutting an endpoint down, rotating a signing secret, replaying deliveries and purging a queue act on
other people's systems or in shared state: a human decision.
Origin
Rewritten from the NestJS documentation repository (MIT, the Nest 12 docs; the microservices, WebSockets,
SSE, versioning, OpenAPI, dynamic-module, discovery, lazy-loading, rate-limiting, queues and webhooks
chapters, each read in full before use), the BullMQ documentation, the nestjs-pino README (MIT), the
Standard Webhooks signing scheme as the Nest webhooks chapter describes it, and one API-guidelines chapter on
deprecation (CC BY 4.0, attribution in references/origin.md). 🟡: never run by us; open points are in
references/origin.md.
1---2name: nestjs-integration-patterns3description: "Use when a NestJS service wires itself to the outside: microservice transports (RpcException, request-response versus events, client timeouts, hybrid apps), WebSocket gateways and Server-Sent Events (exceptions, guards, scaling, teardown), URI/header versioning and the OpenAPI document (types, plugin limits, deprecation headers), dynamic modules, discovery and lazy loading, signed outgoing and incoming webhooks, queue job retention and stalled jobs, rate-limiter storage failure policy, search-index dual writes, and structured request logging with pino."4metadata:5 source: https://skillmd.com/skills/techmefr/nestjs-integration-patterns6---78# nestjs-integration-patterns910Step 6 of the pipeline (`WORKFLOW.md`), for the edges of a NestJS service that the module-and-DTO basics do11not cover. The sections are independent. They share one premise: **each edge has its own error channel,12its own lifecycle and its own idea of "done", and the HTTP defaults of Nest do not carry over**. A filter13written for HTTP is skipped by a message handler; a request that ends does not end the work started for it;14a global setting does not reach a connected microservice. Every section states the principle, then the Nest15mapping. It extends `nestjs-node-conventions` (layout, DTOs), `nestjs-reliability` (idempotency, outbox,16resilience), `nestjs-di-traps` (injection) and `api-design` (contract rules).1718## When19- A handler is reached by a broker, a socket, an event stream or a webhook rather than an HTTP request.20- The API gets a second version, an OpenAPI document, or an endpoint is being retired.21- A reusable module takes options, scans providers for metadata, or loads on demand.22- A queue, a limiter, or a search index is added and its failure behaviour has not been decided.23- Request logs have to carry an id across the service.2425## Steps2627**Read only the sections the task meets.**2829| § | Covers | Read it when | File |30|---|---|---|---|31| 1 | Microservice transports, WebSocket gateways, Server-Sent Events | a handler is not an HTTP route | [`01-transports.md`](./references/01-transports.md) |32| 2 | Versioning, OpenAPI document and types, CLI plugin limits, deprecation signals | the API surface or its documentation changes | [`02-http-surface.md`](./references/02-http-surface.md) |33| 3 | Dynamic modules, discovery, lazy loading | a module takes options, scans metadata or loads late | [`03-module-composition.md`](./references/03-module-composition.md) |34| 4 | Outgoing and incoming webhooks | a service sends or receives signed callbacks | [`04-webhooks.md`](./references/04-webhooks.md) |35| 5 | Queue retention and stalls, limiter failure policy, search-index dual write | a queue, a rate limit or an index is introduced | [`05-queues-limits-indexes.md`](./references/05-queues-limits-indexes.md) |36| 6 | Structured logging with request context | logs must be correlated and safe | [`06-request-logging.md`](./references/06-request-logging.md) |3738## Output / checkpoint39Each rule's edge was exercised, not read: a handler error was thrown on each channel and the caller saw the40intended answer (§1), the generated document was read after a change (§2), the module was built once with41sync and once with async options (§3), a signature was verified against a body altered by one byte and a42delivery was replayed (§4), a job was left to finish and to fail and the Redis footprint checked (§5), and a43request's id appeared on every line it produced (§6). A diff verified only through the happy HTTP path is44not verified.4546## Guardrails47- Never throw an HTTP exception from a transport handler and expect the caller to see it: use the48 channel's own exception (§1.1, §1.4).49- Never verify a webhook signature on a re-serialised body (§4.5).50- Never leave finished queue jobs to the default retention in a long-lived service (§5.1).51- Never let a limiter's storage failure decide your availability by accident: choose open or closed per52 route, on purpose (§5.3).53- Never log request payloads by default; redact (§6.4).54- The Nest packages for webhooks and outbox are described from the documentation only, and their minimum55 versions and release status were not verified; check before relying on a mapping. Nothing here was56 installed or run.57- Dependencies named here are named, not installed: whoever adds one runs the install, with the project's58 package manager.59- Shutting an endpoint down, rotating a signing secret, replaying deliveries and purging a queue act on60 other people's systems or in shared state: a human decision.6162## Origin63Rewritten from the NestJS documentation repository (MIT, the Nest 12 docs; the microservices, WebSockets,64SSE, versioning, OpenAPI, dynamic-module, discovery, lazy-loading, rate-limiting, queues and webhooks65chapters, each read in full before use), the BullMQ documentation, the nestjs-pino README (MIT), the66Standard Webhooks signing scheme as the Nest webhooks chapter describes it, and one API-guidelines chapter on67deprecation (CC BY 4.0, attribution in `references/origin.md`). 🟡: never run by us; open points are in68[`references/origin.md`](./references/origin.md).