Member-only story

Node.js is faster than Go

CJ Hewett
3 min readApr 1, 2024

--

…when you write bad code. A lesson in connection pooling, and not simply copying and pasting code you find on the internet.

I was performance testing APIs I’d made in different frameworks against a Timescale Postgres DB in a Docker container locally. These were simple APIs that searched for a record with over 100 millions records.

I found Go was getting around 2000 requests per second. I thought this was good until I saw NestJS and Bun were getting 3000rps. This couldn’t be right since Go is meant to be far superior 💪.

I found the issue was connection pooling, and not setting limits on max and idle connections. This is something that not many tutorials mention about the Go SQL package. However, this article describes it well:

After setting limits, I started to get 2–3x more RPS for Go.

When searching for how to connect to a database, I found a lot of examples of something similar to the following:

func NewPostgresStore() (*PostgresStore, error) {
godotenv.Load()
connStr := fmt.Sprintf("host=%s port=%s…

--

--

CJ Hewett
CJ Hewett

Written by CJ Hewett

🛹 Skateboarder. 🏂 Snowboarder. 🏄 Websurfer. I write monthly* about Cloud/DevOps/IoT. AWS Certified DevOps Engineer and Terraform Associate

Responses (10)