August 21, 2024

Introducing Auto-Scaling for Prisma Accelerate’s Connection Pool

Since its initial release, Prisma Accelerate has served close to 10 billion queries already! And it continues to get better: With the addition of auto-scaling, Prisma Accelerate is even better at helping applications scale and removing concerns about database connection bottlenecks.

Connection pooling using multiple instances of accelerate's connection poolers

Why connection pooling is important

Connection pooling is often overlooked or ignored for too long when it comes to database performance.

When starting out, you can manage without it. Even small database servers can handle 1 or 2 application servers establishing 5-10 connections. As you grow, better connection management is a quick and easy win.

Most assume a connection pooler is only needed for massive scale, but it's beneficial to implement it well before that!

The challenge with traditional database connections

When your application interacts with a database, it typically follows these steps:

  1. Open a TCP connection to the database
  2. Send queries to the database
  3. Close the TCP connection

This process repeats for every single database interaction. Opening and closing database connections is notoriously slow and resource-intensive because it requires authentication, 3-way-handshake and allocation of resources like memory and CPU.

Requests to the database from around the globe

This challenge is exacerbated in modern serverless and edge computing environments. In these scenarios, each individual function invocation attempts to establish a new database connection.

How connection pooling helps your application

Instead of opening and closing connections for every request, a connection pooler maintains a pool of open database connections that can be reused when future requests to the database are required.

The resulting process for database interactions works as follows:

  1. Request a connection from the pool manager
  2. Send queries to the database
  3. Return the connection to the pool

Using a connection pool:

  • Reduces overhead from constantly creating and closing connections
  • Improves response times for database operations
  • Helps manage traffic peaks without causing outages.
  • Scales effectively as your data and number of users grow.

Learn more about the benefits of connection pooling in our recent article: Saving Black Friday With Connection Pooling

Introducing auto-scaling for Prisma Accelerate

Since its launch last year, Prisma Accelerate has proven its production readiness by serving close to 10 billion queries. As we look to the next 100 billion, we’re looking to launch features that make Prisma Accelerate even more robust. With the addition of auto-scaling, Prisma Accelerate will be an even better fit for scaling any application!

How the new auto-scaling works

  1. When you enable Accelerate, you set a connection limit.
  2. Accelerate continuously monitors how many of those connections are actively being used.
  3. If more resources are needed to handle your application's traffic, additional resources will be allocated up to the connection limit you set.
  4. As traffic decreases, any additional resources will be removed.

Autoscaling Accelerate's connection pooling nodes

Scaling occurs horizontally by provisioning more connection pool instances as your load increases and your volume grows. This not only helps with spiky, unpredictable workloads but with growing applications meaning we can manage your volume at scale.

Setting the connection limit in Prisma Accelerate

In Prisma Accelerate, you can set the connection limit via the connection pool size drop down in the Connection Pool section found when enabling or updating the configuration for an existing Accelerate enabled environment:

Configuring Accelerate connection pool size in Platform Console

Visit the documentation to learn more about configuring the connection pool size for Accelerate.

Why setting the right connection limit matters

Setting the right connection limit matters when your application is under heavy load. Here’s why:

  • Resource allocation: Your set limit helps Accelerate allocate resources efficiently.
  • Performance indicator: It serves as a key metric for understanding your application's database interaction patterns.
  • Scaling efficiency: Proper limits ensure timely scaling, preventing bottlenecks before they impact performance.

Best practices for setting the connection limit

Here are some best practices that help you setting the right connection limit for your application.

  1. Set your connection limit: Analyze your application's needs and set connection limits accordingly. We recommend allocating about a third of your available connections to Accelerate to allow a buffer of connections to be used by other services needing to interact with your database. Note that Accelerate can briefly surge beyond the allocated connections to effectively manage schema changes or migrating to a new Prisma version.
  2. Adjust as needed: As your application grows, revisit and adjust your connection limits.

By understanding and leveraging connection limits, you're not just adjusting a configuration – you're directly influencing how Accelerate optimizes the performance for your application. Connection pooling isn't just for massive scale; it's a technique that can benefit applications at various stages of growth.

If you’re wondering if caching is another step you can take to improve application performance by reducing database round trips, you’re right and Accelerate supports that too! You can learn more about the benefits of databasse caching in our recent blog post: Speed and Savings: Caching Database Queries with Prisma Accelerate

Try Accelerate today to boost your application performance

If you want to see for yourself what performance gains you can get with Prisma Accelerate, check out the Accelerate Speed Test or get started using one of our starter projects.


Get started with Accelerate

Don’t miss the next post!

Sign up for the Prisma Newsletter