DEV Community

Cover image for FastAPI vs Node.js vs Bun: One PostgreSQL Setting Was Worth Up to 31% (No Runtime Changed)
Rudratosh Shastri
Rudratosh Shastri

Posted on

FastAPI vs Node.js vs Bun: One PostgreSQL Setting Was Worth Up to 31% (No Runtime Changed)

Express beat Bun in one test. Bun nearly doubled Node in another. And one PostgreSQL setting was worth up to 31% — with no runtime change at all. The interesting part isn't who won. It's why the winner keeps changing.


Imagine you're choosing the backend for a new application. You have three obvious options:

  • FastAPI — Python, async support, type validation, excellent developer experience.
  • Node.js — a mature JavaScript ecosystem with battle-tested database libraries.
  • Bun — a newer JavaScript runtime promising lower overhead and more speed.

You search for benchmarks. One says Bun is dramatically faster. Another says Node.js wins. A third makes FastAPI look painfully slow. Same general task, different winners.

So what are we actually measuring?

I went through several publicly available 2026 benchmarks — their configurations, their raw result tables, and their methodology. One finding reframed the whole question for me:

Changing how Node.js talks to PostgreSQL was worth up to 31% in a published benchmark — without changing the JavaScript runtime, the framework, or the database engine.

That's a big enough swing to flip a comparison. And it points at a better question than "Which backend is fastest?":

Are we comparing programming languages, HTTP frameworks, database drivers, or somebody's connection-pool configuration?

Let's follow the evidence.

Transparency: I did not run these performance tests myself. This article analyzes independently published 2026 benchmarks, and every measurement below is attributed to its source. Two tables marked hypothetical are explanatory examples, not data.

The short version, if you only read one section

Before the detail, here's how I'd actually decide — because "fastest in a chart" is rarely the deciding factor:

Your situation What I'd prioritize
Existing Python team, ML / data workloads FastAPI's ecosystem and integration
Existing TypeScript backend, mature infra Node.js and its library compatibility
New JS/TS service where resource efficiency matters Evaluate Bun against your actual workload
PostgreSQL-heavy CRUD Query design, indexes, pooling, and p99 — not the runtime
Strict response-time SLAs Repeatable, production-like load testing

Now, why the benchmarks disagree.

1. The numbers that started the argument

In October 2026, the framework-rps benchmark compared seven backend stacks. The task was deliberately tiny: accept an HTTP request, run SELECT 1 against PostgreSQL, return {"status":"ok"}.

Setting Configuration
Host Apple M1 Pro, 10 CPU cores, 16 GB
App container 2 CPUs, 2 GB
PostgreSQL 17 container 1 CPU, 1 GB, max_connections=200
Shared DB connection cap 50
Load generator k6, constant virtual users, 30s warm-up, 3× 30s measured
Date October 15, 2026

Each app ran one at a time, so the stacks never competed for CPU. Reported highest stable throughput (requests/sec):

Backend Requests/sec At p95
Express 5 / Node.js 24 21,604 25 VUs 2.1 ms
Bun 1.4 18,038 400 VUs 52.4 ms
Fastify 5 / Node.js 24 13,632 100 VUs 30.2 ms
FastAPI 0.143 / Python 3.14 8,821 25 VUs 5.0 ms

