Register PubSub as a provider using an injection token. In the mutation, publish the event after the write. In the subscription resolver method, return pubSub.asyncIterator() with the event name. The @Subscription() return type arrow function and the event payload key must match the asyncIterator event name.
Register PubSub with an injection token — inject it into resolvers via @Inject(PUB_SUB).
The object key in publish() must match the subscription field name: { postCreated: post }.
asyncIterator() argument must match the event name used in publish().
In-memory PubSub works only in single-process deployments — use Redis PubSub for multiple instances.
Publish after the database write completes — never publish on a failed or rolled-back write.
We need a simple real‑time chat feature where a client subscribes to new messages. Walk me through how you'd set up a GraphQL subscription using NestJS's PubSub in a single module.
If you forget to call pubSub.publish after creating a message, what will the subscriber see and why?
How would you write a unit test to verify that your subscription resolver receives the published events?
Our product team wants to add a subscription for order status updates, but the status changes are emitted from a separate microservice via a message queue. How would you integrate that with NestJS PubSub and what trade‑offs would you consider?
During a load test, you notice that some subscription events are being dropped. What debugging steps would you take in the NestJS GraphQL layer?
Explain why you might choose NestJS's built‑in PubSub versus an external Redis PubSub adapter in a mid‑scale deployment.
Design a scalable subscription system for a live dashboard that streams metrics from thousands of devices. How would you structure the PubSub, resolver, and any back‑pressure handling in NestJS?
What are the implications of using the default in‑memory PubSub in a horizontally scaled NestJS cluster, and how would you modify the architecture to support multiple instances?
How would you secure subscription connections to ensure only authorized users receive events, and what changes are needed in the GraphQL subscription handshake?
Our organization is moving from a monolith to a micro‑frontend architecture, and we need to migrate existing GraphQL subscriptions to a shared event bus. What architectural changes would you propose for the NestJS PubSub layer to avoid coupling and support versioned schemas?
Consider long‑term maintenance of subscription contracts across several teams. How would you establish a strategy for deprecating fields, handling breaking changes, and ensuring backward compatibility in the NestJS GraphQL subscription implementation?
If we wanted to replace the PubSub implementation with a cloud‑native service like AWS AppSync, what migration path would you outline, and what pitfalls should we watch for in the existing NestJS codebase?