Accelerate & Edge — Series 3

Preview — 3 of 10 questions

What does passing cacheStrategy: { ttl: 60, swr: 300 } to a Prisma Accelerate-enabled query do?

javascript
await prisma.product.findMany({
  cacheStrategy: { ttl: 60, swr: 300 },
});
AAccelerate caches this query's result at its global edge layer: for 60 seconds (ttl), cached results are served directly with no database hit at all; for the next 300 seconds after that (swr, stale-while-revalidate), a still-slightly-stale cached result is served immediately while Accelerate refreshes it in the background, rather than making every caller wait on a fresh database round-trip
BIt's purely a client-side hint with no effect on the actual database round-trip; caching must still be implemented manually
Cttl and swr configure how long Prisma retries a failed connection before giving up
DThis syntax only works for raw SQL queries ($queryRaw), never for the regular query builder methods like findMany

Prisma Pulse lets application code subscribe to real-time database change events (prisma.user.subscribe(...)). What PostgreSQL mechanism does it rely on under the hood to know about changes as they happen?

APulse is built on PostgreSQL's logical replication — the same underlying mechanism (publications, replication slots, decoded WAL) covered in the replication material — capturing row-level change events as they're written and streaming them out to subscribed application code, rather than repeatedly querying the whole table for changes
BPulse polls the entire table on a fixed interval, checking for any differences since the last poll
CPulse requires a separate message queue (like Kafka) to be manually wired up as a prerequisite; it has no direct database-level mechanism of its own
DPulse works by attaching a SELECT ... FOR UPDATE lock to every row an application subscribes to

Why can't a Prisma Client using the standard PostgreSQL connection normally work directly inside an Edge runtime (like Vercel Edge Functions or Cloudflare Workers), without Accelerate or a driver adapter?

AEdge runtimes are deliberately restricted, lightweight execution environments that typically don't provide raw TCP socket access — but PostgreSQL's native wire protocol (which Prisma's standard connection mechanism relies on) requires exactly that. Prisma Accelerate works around this by proxying the connection over HTTP (which Edge runtimes do support); certain driver adapters (built on HTTP- or WebSocket-based drivers for specific providers) solve the same problem differently
BEdge runtimes don't support JavaScript at all, only WebAssembly
CEdge runtimes only support MySQL, never PostgreSQL, for any client library
DThis limitation was fully removed as of the most recent Prisma version, and no workaround is needed anymore

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.