Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 12 min read Deep dive hardMaster

Autoscaling Lakebase Postgres

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.

Assumes: Postgres shared buffersKubernetes schedulingHyperLogLog basicsseparation of storage and compute

Related posts

  • Dynamically estimating and scaling Postgres’ working set size

    Neon mediumAdept

    Neon autoscales Postgres compute to keep the workload's working set in memory, using a modified HyperLogLog whose register bits are replaced with timestamps so the number of distinct pages accessed can be estimated for any lookback window. A heuristic scans windows from a 5-minute offset up to one hour and treats the point where the estimate jumps sharply as the end of the current workload's plateau. Scaling then projects working set growth to avoid repeated cache evictions. In benchmarks this matched fixed-size compute performance at 30% lower cost, roughly tripled throughput on a bursty pgbench workload, and raised cache hit rate from 30-70% to 100% on a batch workload.

  • 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.

  • Scaling serverless Postgres: How we implement autoscaling

    Neon mediumAdept

    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.

  • 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.

  • 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.

The quest for software engineering knowledge.

Look:
Layout: