Subscribe to the Timescale Newsletter

By submitting you acknowledge Timescale's  Privacy Policy.

Understanding Serverless PostgreSQL

Understanding Serverless PostgreSQL

One of the most popular and well-supported open-source databases, PostgreSQL has been a staple in the data management world for decades. As cloud computing evolves, serverless architectures are not just a trend but a growing reality, offering easy and efficient database scaling. Unsurprisingly, serverless PostgreSQL has become an enticing option for many organizations. But like any technological advancement, it comes with its own set of challenges and considerations.

This article explores serverless PostgreSQL's benefits, limitations, and strategies for maximizing its potential. 

What Is Serverless Architecture?

Hosting any software offers a range of options. On the left side is on-prem hosting, which requires physical hardware and active maintenance, resulting in high overhead. On the right-hand side of the scale is serverless, where most, if not all, of the infrastructure is entirely managed for you in the cloud.

A diagram with the differences of on-prem infrastructure (upfront cost and manual provisioning) vs. serverless cloud providers (pay-o-demand and automated provisioning)
The differences between on-premise and serverless cloud providers

Traditionally, when we want to use software like PostgreSQL, we first need the hardware to run it on. The old-school way would be to buy physical servers and manually run PostgreSQL. As we need more storage space, we would physically add more hard drives to the servers. We need to manually back up the data on the server onto a separate hard drive, preferring in a separate building, to prevent losing precious data due to, say, a house fire. Running any software this way has a significant upfront cost and maintenance overhead. 

Serverless systems are cloud-hosted solutions in which the cloud provider provides infrastructure as needed and is responsible for provisioning, scaling, applying security patches, providing backups, and maintaining it. In contrast, serverless PostgreSQL in a cloud environment relieves you from the manual tasks in traditionally hosted software, allowing you to focus on more strategic aspects of your work.

Using PostgreSQL in Serverless Systems

PostgreSQL's extensive support and vibrant community make it a compelling choice for a relational database system. When deployed on a serverless architecture, a PostgreSQL database can be the backbone of robust, responsive, and scalable products.

Serverless hosting services for PostgreSQL

Several cloud providers offer serverless PostgreSQL solutions. Popular options include:

  1. Amazon Aurora Serverless: AWS's solution provides on-demand, auto-scaling configuration for Amazon Aurora (Amazon's PostgreSQL service). It automatically starts, shuts down, and scales capacity based on your application's needs.
  2. Databricks SQL: Databricks offers a serverless SQL warehouse that automatically scales to meet your query demands, providing instant, elastic compute.
  3. Crunchy Bridge: Crunchy Data's fully managed PostgreSQL service includes auto-scaling capabilities and seamless integration with various cloud platforms.
  4. Timescale: Timescale provides a cloud-native PostgreSQL experience with intelligent scaling capabilities, which we'll explore in more detail later.

Benefits and limitations of serverless PostgreSQL

As with any architecture, choosing serverless PostgreSQL has its pros and cons.

Benefits

Opting for a serverless PostgreSQL setup comes with several advantages:

  1. Cost-effective baseline: As an open-source system, PostgreSQL is free to set up and use, eliminating licensing costs.
  2. Extensibility: PostgreSQL's broad base of extensions allows it to adapt to many use cases, making it a versatile choice for various applications.
  3. Community support: The large open-source community provides a wealth of support for troubleshooting and implementation ideas.
  4. Smooth scaling: Serverless architecture allows organizations to scale databases and use cases smoothly and automatically without the need to manage capacity in their cloud account.
  5. Reduced administrative overhead: With less infrastructure to manage, your team can focus on other critical tasks.
  6. Security is handled: In serverless, the hosting provider handles security patches to the servers and PostgreSQL instances.

Limitations

While serverless PostgreSQL offers numerous benefits, it's crucial to be aware of its limitations:

  1. Scaling challenges: PostgreSQL's complex internal structure is known to need help with substantial scaling scenarios.
  2. Performance impact of sharding: "Sharding", or splitting data into smaller chunks across multiple servers, can lead to significant performance loss.
  3. Architectural conflict: Serverless architectures are designed for arbitrary scaling by splitting across servers, which can conflict with PostgreSQL's inherent limitations.
  4. Cost considerations: Serverless systems generally have a higher price tag. For instance, Amazon Aurora Serverless can be up to 85 % more expensive than Amazon RDS.

