⚡ How I Made My Prisma Queries 10x Faster with Accelerate

Kean SernaKean Serna
3 min read

When I first built my app using Prisma, I was blown away by how clean and intuitive the ORM felt. But as my user base grew and data started to pile up, I noticed something troubling my queries were slowing down, and my server was feeling the heat. 🥵

That's when I discovered Prisma Accelerate and boom, my query performance skyrocketed. Here's how I supercharged my backend and made Prisma feel like it was on steroids (in a good way).

🧠 The Problem: Sluggish Queries and Bottlenecks

At first, everything was smooth. But as more records hit the database, things changed:

  • Pages took longer to load

  • Dashboards became laggy

  • API response times shot up

  • Users started noticing 👀

I tried optimizing indexes and tweaking my queries, but the improvements were minimal. I needed something smarter and more scalable.

💡 The Solution: Prisma Accelerate

Enter Prisma Accelerate a global edge caching layer for your database queries. It sits between your app and the database, caching and delivering data with blazing speed — especially for read-heavy apps.

The best part? It integrates seamlessly with your existing Prisma setup.

🛠️ Setup: Getting Accelerate Up and Running

Adding Prisma Accelerate was surprisingly painless:

1. Install the CLI

npx prisma accelerate init

2. Push Your Schema

npx prisma db push

3. Run with Accelerate

npx prisma accelerate dev

Now, just swap your Prisma client with Accelerate's wrapped client:

import { PrismaClient } from '@prisma/client/edge'
import { withAccelerate } from '@prisma/extension-accelerate'

interface PrismaEnv {
  DATABASE_URL: string
}

const prismaClientSingleton = (env: PrismaEnv) => {
  if (!env.DATABASE_URL) {
    throw new Error('DATABASE_URL must be provided for Prisma client')
  }

  const client = new PrismaClient({
    datasourceUrl: env.DATABASE_URL
  }).$extends(withAccelerate())

  return client as unknown as PrismaClient
}

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>

const globalForPrisma = globalThis as unknown as {
  prisma: PrismaClientSingleton | undefined
}

export function getPrisma(env: PrismaEnv): PrismaClient {
  const prismaInstance =
    globalForPrisma.prisma ?? prismaClientSingleton(env)

  // In non-production-like environments, cache the client
  if (typeof globalThis !== 'undefined') {
    globalForPrisma.prisma = prismaInstance
  }

  return prismaInstance
}

export type PrismaClientOrTx = Omit<PrismaClient, '$connect' | '$disconnect' | '$on' | '$transaction' | '$use' | '$extends'> | PrismaClient;
export const prisma: PrismaClient = getPrisma({ DATABASE_URL: process.env.DATABASE_URL! });

That's it — no major rewrites, no fuss. ⚡

🔬 The Results: Real Numbers, Real Impact

After enabling Accelerate, here's what I saw:

MetricBefore AccelerateAfter Accelerate
Avg Query Time450ms35ms
P95 Response Time900ms100ms
DB CPU LoadHighWay Lower
User ComplaintsFrequent 😩Gone 😎

That’s over a 10x speed boost, with zero code gymnastics.

🧵 Final Thoughts

If you're already using Prisma and dealing with growing pains, Accelerate is a no-brainer. It gave me the performance edge I needed, without migrating to another ORM or caching layer.

So if your Prisma queries are dragging their feet, give Accelerate a spin. You’ll thank yourself later.

Follow me on Hashnode: https://hashnode.com/Kean De La Serna

0
Subscribe to my newsletter

Read articles from Kean Serna directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kean Serna
Kean Serna