How Node.js and Go compare for backend APIs and workers: the event loop vs goroutines, CPU-bound work, types, tooling, deployment and the same endpoint written in both.

Node.js and Go are the two most common picks for a new backend API, and both handle thousands of open connections without trouble. Node.js runs JavaScript or TypeScript on a single-threaded event loop with npm behind it, and Go runs compiled code on goroutines spread across every core.
The gap shows when a request does CPU work, when the team wants one language with the frontend, and in how many instances the same traffic needs.
Node.js runs your JavaScript on one thread and hands I/O to the operating system, so a request waiting on Postgres costs almost nothing and the event loop moves on to the next one. For APIs that mostly read and write a database, that model is efficient and easy to reason about with async/await:
import express from "express";
import pg from "pg";
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
const app = express();
app.get("/orders/:id", async (req, res) => {
const id = Number(req.params.id);
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid id" });
const { rows } = await pool.query(
"SELECT id, status, total_cents FROM orders WHERE id = $1",
[id],
);
if (rows.length === 0) return res.status(404).json({ error: "order not found" });
res.json(rows[0]);
});
app.listen(Number(process.env.PORT ?? 8080));
The single thread is also the limit, since a handler that hashes a password with a slow sync call, parses a large CSV or resizes an image holds the loop, and every other request on that process waits. The fixes are worker_threads for CPU work and more processes per machine, which multiplies V8 heaps and connection pools. TypeScript types disappear at runtime too, so request bodies still need a validator; recent Node.js versions can run .ts files directly through type stripping, but they do not check them.
The strengths are the ecosystem and the language overlap: npm has a client for nearly every SaaS API, and a team that writes TypeScript on the frontend can share types and validation schemas with the backend.
Best fit: I/O-bound APIs, BFFs and webhook handlers written by teams that already work in TypeScript.
Go's net/http server runs each request in its own goroutine, and the runtime schedules goroutines across all CPU cores. Code blocks normally, and a CPU-heavy request uses one core while the others keep serving. From Go 1.22 the standard router matches methods and path parameters without a framework:
package main
import (
"context"
"encoding/json"
"errors"
"net/http"
"os"
"strconv"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)
type Order struct {
ID int64 `json:"id"`
Status string `json:"status"`
TotalCents int64 `json:"total_cents"`
}
func main() {
pool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
panic(err)
}
mux := http.NewServeMux()
mux.HandleFunc("GET /orders/{id}", func(w http.ResponseWriter, r *http.Request) {
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
if err != nil {
http.Error(w, "invalid id", http.StatusBadRequest)
return
}
var o Order
err = pool.QueryRow(r.Context(),
"SELECT id, status, total_cents FROM orders WHERE id = $1", id,
).Scan(&o.ID, &o.Status, &o.TotalCents)
if errors.Is(err, pgx.ErrNoRows) {
http.Error(w, "order not found", http.StatusNotFound)
return
}
if err != nil {
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(o)
})
http.ListenAndServe(":"+os.Getenv("PORT"), mux)
}
The build is one static binary that fits in a small container image, memory per instance is usually lower than a Node.js process serving the same load, and the standard library covers HTTP, JSON, TLS and crypto. The trade is a smaller package ecosystem for SaaS SDKs, more explicit code for things like error handling, and no shared types with a TypeScript frontend unless you generate a client.
Best fit: services and workers with CPU work in the request path, high request volumes per instance, or a team that wants simple binaries to deploy.
Both examples above read DATABASE_URL from somewhere, and that database, its migrations and its credentials have to exist locally and in each environment. Encore is a backend framework with built-in infrastructure, so the endpoint and the database it reads are declared in the same file, encore run starts Postgres locally and applies the migrations, and a deploy provisions RDS or Cloud SQL in your own AWS or GCP account.

Run in your terminal to get started locally.
In TypeScript the path parameter is typed and validated before the handler runs, and the query is a tagged template with bound parameters:
// orders/orders.ts
import { api, APIError } from "encore.dev/api";
import { SQLDatabase } from "encore.dev/storage/sqldb";
// Postgres locally under encore run, RDS or Cloud SQL after deploy.
const db = new SQLDatabase("orders", { migrations: "./migrations" });
interface Order {
id: number;
status: string;
total_cents: number;
}
export const getOrder = api(
{ expose: true, method: "GET", path: "/orders/:id" },
async ({ id }: { id: number }): Promise<Order> => {
const order = await db.queryRow<Order>`
SELECT id, status, total_cents FROM orders WHERE id = ${id}
`;
if (!order) throw APIError.notFound("order not found");
return order;
},
);
The same endpoint in Go is a function with an //encore:api annotation and a sqldb database:
// orders/orders.go
package orders
import (
"context"
"errors"
"encore.dev/beta/errs"
"encore.dev/storage/sqldb"
)
var db = sqldb.NewDatabase("orders", sqldb.DatabaseConfig{Migrations: "./migrations"})
type Order struct {
ID int64 `json:"id"`
Status string `json:"status"`
TotalCents int64 `json:"total_cents"`
}
//encore:api public method=GET path=/orders/:id
func GetOrder(ctx context.Context, id int64) (*Order, error) {
var o Order
err := db.QueryRow(ctx,
`SELECT id, status, total_cents FROM orders WHERE id = $1`, id,
).Scan(&o.ID, &o.Status, &o.TotalCents)
if errors.Is(err, sqldb.ErrNoRows) {
return nil, &errs.Error{Code: errs.NotFound, Message: "order not found"}
}
if err != nil {
return nil, err
}
return &o, nil
}
The surrounding pieces stay the same whichever language you pick: plain SQL migrations, request tracing in the local dashboard, and a deploy to your own cloud where Encore provisions an IAM role for the service, or a service account on GCP. That also makes the language choice reversible per service, since a new Go service and an existing TypeScript one live in the same app.
The declarations give coding agents a short loop in either language: the agent adds the migration and the endpoint, calls it against the local Postgres and reads the trace, with no connection string or cloud console involved.
Best fit: TypeScript or Go backends that want endpoints, Postgres and Pub/Sub declared in code, running locally and in their own AWS or GCP account.
Pick Node.js with TypeScript when the team already writes TypeScript, the API is I/O-bound, and sharing types or packages with a frontend saves time. Pick Go when requests do CPU work, when you want fewer and smaller instances for the same load, or when the backend is several services and workers that should ship as simple binaries. A common split is TypeScript for the API layer close to the frontend and Go for the workers behind it.
Yes. Go is faster for CPU-bound work, and not by much for I/O-bound APIs that mostly wait on a database, where both handle high concurrency. Go pulls ahead when requests do CPU work such as JSON transformation, hashing or image processing, because goroutines run across all cores while a Node.js process runs JavaScript on one thread.
Use Node.js with TypeScript when the team already writes TypeScript, shares types with a frontend, or depends on npm packages with no Go equivalent. Use Go when the backend is a set of services and workers where predictable performance, low memory per instance and a single static binary matter.
Yes. Not inside one event loop, but Run several processes behind a load balancer or with the cluster module, or move CPU-heavy work to worker_threads. Each process keeps its own memory, so a Node.js deployment usually runs more processes than an equivalent Go service.
Yes. Encore is a backend framework with built-in infrastructure. Endpoints and the Postgres databases, Pub/Sub topics and buckets they use are declared in code, run locally under encore run, and are provisioned in your own AWS or GCP account on deploy.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.