PostgreSQL Scaling Solutions

The design of PostgreSQL and the serverless architecture's strategy of distributing databases across servers present an inherent challenge. However, taking advantage of a few general techniques built into PostgreSQL and Timescale can provide effective ways to scale a PostgreSQL database while maintaining performance.

Serverless scaling techniques

  • Intake scaling: Optimize your data ingestion (inserting data into PostgreSQL) process to handle increased load efficiently.
    • Ensure appropriate resources are allocated for data intake. At Timescale, we recommend matching CPU count with the number of ingest processes (eight ingest processes should run on eight CPU instances).
    • Put your client and server nearby; in cloud environments, this means they should be in the same region.
    • Use batch inserts to insert multiple rows per statement instead of row-by-row.
  • Storage assessment: Regularly evaluate your storage needs and optimize data retention policies.
  • Materialized views: Use materialized views to pre-compute and store the results of expensive queries.
  • Table partitioning: Divide large tables into smaller, more manageable chunks based on specific criteria to improve query performance.

While these techniques are powerful, they can be complex to manage and maintain, especially in a rapidly scaling environment.

PostgreSQL scaling with Timescale

Timescale is built entirely around PostgreSQL, which addresses many of the challenges associated with serverless PostgreSQL. While not the same as traditional serverless setups, Timescale provides similar scaling management and ease of use.

Some key features that set Timescale apart are:

  1. Hypertables: Timescale introduces the concept of hypertables, which automatically partition data across time and space—eliminating the need for manual sharding and reducing the performance impact often seen in traditional serverless PostgreSQL setups. Hypertables allow for efficient querying and insertion of time-series data, even at a massive scale.
  2. Continuous aggregates: Similar to materialized views without the downsides. Continuous aggregates in Timescale automatically update in the background, ensuring your pre-computed data is always up-to-date without manual intervention.
  3. Scalability: Timescale has demonstrated the ability to scale PostgreSQL up to the petabyte scale, showcasing its potential for handling massive datasets.

Through these features and more, Timescale Cloud can scale to any load without manual intervention while providing predictable, manageable pricing. It takes the ease of use and power of serverless without compromising on high costs.

In fact, compared to Amazon Aurora Serverless, Timescale Cloud overperforms in a series of aspects, being:

  • 35 % faster to ingest
  • 1.15x-16x faster to query in all but two query categories
  • 95 % more efficient at storing data
  • 52 % cheaper per hour for compute
  • 78 % cheaper per month to store the data created

Conclusion

Serverless offers significant ease of use and efficiency when scaling and maintaining databases, but it can present unique challenges for PostgreSQL. PostgreSQL's inherent design can conflict with the distributed nature of serverless setups, leading to potential performance issues and increased costs.

However, the right tools and strategies can overcome these challenges. Solutions like Timescale provide an intelligent approach to PostgreSQL scaling, offering many of the benefits of serverless architectures while addressing the specific needs of PostgreSQL databases. By leveraging features like hypertables, continuous aggregates, and dynamic scaling, Timescale Cloud takes the complexity out of managing large-scale PostgreSQL deployments. It lets you focus on deriving value from their data rather than wrestling with infrastructure management.

As with any technological decision, adopting a serverless PostgreSQL architecture should be based on your specific use case, scaling needs, and budget considerations. While serverless offerings from major cloud providers can be suitable for some scenarios, solutions like Timescale Cloud provide a compelling alternative that combines the best of both worlds—serverless's flexibility with PostgreSQL's power and familiarity.

Ready to experience the benefits of smart PostgreSQL scaling? Try Timescale Cloud for free today—no credit card required.

Ingest and query in milliseconds, even at petabyte scale.
This post was written by

Originally posted

Last updated

6 min read
PostgreSQL, Blog
Contributors

Related posts