(The full benchmark also includes Go — which won outright at 24,690 — plus Spring Boot and Laravel. I'm focusing on the three stacks in the title.)

Highest stable throughput — requests/sec (higher is better)

Express  ████████████████████  21,604
Bun      █████████████████     18,038
Fastify  █████████████         13,632
FastAPI  ████████               8,821
Source: framework-rps, Oct 2026
Enter fullscreen mode Exit fullscreen mode

Wait. Wasn't Bun supposed to beat Node?

Two things before anyone declares Express the champion.

First, these "best" numbers come from different concurrency levels. Express peaked at 25 virtual users (p95 2.1 ms); Bun peaked at 400 (p95 52.4 ms). That's not a comparison at the same offered load. At 25 VUs, the same benchmark records Bun at 16,432 RPS — a published row, not my estimate. So the honest reading is narrow:

On this machine, with these implementations and this SELECT 1 workload, Express sustained higher stable throughput than Bun. It does not prove Node is universally faster.

Second, look at Express versus Fastify. Express (21,604) beats Fastify (13,632) by ~58% — and both use the same driver (pg, simple-query protocol) on the same 2-CPU budget. Fastify is normally the faster of the two. Identical driver, identical budget, 58% apart, with Fastify never clearing ~13.6k at any concurrency level: that's not something framework overhead alone explains, and it's exactly the kind of result that should make you open the methodology before you quote the chart. I won't claim the benchmark is "wrong" — but that row deserves investigation, not a headline.

Source: framework-rps — full methodology and per-level results

2. In a different benchmark, Bun nearly doubled Node

A separate 2026 project, js-runtimes-benchmark, tested 22 JavaScript runtime × framework stacks against a full RealWorld app on an 8-vCPU box with a dedicated 16-vCPU PostgreSQL machine.

Its headline metric is sustained users — the most simulated users each stack held for five minutes under p95 < 500 ms, p99 < 1 s, < 1% errors — with requests/sec reported as a separate column. Those are not the same number, and conflating them is the exact trap this article is about, so here's the top of the table with both:

Implementation Sustained users Requests/sec
Bun · Bun.serve 84,000 21,469
Node · Fastify 46,000 12,181
Node · Express 40,000 10,530

By requests/sec, Bun delivered ~76% more throughput than Fastify here (the users column shows +83% — pick one unit and stick to it).

So which benchmark is right? Both — they're measuring different stacks on different hardware. And notice what doesn't survive the unit fix: benchmark 2's Bun did 21,469 RPS on an 8-vCPU box with a 16-vCPU database; benchmark 1's Express did 21,604 RPS on a 2-CPU container. By requests/sec they're nearly identical — on roughly four times the hardware. You cannot line up the absolute numbers from these two experiments at all. "Bun nearly doubled Node" is true inside benchmark 2 (same rig, Bun vs Node); it is meaningless across the two.

That is the whole problem with most runtime comparisons in one example: we take a measurement of an entire stack-plus-hardware and attribute it to a single component.

Let's isolate one of those components.

3. The PostgreSQL setting worth up to 31%

This was the most useful finding in the research. In the 22-stack benchmark, the author first used node-postgres (pg) the way most code does:

const result = await pool.query(
  "SELECT * FROM users WHERE id = $1",
  [userId]
);
Enter fullscreen mode Exit fullscreen mode

Perfectly normal. But in this form pg sends an unnamed statement, which PostgreSQL re-parses and re-plans on every call. The author then switched to named prepared statements:

const result = await pool.query({
  name: "find-user-by-id",
  text: "SELECT * FROM users WHERE id = $1",
  values: [userId],
});
Enter fullscreen mode Exit fullscreen mode

The name lets PostgreSQL reuse the prepared statement on that connection. Same runtime, same framework, same database — only the driver's statement handling changed.

Important: these figures are the benchmark's sustainable-user capacity (its headline metric), not raw RPS. Capacity and RPS move together here, but the number is users:

Node stack Default pg Named prepared Change
Express 39,000 40,000 +3%
Hono 35,000 39,000 +11%
Fastify 42,000 46,000 +10%
node:http 36,000 42,000 +17%
Ultimate Express 35,000 46,000 +31%

Source: js-runtimes-benchmark, section 3. Median across all Node stacks was +14%, with 30–37% less database CPU per request.

Two things to keep honest about this:

  • The gain was framework-specific. Ultimate Express jumped 31%; plain Express moved 3%, because Express was already its own bottleneck. "Node got 31% faster" would be the wrong lesson.
  • It didn't close the gap to Bun. The Node stacks stayed CPU-limited on the app box; prepared statements cut database CPU, not Node's. Bun (via Bun.SQL) and the Deno stacks (via postgres.js) prepare automatically, so the default-pg Node rows were carrying a tax the others never paid.

Which is the real point:

A runtime benchmark can contain a large database-client effect even when the HTTP application looks identical. Comparing Node + pg (unnamed) against Bun + Bun.SQL (auto-prepared) isn't just V8 vs JavaScriptCore — it's two database-access implementations with different defaults.

4. The database can hide the runtime — or expose it

Here's where I'd push back on a common oversimplification ("add a database and all runtimes converge"). Whether that's true depends entirely on how much work the database does.

Regime A — trivial query (SELECT 1). The database computes almost nothing. HTTP routing, the PostgreSQL wire protocol, driver behavior, and scheduling make up a large share of each request. Runtime and driver differences are highly visible — which is exactly why section 1's stacks spread so far apart. That benchmark is closer to a runtime-and-driver test than a "database" test.

Regime B — expensive query (joins, sorts, large result sets). Now consider an illustrative request (hypothetical numbers, to show the shape — not measured data):

Operation Example duration
HTTP routing + validation 0.3 ms
Waiting for a connection 0.5 ms
Database / network work 8.0 ms
Decode rows + serialize JSON 0.7 ms
Total 9.5 ms

Halve the routing cost and you save 0.15 ms — a 1.6% improvement to the whole request. That's Amdahl's law: speeding up a small slice barely moves the total.

So both can be true. A trivial query exposes the runtime; an expensive one can bury it. The database doesn't erase runtime differences — it changes where they show up. (A separate 2026 Bun vs Node comparison on DEV found Bun kept a real edge on a local PostgreSQL route, consistent with Regime A.)

5. FastAPI needs a fairer comparison too

So far Python looks like the loser. But there's a gap between measuring FastAPI's framework overhead and measuring a production-style FastAPI app.

FastAPI runs ordinary def endpoints in a thread pool and async def endpoints as coroutines on the event loop (official docs). An async endpoint over an async driver like asyncpg behaves very differently from a sync endpoint over a sync driver — and worker count matters just as much. Comparing one FastAPI process against a multi-process Node setup answers a different question than comparing production configurations of both. Both are legitimate; they just aren't the same experiment.

And the ORM can cost more than the language. The small-runtime-bench project, run on dedicated 16-vCPU cloud machines, measured each stack through its real ORM versus the raw driver:

  • SQLAlchemy cut FastAPI throughput ~57%
  • Prisma cut NestJS ~48%
  • Django's ORM cost ~30%
  • ActiveRecord was nearly free (0–2%)

That doesn't make SQLAlchemy "bad" — ORMs buy you models, relationships, portability, and ergonomics. But it means you cannot compare FastAPI-with-an-ORM against Node-with-raw-SQL against Bun-with-a-native-client and announce you've isolated the fastest language. You've measured three application stacks. That's useful — as long as you call it what it is.

Source: small-runtime-bench — ORM-tax methodology and results

6. The hidden variable: connection pooling

Say your app gets 500 concurrent requests and your pool allows 20 connections. The other 480 wait — and waiting time hits your users exactly like query time does. Now compare three apps configured like this:

Stack Pool size
FastAPI 10
Node.js 20
Bun 50

One wins. Can you attribute that to the runtime? No — the larger pool might help one workload and overload PostgreSQL on another. A controlled comparison tests identical connection limits first, then sweeps pool size (5 → 10 → 20 → 50), measuring completed RPS, p95/p99, connection wait, database CPU, and errors at each step.

One more trap: the limit is per pool instance. Four workers with a pool of 20 each is up to 80 database connections, and PostgreSQL has its own connection and memory ceiling. A config that's harmless for one process gets expensive when scaled — which is why the fastest app config and the fastest database config have to be chosen together.

7. RPS can hide a collapsing service

The question I'd ask of any benchmark chart: what happened to the requests that didn't finish?

Metric Service A Service B
Completed RPS 20,000 18,000
p95 latency 900 ms 35 ms
p99 latency 2,500 ms 70 ms
Error rate 2.0% 0%

(Hypothetical, to illustrate.) Service A "wins" on throughput. Would you ship it for a latency-sensitive API? A system under overload can post an impressive RPS headline while quietly queueing and erroring.

This is also where the load model matters — and where I'll be honest about the benchmarks above. There are two models:

  • Closed-loop: each virtual user waits for a response before sending the next. If the server slows down, the offered rate automatically falls, which can hide overload behavior.
  • Open-loop: new work arrives on a fixed schedule regardless of whether prior work finished — which exposes what happens when traffic keeps coming and responses slow.

Grafana k6 supports both; its constant-arrival-rate executor is the open-loop one:

import http from "k6/http";
import { check } from "k6";

export const options = {
  scenarios: {
    database_read: {
      executor: "constant-arrival-rate",
      rate: 1000, timeUnit: "1s", duration: "60s",
      preAllocatedVUs: 200, maxVUs: 1000,
    },
  },
  thresholds: {
    http_req_failed: ["rate<0.01"],
    http_req_duration: ["p(95)<200"],
    dropped_iterations: ["count==0"],
  },
};

export default function () {
  const res = http.get(`${__ENV.BASE_URL}/users/42`);
  check(res, { "status is 200": (r) => r.status === 200 });
}
Enter fullscreen mode Exit fullscreen mode

Worth flagging: both benchmarks I've leaned on here are closed-loop (constant virtual users / think-time visitors). They're carefully run — both warm up, and the second does two-minute capacity probes and five-minute sustained holds — but the closed-loop model is the one with the blind spot I just described. If you reproduce any of this, add an open-loop run and watch dropped_iterations (k6 reports these when it can't launch scheduled work). A benchmark should distinguish offered, sent, and completed traffic — that distinction often matters more than the biggest number in the chart.

Sources: k6 open vs closed models, dropped iterations.

8. What a fair FastAPI vs Node vs Bun test would look like

I wouldn't start with a single winner-takes-all number. I'd split it into two questions.

Experiment A — which application stack handles the workload best? Realistic, idiomatic implementations:

Stack HTTP server DB client
FastAPI Uvicorn asyncpg
Node.js Fastify node-postgres
Bun Bun.serve Bun.SQL

Same schema, query semantics, indexes, response shape, and resource budget — and document the statement handling, because section 3 shows it moves the number.

Experiment B — how much is the runtime vs the client? Add controls that hold the runtime constant and vary the driver (Fastify on Node and Bun with the same postgres.js; pg unnamed vs named). Then run five increasingly realistic workloads:

Test What it reveals
JSON only HTTP + serialization overhead
SELECT 1 Minimal DB round trip (Regime A)
Indexed lookup Basic real-data read
100-row query Decode + serialization cost
Mixed read/write Transactions, contention, pool behavior (Regime B)

The rule is: don't change five variables at once. If Bun wins JSON but loses mixed read/write, that's a bottleneck to investigate, not proof one runtime is "better."

My minimum checklist before trusting results for a production decision: fixed versions/hardware/DB settings/dataset; comparable worker counts and connection budgets; correctness tests per endpoint before timing; warm-up plus repeated runs with variability reported; identical offered load and a capacity search; p50/p95/p99, throughput, errors, and dropped work; CPU/memory/DB-utilization/pool metrics; and a repo with source, config, and raw results. Excessive for a blog post — not excessive for an architecture decision.

9. So which would I choose?

Not from these benchmarks alone. The table at the top is how I'd actually weigh it — but the deciding factors usually aren't in any RPS chart. If one stack serves the same traffic with fewer instances or more latency headroom, that's real operational money. But application economics also include migrations, debugging, libraries, deployment, and the familiarity of the team that has to run it at 3 a.m. A stack that's 30% faster in a synthetic test isn't automatically 30% cheaper to operate — and it certainly won't make your developers 30% more productive.

10. The result that changed how I read benchmarks

The finding that stuck with me wasn't Express hitting 21,604 RPS, or Bun sustaining 84,000 users in a different test, or FastAPI trailing. It was this:

One published experiment changed a stack's capacity by up to 31% just by naming its prepared statements.

The runtime didn't change. The framework didn't change. The database engine didn't change. A detail in the database-access layer did — and it was enough to reorder stacks.

A benchmark tells you what was fastest under its conditions. Understanding the conditions tells you whether the result applies to your application.

That's the part I'd read before rewriting a backend — and the part I wish more framework comparisons put in their headline instead of a chart with three bars.


Sources

  1. framework-rps — Oct 2026 PostgreSQL API benchmark; container limits, per-concurrency throughput and latency.
  2. js-runtimes-benchmark — 22 JS stacks; sustained-users metric, prepared-statement experiment, CPU observations. (The authors note one grid had ~5% background-CPU contamination affecting the Bun rows, and run-to-run spread of ~±5% — read close results as ranges.)
  3. small-runtime-bench — multi-runtime ORM-tax measurement and reproducibility methodology.
  4. Bun SQL docs · 5. node-postgres docs · 6. FastAPI async docs · 7. k6 constant-arrival-rate · 8. Bun vs Node 2026 (DEV).

Tables reproduce or compute from these published measurements; the two tables marked hypothetical are explanatory.


One question for the comments: have you ever changed a database driver, pool size, or ORM config and seen a bigger improvement than switching frameworks? I'm especially interested in cases where the benchmark winner changed once a real database entered the picture.

Top comments (0)