NeonN
Neon9mo ago
2 replies
accused-moccasin

Best Method for Connecting to Neon from Serverless Functions Using Drizzle ORM

I'm building a Remix app hosted on Vercel and also running some AWS Lambda functions. I'm trying to determine the best way to connect to my Neon database using Drizzle ORM in a serverless environment.

Currently, I'm evaluating two approaches:

Here are the options I am currently looking at.

Option 1: WebSocket Connection
import { neonConfig, Pool } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-serverless';
import { WebSocket } from 'ws';
import * as schema from '~/.server/db/schema';

neonConfig.webSocketConstructor = WebSocket;

const pool = new Pool({ connectionString: process.env.DATABASE_URL });

const db = drizzle(pool, { schema });

export default db;


Option 2: HTTP Connection
import { drizzle } from 'drizzle-orm/neon-http';
import * as schema from '~/.server/db/schema';

const db = drizzle(process.env.DATABASE_URL, { schema });

export default db;


I'm looking for advice on the pros and cons of each approach, particularly in the context of high-concurrency workloads. For example, in a scenario where many AWS Lambda functions are triggered simultaneously to handle a high volume of incoming webhooks—each requiring a DB query—is there a recommended approach?

Any input or experience with either method would be really appreciated!
Was this page helpful?