Sacred Lantern Studio
2026-11-12· 9 minInfrastructureNext.jsCostOps

Next.js on a 2-core, 2 GB server: 182 MB at runtime, 1.3 GB during build

Measured on a real 60-page bilingual site: runtime memory is 182 MB, but the build peaks at 1342 MB — 78% of a 2 GB box. On a small VPS the bottleneck is deployment, not traffic. Full numbers, disk usage and sizing guidance.

Ask "what spec do I need for a website" and you get "it depends". That answer is useless.

So I instrumented my own site: 60 pages, bilingual, Next.js 16, running on a 2-core / 2 GB instance. Here is every number.

Short version: 2 GB is generous at runtime and tight during build.


The setup

Item Value
CPU 2 cores
RAM 1711 MB (about 1047 MB available after kernel overhead)
Disk 50 GB, 15 GB used (32%)
OS Ubuntu 24.04 LTS
Node v20.20.2
Next.js 16.2.9
Pages 60 (bilingual, all pre-rendered)
Reverse proxy Caddy
Process manager PM2

What it costs per month isn't the interesting part. What matters is whether this box holds up.


Runtime: 182 MB, basically idle

The Next.js process under PM2 sits at 182 MB resident.

Machine-wide:

              total   used   free   buff/cache   available
Mem:           1711    664    682          522        1047

664 MB is in use, but most of that is the OS, Caddy and log rotation. Next.js itself is 182 MB.

Response times:

Server-local (127.0.0.1:3100)   TTFB 4–5 ms
x-nextjs-cache                  HIT
Cache-Control                   s-maxage=31536000

Pages are statically pre-rendered and served from cache — no React rendering per request, no database pool, no per-request work.

Runtime is not the constraint.


Build: 1342 MB peak, and that's the real problem

Same site, npm run build, sampling memory once per second:

Baseline      676 MB
Peak         1342 MB        ← 78% of total RAM
Build time    27 s (12.4 s compiling)

On a 2 GB box that leaves 369 MB of headroom.

Why it matters: double the page count to 120, or add a few heavy dependencies, and the build gets OOM-killed. The error is usually just Killed or a webpack crash with no useful message — people spend hours debugging code that was never the problem.

Why builds are memory-hungry

A Next.js build has to:

  1. Compile every page to JS
  2. Statically generate each route
  3. Produce the sitemap, optimise images, analyse the dependency graph
  4. Minify and emit server output

Node's GC is inefficient with many large objects, and peak memory typically runs 5–10× the final artifact size.

This isn't a Next.js flaw — it's normal for build tooling. Vite, Webpack and esbuild behave the same way.


Disk: 50 GB, 15 GB used

Site directory     734 MB
  node_modules     661 MB      ← 90% of it
  .next             37 MB
  public            11 MB
System + rest     ~14 GB

node_modules dominates, but it's only needed to build. At runtime Next.js loads .next output and nothing else.

50 GB is plenty for a static site. The constraint is RAM, not disk.


When 2 cores / 2 GB is enough

Enough

  • Static or fully pre-rendered (SSG, low-frequency ISR)
  • Under ~100 pages
  • No database, or only light queries
  • A few thousand pageviews a day (static pages are served by Caddy and barely touch the CPU)
  • You build elsewhere and deploy only the output

Not enough

  • Heavy SSR — rendering on every request eats CPU and RAM
  • 300+ pages — the build will likely OOM
  • Running a database (MySQL/Postgres alone take a few hundred MB resident)
  • Image processing, video transcoding, PDF generation — memory goes immediately
  • Docker plus several services

The grey zone

100–300 static pages: it runs, but builds get risky. Two mitigations:

  1. Add 1–2 GB of swap during builds
  2. Build locally or in CI and upload only .next and public

At 60 pages I'm at 1342 MB peak with 22% headroom. Go much further and you need to watch it.


Three fixes that actually help

1. Swap, for free

2 GB of swap on a 2 GB box takes the pressure off the build:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

The build gets slower (disk is an order of magnitude slower than RAM) but it won't be killed.

2. Separate build from runtime

Build on your laptop or in CI, upload .next, public and package.json, then run next start.

  • Server RAM pressure drops sharply
  • The live site is unaffected while you build
  • You can build on a bigger machine

Cost: a slightly more involved deploy.

3. Compression pays more than you think

Measured on this site:

HTML uncompressed    73,479 B
HTML compressed      13,236 B     (−80%)
JS chunk             10,580 B → 4,150 B gzip (−61%)

One line in Caddy:

encode zstd gzip

Compression is free performance — trivial CPU cost, 60–80% less transfer. On a cross-border site this beats upgrading the box.


Picking a spec

Your situation Recommendation
Static site, 50–100 pages 2 cores / 2 GB is fine, add swap
Static site, 200+ pages 2 cores / 4 GB, or separate the build
With a database At least 2 cores / 4 GB
Heavy SSR or APIs 4 cores / 8 GB and up
Personal blog or portfolio 1 core / 1 GB works if you keep it minimal

Don't start with 4 cores / 8 GB. Most sites are limited by missing compression, caching and static rendering — not by hardware. Fix those three and a 2 GB box does more than you expect.

The inverse is also true: if your build keeps getting OOM-killed or the site keeps returning 502, upgrading is correct — but first check for a memory leak and confirm swap is configured.


What this runs on

I use a Tencent Cloud Lighthouse instance: 2 cores, 2 GB, 4 Mbps, Singapore region.

The reasons are mundane:

  • Singapore is close to Southeast Asia and Australia, tolerable to Europe and the US
  • Lighthouse bills a fixed bandwidth allowance, so there's no surprise overage charge
  • For a site this size the monthly cost is noise

If you want to run something similar, this tier is enough — provided you do the static rendering and compression described above.

Affiliate link. I do run this site on that instance.


The one-line version

A 2 GB box is idle at runtime and tight during build. Add swap, compress everything, and separate the build if you need to — this configuration handles more than most people assume.

The money is better spent on making pages static, shrinking assets and caching correctly than on a bigger server. Do those three and the difference between 2 GB and 8 GB is a few hundred milliseconds.

If you're sizing a site right now, run it through the free site audit first — body text length, asset weight and cache headers tell you more than a spec sheet.

Does your site have these problems?

Run the free audit tool for a 30-second report, or just write to me and describe the situation — I will tell you whether it is worth fixing.