---
title: "Scaling serverless Postgres: How we implement autoscaling"
description: "Neon autoscales serverless Postgres by running each compute endpoint in a QEMU/KVM VM on Kubernetes (via its NeonVM controller) and hot-adding or removing CPU and memory based on load average."
url: "https://swe.quest/articles/scaling-serverless-postgres-how-we-implement-autoscaling-6cecd10b4a114371"
canonical: "https://neon.com/blog/scaling-serverless-postgres"
source: "Neon"
published: "2023-03-29"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 9
tags: ["postgres","serverless","kubernetes","virtualization","capacity-planning"]
---

# Scaling serverless Postgres: How we implement autoscaling

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-03-29, 9 min read, Deep dive. Original: [https://neon.com/blog/scaling-serverless-postgres](https://neon.com/blog/scaling-serverless-postgres)

## Summary

Neon autoscales serverless Postgres by running each compute endpoint in a QEMU/KVM VM on Kubernetes (via its NeonVM controller) and hot-adding or removing CPU and memory based on load average. A per-node autoscaler-agent makes scaling decisions but must get every upscale approved by a modified Kubernetes scheduler plugin, which acts as the single source of truth to prevent memory overcommit. Post-copy live migration (~100ms pauses) moves VMs off full nodes, kept cheap by separated storage. Inside each VM, a vm-informant uses cgroup memory.high notifications to freeze Postgres briefly (up to 20ms) while requesting more memory, and resizes a tmpfs-backed local file cache with 1MB LRU chunks that gave one user a 4x speedup.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [Kubernetes](https://swe.quest/tags/kubernetes.md) (Infrastructure)
- [Virtualization](https://swe.quest/tags/virtualization.md) (Infrastructure)
- [Capacity planning](https://swe.quest/tags/capacity-planning.md) (Reliability & operations)

## Prerequisites

- Kubernetes scheduling basics ([easy posts on Kubernetes](https://swe.quest/tags/kubernetes.md?difficulty=easy))
- Linux cgroups ([easy posts on Linux](https://swe.quest/tags/linux.md?difficulty=easy))
- virtual machines and hypervisors
- Postgres memory usage ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))

## Keywords

Neon, NeonVM, QEMU, KVM, autoscaler-agent, vm-informant, cgroups, live migration

## Related posts

- [Neon Autoscaling is Generally Available](https://swe.quest/articles/neon-autoscaling-is-generally-available-f402e1eef903aa23.md): Neon · 2024-08-26 · Easy · 6 min read · PostgreSQL, Serverless, Capacity planning, Kubernetes, Virtualization
  Neon's Postgres autoscaling is now generally available on all plans, including Free (up to 2 CPU, 8 GB RAM), adjusting CPU and memory to load between user-set minimum and maximum limits, with scale-to-zero.
- [1 Year of Autoscaling Postgres: How it’s going, and what’s next](https://swe.quest/articles/1-year-of-autoscaling-postgres-how-it-s-going-and-what-s-next-a75ce75d92118903.md): Neon · 2024-04-15 · Hard · 8 min read · PostgreSQL, Virtualization, Capacity planning, Memory management, Kubernetes
  Neon autoscales Postgres by running each instance as a VM in Kubernetes (NeonVM), with a per-node autoscaler-agent, a modified scheduler, and an in-VM vm-monitor that resizes the Local File Cache.
- [Autoscaling Lakebase Postgres](https://swe.quest/articles/autoscaling-lakebase-postgres-63257ef0753db067.md): Neon · 2026-08-31 · Hard · 12 min read · PostgreSQL, Capacity planning, Virtualization, Algorithms, Kubernetes
  Neon's Lakebase Postgres resizes compute in place about once every 81 seconds by taking the maximum of three target sizes: CPU load (one-minute average kept under 90%), memory (polled every 100 ms by an in-VM monitor and kept under 75%), and the working set of the compute cache.
- [How to reduce Postgres compute costs as you scale](https://swe.quest/articles/how-to-reduce-postgres-compute-costs-as-you-scale-00db750fe1e313ab.md): Neon · 2024-04-29 · Medium · 12 min read · PostgreSQL, Cost optimization, Capacity planning, Cloud platforms, Serverless
  Compute, not storage, usually dominates managed Postgres bills, and allocation-based services like Amazon RDS leave most provisioned capacity idle.
- [RAG With Autoscaling: Better Performance With Lower Costs For pgvector](https://swe.quest/articles/rag-with-autoscaling-better-performance-with-lower-costs-for-pgvector-52ce2e1857682b4f.md): Neon · 2024-08-27 · Medium · 4 min read · Vector search, PostgreSQL, Capacity planning, RAG & retrieval, Cost optimization
  Neon's autoscaling lets a Postgres instance scale up temporarily for the heavy memory and CPU demands of pgvector HNSW index builds, then scale back down, instead of being permanently overprovisioned.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
