A typical Node.js API with a PostgreSQL database is small: most run comfortably on 1-2 GB of memory and one vCPU, and the database needs a similar amount again. The honest way to arrive at a number is not a formula but three measurements taken on your own code: peak resident memory (RSS) under load, event loop utilisation at the request rate you expect, and how many database connections are busy at once. Buy the plan that holds those numbers with about 30-40% headroom, and re-measure after every release that changes a query. This guide shows how to take each measurement with built-in tools, how to turn them into a plan size, and what a bigger plan will not fix.
It is deliberately about measuring before spending. If you already know your app is dying at its memory limit, Node.js memory limits is the faster read. If the symptom is a Postgres connection error, start with node-postgres connection pooling on small servers. For the general upgrade decision on any runtime, see when to upgrade your hosting plan. This post is the part before all of those: working out the size in the first place.
What actually consumes resources in a Node API#
Node runs your JavaScript on one thread. That single fact shapes the whole sizing exercise. An API process can use at most about one core for your code, however many cores the plan has, because the event loop runs everything - routing, JSON parsing, serialisation, your business logic - one task at a time. Extra cores help in three narrower ways: garbage collection runs on helper threads, the libuv thread pool handles some file system, DNS lookups and crypto work, and you can run several processes (with cluster, pm2 or several containers) to use more than one core for JavaScript.
So the useful question is not "how many cores do I need" but "how busy is my one event loop at the traffic I expect". A plan with 1 vCPU and a plan with 2 vCPU give a single Node process the same JavaScript throughput. The second core only pays off once you run a second process.
Memory is more forgiving to estimate. A Node process has a fixed baseline, then grows with what your code holds on to:
- Baseline: a bare process with Express or Fastify loaded typically sits at a few tens of megabytes. Your own number will differ, so measure it.
- Heap: objects your code allocates and has not yet released. In-memory caches, big result sets and request bodies live here.
- Buffers and native memory: file uploads, compression, TLS, and the
pgdriver's socket buffers are outside the V8 heap but inside RSS. - Per-connection state: each open database connection costs something on the Node side, and a good deal more on the Postgres side (more on that below).
The container limit applies to RSS, not to the heap, which is why the number to watch is resident memory. If this distinction is new, read the two-ceilings section of the memory limits post first.
Step one: write down the workload#
Sizing from "a small API" is guessing. Spend ten minutes writing four numbers, even rough ones:
- Peak requests per second. Not the daily average. If you expect 50,000 requests a day, that is under one request a second on average, but traffic is lumpy and a peak of 10-20 times the average is normal. Use your peak.
- Mix of cheap and expensive endpoints. A health check and a report that aggregates a million rows are not the same request. List the three most expensive endpoints.
- Queries per request. Count how many database round trips the typical request makes. An ORM that lazily loads relations can turn one endpoint into twenty queries without anyone noticing.
- Payload size. Average response size in kilobytes. Large JSON is CPU time on your event loop, because serialising it is synchronous.
Those four numbers are the inputs to everything below. Write them in the repository next to the code, so the next person to resize the app does not start from nothing.
Step two: measure on your own machine first#
Before any hosting plan is involved, find out what the app costs at idle and under load. Use a production build, NODE_ENV=production, and a database with realistic data volume - a table of 200 rows hides every missing index.
Memory at rest and under load
Print the resident set size from inside the process, or watch it from outside:
setInterval(() => { const m = process.memoryUsage(); const mb = (n) => Math.round(n / 1024 / 1024); console.log(`rss=${mb(m.rss)}MB heapUsed=${mb(m.heapUsed)}MB external=${mb(m.external)}MB`);}, 10000).unref();Run the app, note the idle RSS, then apply load (next section) and note the RSS after a few minutes. The number that matters is the plateau: memory that climbs during load and settles is your working set, while memory that climbs for ever is a leak, and no plan size fixes a leak.
Load with autocannon
autocannon is a small Node-based load generator that runs from npx without installing anything permanently:
$ npx autocannon -c 50 -d 30 http://localhost:3000/api/orders-c 50 is 50 concurrent connections and -d 30 is thirty seconds. It prints a latency distribution and requests per second. Run it against each of your three expensive endpoints separately, then against a realistic mix, and always against the endpoint with the database in the loop. Increase -c in steps (10, 25, 50, 100) and watch where throughput stops rising and latency starts climbing. That knee is your capacity on that machine.
A caveat: your laptop is not the hosting plan. Treat local numbers as relative (this endpoint costs ten times that one) and take the final absolute numbers from a short run against the real server, covered further down.
Event loop lag: the number that says whether you are CPU bound#
Throughput tells you how fast the app is. Event loop delay tells you how close it is to the edge. When a Node process is saturated, requests queue behind whatever is currently running, and the time a timer fires late is a direct measure of that queue.
Node has this built in, in perf_hooks:
const { monitorEventLoopDelay, performance } = require('node:perf_hooks');const h = monitorEventLoopDelay({ resolution: 20 });h.enable();let last = performance.eventLoopUtilization();setInterval(() => { const now = performance.eventLoopUtilization(); const util = performance.eventLoopUtilization(now, last).utilization; last = now; console.log(JSON.stringify({ loopMeanMs: +(h.mean / 1e6).toFixed(1), loopP99Ms: +(h.percentile(99) / 1e6).toFixed(1), loopMaxMs: +(h.max / 1e6).toFixed(1), utilisation: +util.toFixed(2), })); h.reset();}, 10000).unref();The histogram values are in nanoseconds, hence the division. Two metrics come out of it, and they answer different questions:
| Metric | What it tells you | Rough reading |
|---|---|---|
| Event loop delay p99 | How late timers fire at the tail | Under 50 ms is healthy; sustained hundreds of ms is queueing |
| Event loop utilisation | Fraction of time spent running JS, 0 to 1 | Sustained above 0.7-0.8 means little headroom |
These thresholds are rules of thumb, not standards. What you are looking for is a trend under load: lag that stays flat as you add concurrency, then bends sharply upward. Where it bends is the traffic level at which one process runs out.
Read the result like this:
- Utilisation low, latency high. The loop is idle but requests are slow, so the time is going elsewhere: usually waiting on the database or an upstream API. More CPU will not help; look at queries and the pool.
- Utilisation near 1, loop delay high. You are CPU bound on one thread. Options in order of cost: find the hot function with a profile, remove synchronous work, then run a second process, then a faster core.
- Delay spikes with a flat average. One slow synchronous task blocks everyone now and then. Typical culprits are
JSON.parseof a huge body, a regular expression with catastrophic backtracking,bcryptrun in a synchronous mode, or a large.sort()on every request.
To find the hot function rather than guess, Node can write a CPU profile:
$ node --cpu-prof --cpu-prof-dir=./profiles server.jsStop the process after a load run and open the resulting .cpuprofile file in Chrome DevTools (Performance or the JavaScript Profiler panel). The widest bars are where the loop spends its time. It is common to find that one JSON serialisation or one logging call accounts for a quarter of CPU.
Pool size: connections are the real constraint#
The pg driver's Pool defaults to max: 10 connections per Node process. That default is reasonable for many apps and wrong for others, and the right value is derived, not guessed.
Every Postgres connection is a separate server process. Each one holds some memory of its own and, when it runs a sort or a hash, up to work_mem per operation. This is why a bigger pool is not a faster pool: past a point, more concurrent queries just compete for the same CPU and disk on the database server. PostgreSQL tuning for small servers covers the memory arithmetic on the database side.
A formula that holds up
Little's law gives the average number of connections in use:
busy connections = queries per second x average query time (seconds)A worked example. Your peak is 150 requests a second, each request runs 3 queries, and the average query takes 4 ms:
150 x 3 = 450 queries/s450 x 0.004 = 1.8 busy connections on averageAverages hide bursts, so plan for several times that. A pool of 10 is generous for this workload. The same API with a slow report endpoint that holds a connection for 800 ms and is hit five times a second needs 5 x 0.8 = 4 connections for that endpoint alone, and it will starve everything else on a pool of 5. Slow queries, not request volume, are what exhaust pools.
Watch the pool from the app
The Pool object exposes three counters worth logging every few seconds:
setInterval(() => { console.log(JSON.stringify({ total: pool.totalCount, idle: pool.idleCount, waiting: pool.waitingCount, }));}, 10000).unref();waiting above zero for more than a moment means requests are queueing for a connection. If idle is high and waiting is zero, the pool is bigger than it needs to be. Pair this with a sensible set of options:
const { Pool } = require('pg');const pool = new Pool({ connectionString: process.env.DATABASE_URL, max: 10, idleTimeoutMillis: 30000, connectionTimeoutMillis: 5000, statement_timeout: 15000,});connectionTimeoutMillis matters most for sizing: without it, a request waits indefinitely for a free connection and your latency graph becomes a flat line of timeouts instead of an error you can see. statement_timeout stops one runaway query from holding a connection for minutes.
The multiplication trap
The pool is per process. If you run two Node processes (or two containers, or cluster with four workers), the database sees max times that many connections. Check the database's ceiling:
SHOW max_connections;SELECT state, count(*)FROM pg_stat_activityGROUP BY stateORDER BY count DESC;The second query shows how many connections are active (running something), idle (held by a pool but doing nothing) and idle in transaction (a bug: someone started a transaction and never finished it). If idle connections dominate, lower max. If you see idle in transaction, fix the code, because those hold locks and block vacuum.
Total demand is processes x max plus whatever else connects: migrations, a worker, an admin session, a monitoring agent. Keep that sum comfortably below max_connections. If you cannot, the next move is a pooler such as PgBouncer or fewer, smaller pools - not a larger max_connections.
Find the slow queries before you size the database#
A database that looks too small is very often a database with one missing index. Sizing the machine around a bad query means paying every month for a problem a one-line index would remove. Before choosing a database plan, spend an hour on the queries.
EXPLAIN (ANALYZE, BUFFERS) runs a query and reports where the time went:
EXPLAIN (ANALYZE, BUFFERS)SELECT * FROM orders WHERE customer_id = 42 ORDER BY created_at DESC LIMIT 20;A Seq Scan over a large table for a query that returns a handful of rows is the classic sign of a missing index. PostgreSQL indexes explained walks through reading plans. To find which queries to look at, the pg_stat_statements extension ranks them by total time; the setup and reading are in find slow PostgreSQL queries with pg_stat_statements. On a hosted database, check whether the extension is available to you before assuming it is.
Then size the database on three things:
- Working set versus memory. Postgres is fast when the frequently read part of your data fits in memory (its own cache plus the operating system's). A 2 GB database on a server with 1 GB of RAM will do disk reads constantly.
- Disk. Data, indexes and the write-ahead log. Leave room: a table that is rewritten by a heavy update load grows before vacuum catches up.
- Connections. From the section above; each one has a memory cost.
On RE:NODE, PostgreSQL plans start at 1 GB of memory and 20 GB of disk and go up from there; the current ladder is on the database hosting page.
Turning measurements into a plan#
Now put the numbers together. This is a worked example with invented but realistic figures, to show the method rather than to predict yours.
An API serving a mobile app. Peak is 80 requests per second. Local autocannon shows one process saturates around 400 requests per second on the expensive endpoint mix, with event loop utilisation about 0.2 at the target peak. RSS plateaus at 310 MB under load. Pool statistics show 3-4 connections busy at peak.
| Resource | Measured | Plan for |
|---|---|---|
| App memory | 310 MB RSS plateau | About 450-500 MB with headroom |
| App CPU | 20% of one core at peak | One vCPU, with room for 4x growth |
| DB connections | 3-4 busy | max: 10, one process |
That workload fits the smallest plans on both sides with room to spare. The main reason to buy more would be database memory if the working set outgrows 1 GB, which you find out from pg_stat_statements cache statistics and from watching read latency rise, not from guessing.
Some practical rules for the conversion:
- Memory headroom of 30-40% above the plateau. Garbage collection needs room to work, and the plateau is not the peak.
- One Node process per vCPU at most. On a plan with 2 vCPU, two processes can use both; on 0.5 vCPU a single process will be throttled below what it wants.
- CPU limits are hard throttles. On RE:NODE the CPU figure on a plan is the share you bought and it is a hard limit, so a busy server is slow, never suspended. That makes event loop delay the first symptom of an undersized plan, well before errors appear. Details on the plan ladder are on app hosting.
- Leave the database its own plan. Running Postgres beside the app on one small machine means they compete for the same memory. A separate database plan gives each a defined limit and you can resize them independently.
Verify on the real server, then watch it#
Once the app is deployed, repeat the load test against it, from a different machine, and keep the same instrumentation running. The things to read:
- The panel graphs for memory, CPU and disk against the plan limits, on the Console tab. Memory near the limit under load is the one to act on; CPU pinned at the limit means the throttle is active.
- Your own logs of loop delay, utilisation and pool counters. These are more precise than any graph and they survive a restart if you ship them somewhere.
- Container limits if you have a shell: on a cgroup v2 system,
cat /sys/fs/cgroup/cpu.statshowsnr_throttledandthrottled_usec, which count how often the CPU limit held you back. The exact files depend on the host's cgroup version, so treat this as something to check rather than to assume.
If memory hits the limit, the kernel stops the container and it restarts clean rather than swapping. That is a deliberate design, and it means an undersized plan shows up as restarts, not slow degradation. Three restarts in an hour trigger a warning on the server page and an automatic ticket, so do not let a crash loop run unattended.
Add a lightweight health route and uptime check, and pick the metrics from monitoring that tells you something so you are alerted on symptoms (latency, errors) and not on every wobble.
When to scale up, and when it will not help#
Scaling up costs money every month, so match the fix to the diagnosis:
| Symptom | Likely cause | Fix |
|---|---|---|
| Loop utilisation near 1, delay climbing | One thread is saturated | Profile, remove sync work, add a process |
Loop idle, latency high, waiting > 0 | Pool exhausted by slow queries | Fix queries first, then raise max |
| RSS climbing without a plateau | Memory leak | Find the leak, do not buy RAM |
| RSS plateau at the plan limit | Genuinely too little memory | Move to the next tier |
| DB reads slow as data grows | Working set exceeds memory | Index, then more database RAM |
Scaling up a tier is right when a measurement says the resource is the limit and the cheaper fixes are done: memory plateau within 20% of the limit, or CPU genuinely saturated across several processes. Changing plan does not rebuild the server, so moving up is a low-risk step you can take the day the numbers say so. There is no reason to over-buy "just in case" when the step up is that cheap.
A bigger plan will not fix a missing index, a connection leak, a synchronous call that blocks the loop, or a chatty ORM issuing twenty queries per request. Those all show up again at the next tier, only later and more expensively.
When a dedicated server is the answer
A move to a dedicated server makes sense in narrower cases than people expect:
- You run several services on one machine - the API, a worker, a queue, a cache, the database - and want to tune them together.
- You need software that needs the operating system, such as a specific Postgres extension build, a custom
postgresql.conf, or background daemons. - You are already using the largest app plan across multiple processes and measurements still show saturation.
The dedicated line on RE:NODE is an Intel i9-9900K machine, and the current plans and prices are on the dedicated servers page. It brings more headroom and more freedom, and also more to look after: updates, backups and monitoring become yours. When an app needs a dedicated server, and how to move lays out the signs and the migration path, and VPS vs VDS vs dedicated server explains the differences between the three.
For most single-API workloads, the sequence is: measure, fix queries, size the app and database plans separately, scale up a tier when a measurement demands it, and only then consider a dedicated machine.
FAQ#
How much RAM does a small Node.js API need?
Measure the RSS plateau under load and add 30-40% headroom. Many small APIs plateau between a few hundred megabytes and 1 GB, but the number depends on caches, payload sizes and dependencies, so a figure from someone else's app is only a starting guess.
How many CPU cores does a Node.js API need?
One process uses about one core for JavaScript, so a single process gains nothing from a second core. Run one process per core you want to use. Judge the need by event loop utilisation: if it stays low at your peak load, you are not CPU bound.
What is a good event loop lag for a Node API?
Under about 50 ms at p99 is a comfortable rule of thumb, and a flat line is better than any particular number. Sustained lag in the hundreds of milliseconds means requests are queueing behind synchronous work or a saturated core.
What should I set the pg Pool max to?
Start from queries per second x average query seconds, multiply by a few for bursts, and round up modestly. The pg default is 10 per process. Remember to multiply by the number of processes and keep the total below the database's max_connections.
Should the app and the database be on the same plan?
Separate is easier to reason about: each has its own memory and CPU limit, and you can resize one without touching the other. RE:NODE sells a bundle of a Node.js plan with a PostgreSQL plan at a discount, bought in one checkout, which suits this layout; see the app hosting page.
Can I test sizing without paying first?
Yes, locally. Run a production build against a copy of realistic data, use autocannon and the measurement snippets above, and treat the results as relative. RE:NODE has no free tier, so the final check on the real server is a short paid test, which you can follow with a plan change if the numbers disagree with your estimate.


