Scaling serverless Postgres: How we implement autoscaling
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.
Related posts
- Neon Autoscaling is Generally Available
Neon easyNovice
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. Each Postgres instance runs in its own VM managed inside Kubernetes by NeonVM, which supports live migration. A per-node autoscaler-agent checks metrics every 5 seconds, and a modified scheduler must pre-approve every upscale. Memory scaling moved from unstable cgroup memory.high signals to polling every 100ms, with swap added for bursty allocations. A resizable local file cache extends shared buffers and feeds scaling decisions. The recommended setup is a high limit with scale-to-zero disabled for production, and a low limit with scale-to-zero enabled for dev branches.
- 1 Year of Autoscaling Postgres: How it’s going, and what’s next
Neon hardMaster
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. Over the past year the team replaced cgroup memory.high event triggers with 100ms polling of memory usage for stability, and traced a 0-TPS stall to a kernel bug in ACPI memory hotplug that was fixed by upgrading the kernel. Next steps include sizing compute with a HyperLogLog estimate of working set from LFC page accesses, since a slightly larger cache can yield 10x gains. They are also adding swap, set up via mkswap/swapon on pre-created VMs, and disabling overcommit so up-front allocations like pgvector 0.6's parallel HNSW builds don't OOM.
- Autoscaling Lakebase Postgres
Neon hardMaster
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. The working set comes from a modified HyperLogLog that stores timestamps instead of bits, so it can estimate distinct pages for any window from 1 to 60 minutes. The algorithm then looks for a jump in that curve to find where the current workload ends, and projects growth forward to the next 20-second interval. Resizes are applied to running QEMU/KVM VMs via NeonVM, with a modified Kubernetes scheduler approving upscales, live migration when a node is full, and in-VM checks before any downscale.
- How to reduce Postgres compute costs as you scale
Neon mediumAdept
Compute, not storage, usually dominates managed Postgres bills, and allocation-based services like Amazon RDS leave most provisioned capacity idle. On RDS, costs fall through careful planning of instance count, multi-AZ use and instance size, through downsizing guided by CloudWatch metrics such as CPUUtilization and FreeableMemory, and through query tuning: EXPLAIN ANALYZE, indexes, materialized views, caching and fixing ORM N+1 queries. Manual resizing is slow, error-prone and causes downtime, so Neon positions its autoscaling (autoscaler-agent, a modified Kubernetes scheduler and NeonVM) and scale-to-zero autosuspend as the way to make compute spend track actual load.
- RAG With Autoscaling: Better Performance With Lower Costs For pgvector
Neon mediumAdept
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. On a 1M-row table, a sequential-scan similarity query took about 3 seconds, while an HNSW index cut it to about 1 ms. Building that index used 8 parallel workers and 8GB of maintenance_work_mem and produced a ~7.8GB index. Because maintenance_work_mem is allocated upfront, Neon backs it with disk swap so a small compute can accept an 8GB setting, swapping data back into memory as the autoscaler adds compute units.