August 10, 2023
Accelerate in Preview: Global Database Cache & Scalable Connection Pool
Prisma Accelerate is now available to everyone in Preview! Make your application faster with our powerful global cache and scalable connection pooler. Get started now, and let us know what you think.
Table of contents
- Cache query results close to your servers
- Supercharge serverless and edge apps with Accelerate's connection pool
- Boost your app performance and scalability
- Let us know what you think
Accelerate has transitioned from Early Access to public Preview! Now you can leverage the power of a managed global cache and connection pool with Prisma with support for 300 locations globally and use a connection pool with support for 16 regions.
Cache query results close to your servers
Accelerate ensures that cached query results are always served from the nearest cache node to the application server, resulting in faster response times. Accelerate's cache nodes are built with Cloudflare and are available in 300 locations worldwide.
This greatly benefits distributed, serverless, and edge applications as performance remains consistent regardless of the application server's location. This is because a cache node is always available closest to the application server, and when data is cached, large round trips to the database are avoided.
Accelerate cache nodes are available globallySuppose a database is located in North America, and a request is made to the database from a server in Japan. By using Accelerate to cache query results, the results can be retrieved from a cache in the same region of Japan, avoiding a round trip of about ~16,000 kilometers (considering the speed of light, there would be an additional latency of approximately 53 milliseconds) to fetch query results from the database in North America.
Programmatic control over cache behavior
Accelerate extends your Prisma Client with an intuitive API offering granular control over established caching patterns on a per-query basis. Utilise time-to-live (TTL) or state-while-revalidate (SWR) to fine-tune your cache behavior tailored to your application needs.
await prisma.user.findMany({ cacheStrategy: { ttl: 60, },});
Learn more about caching strategies in our docs.
To comply with regulations regarding the storage of personally identifiable information (PII) like phone numbers, social security numbers, and credit card numbers, you may need to avoid caching query results. Excluding the cacheStrategy
from your queries provides a straightforward way to opt out of caching your query results.
To understand the advantages and drawbacks associated with caching database query results, read the blog post Database Caching: A Double-Edged Sword? Examining the Pros and Cons.
Supercharge serverless and edge apps with Accelerate's connection pool
Accelerate seamlessly integrates with serverless and edge environments. While database connections are stateful, serverless and edge environments are stateless, making it challenging to manage stateful connections from a stateless environment.
In serverless environments, a sudden surge in traffic can spawn several ephemeral servers (also referred to as ‘serverless functions’) to handle requests. This results in each server opening up one or more database connections, eventually exceeding the database connection limit.
Learn more about the serverless connection management challenge here.
Accelerate's built-in connection pool can be deployed in the same region as your database. The connection pool helps you scale your application by persisting and reusing database connections, preventing the connection limit from being exceeded.
The connection pool is deployed in the database region, while the Accelerate cache nodes reside in the application region.Boost your app performance and scalability
Accelerate caches query results with incredible efficiency, allowing for lightning-fast retrieval of cached data with latencies as low as 5ms. The significant speedup provided by Accelerate is most noticeable when the results of complex, long-running queries are cached.
For example, a query that usually takes 30 seconds to process can be cached with Accelerate, resulting in a response time of approximately 5-20 milliseconds, providing a massive ~1000x speedup.
Queries with Prisma Client | Queries with Prisma Client and Accelerate without caching | Queries with Prisma Client and Accelerate with caching | |
---|---|---|---|
Description | Prisma Client connects directly to the database and executes the query | The query is routed through the connection pool instance hosted close to the database region | Accelerate caches the query |
Pros | • No need to write SQL • No additional service or component | • Built-in connection pooling for serverless and edge runtimes • Allows Prisma to be used in Edge Functions | • Built-in connection pooling for serverless and edge runtimes • Allows Prisma to be used in Edge Functions • Performance boost |
Cons | • Setting up and managing connection pooling for serverless/edge environments • Long round-trips in multi-region deployments | • Slight latency overhead due to routing query through Accelerate’s connection pooler | • Data may be stale |
Accelerate enables you to serve more users with fewer resources. Storing frequently accessed query results reduces the need for repeated database queries. This improves scalability and performance by freeing up the database to perform more tasks. Application servers can handle more requests if query results are cached because the queries respond faster. This can help accelerate your website's response times.
Test Accelerate's speed
Let us know what you think!
Get started to supercharge your application with Prisma Accelerate! Try it out and share your experience with us on Twitter or join the conversation in our community Slack or Discord communities in the dedicated #accelerate-feedback
channel.
Get started Read the docs