P
Prisma•2w ago
xeno

Tips for using Neon + Pulse + tRPC for real-time updates

I'm on the Pro plan, which guarantees "real-time" updates, Neon setup completed, Prisma client initialized using withPulse() and everything looks like it is setup correctly. However, new events from Pulse seem to arrive either very late or not arrive at all, regardless if I'm using stream() or subscribe(). Here's my tRPC router:
onChanges: protectedProcedure.subscription(async function* ({ ctx }) {
const events = await ctx.db.modelToUpdate.subscribe();

console.log("Initializing Pulse subscription");

for await (const event of events) {
console.log("document event", event);

yield event;
}
}),
~
onChanges: protectedProcedure.subscription(async function* ({ ctx }) {
const events = await ctx.db.modelToUpdate.subscribe();

console.log("Initializing Pulse subscription");

for await (const event of events) {
console.log("document event", event);

yield event;
}
}),
~
And my frontend code:
const documentSubscription = api.xxx.onChanges.useSubscription(
undefined,
{
onData: (data) => {
console.log("Pulse update received");
}
}
);
const documentSubscription = api.xxx.onChanges.useSubscription(
undefined,
{
onData: (data) => {
console.log("Pulse update received");
}
}
);
It seems like subscribe() doesn't deliver any events, while stream() delivers them in order, but very very late (can be several minutes after the actual database update).
4 Replies
Prisma AI Help
Prisma AI Help•2w ago
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the #ask-ai channel awaits if you're curious!
xeno
xenoOP•2w ago
I keep seeing Pulse events arriving with really long delays and I'm not sure why that's happening
Nurul
Nurul•2w ago
Hey @xeno 👋 What is your email id or GitHub handle? I would like to take a look at logs for your workspace
xeno
xenoOP•2w ago
hi - it's [email protected] Using Neon, getting no error messages I thought it might be a tRPC issue, but other subscriptions I had never terminated by themselves. So my guess is
for await (const event of events) {
for await (const event of events) {
ends after a short while.

Did you find this page helpful?