P
Prismaā€¢6d ago
xeno

Initializing a specific connection string for Prisma Pulse

I'm currently using Prisma + Neon w/ tRPC hosted on Vercel. My Prisma is initialized using the DATABASE_URL connection string, which is a pooled connection. Pulse requires a direct connection. Do I need to initialize a separate prisma instance for it to work, or will it work if I add a DIRECT_URL env variable to my deployment that contains the direct connection string (unpooled)?
15 Replies
Prisma AI Help
Prisma AI Helpā€¢6d ago
You selected to wait for the human sages. They'll share their wisdom soon. Grab some tea while you wait, or check out #ask-ai if you'd like a quick chat with the bot anyway!
Nurul
Nurulā€¢6d ago
Hey @xeno šŸ‘‹ Just responded to your email šŸ™‚ We can continue conversation here as well You would need to provide a direct connection string while configuring Pulse. Pulse relies on API Keys to connect to your provided connection string.
xeno
xenoOPā€¢6d ago
Hi, I'm asking specifically about connecting from the prisma client. Will it use the DIRECT_URL or does the DATABASE_URL have to be the direct connection?
Nurul
Nurulā€¢6d ago
Maybe I misunderstood your question. Please bear with me.
Pulse requires a direct connection.
You are correct. This requirement is for listening to database changes. I assume you have already provided a direct connection string while configuring Prisma Pulse. If you did that, then pulse will work as expected.
Iā€™m referring to connecting to Prisma Pulse from my application using Vercel.
I assume here you are referring to listening to Pulse events via subscribe/stream? You will not need to initialize a separate prisma instance for Pulse to work. It should work as expected. Just as an FYI, Pulse cannot be directly used in Frontend (Reference)
xeno
xenoOPā€¢6d ago
yes, understood. However, it seems like using Pulse from my backend using a pooled connection doesn't work (subscriptions don't work). When I changed my DATABASE_URL to remove the -pooled part from my Neon connection string, everything started working as expected.
Nurul
Nurulā€¢6d ago
Yes, that is expected. Prisma Pulse needs a direct connection string, not a -pooled one
xeno
xenoOPā€¢6d ago
That's what I was asking - will I need to initialize a separate prisma instance just for pulse? since the current prisma instance uses a pooled connection
Nurul
Nurulā€¢6d ago
I was referring to this step, using a pooled connection string here is not recommended and instead a direct connection string should be used. Did you pass a non-pooled connection string in this step? And then when you tried to subscribe to events, you weren't getting any?
No description
xeno
xenoOPā€¢6d ago
this step is all set, it has the direct connection string all good I'm referring to connecting from Prisma on the client side
Nurul
Nurulā€¢6d ago
Okay, that's great. The requirement for using a direct connection string was specific for this step, while setting up Pulse. It's not a requirement for listening/subscribing to events. That should work fine on a pooled connection string, but it looks like it didn't work for you. Did you get any errors?
xeno
xenoOPā€¢6d ago
No errors. Just no events whatsoever. It's been this way for months and I just got around to taking a look. I have multiple Neon databases setup with Pulse and it's the same for all of them.
Nurul
Nurulā€¢6d ago
Okay, thanks for reporting! I'll create a sample app to reproduce this behaviour. I'll use direct connection string while configuring pulse and will use a pooled connection string while listening for the events. I'll check with our Pulse team and will either document this behaviour it if this is expected or will fix it šŸ™
xeno
xenoOPā€¢6d ago
thank you. Another compounding factor is that it is deployed to vercel and the listener runs as a serverless function so the pooled connection might be interfering with the subscription socket
Nurul
Nurulā€¢6d ago
Noted. Are the listeners on Nextjs server actions or API routes? Or are these serverless functions deployed on some other platform?
xeno
xenoOPā€¢6d ago
API routes using tRPC. No other platform.

Did you find this page helpful?