Software Studio
Back to Articles

Go for Backend Services: A Node.js Developer's Perspective

GoNode.jsBackend
Cover illustration for Go for Backend Services: A Node.js Developer's Perspective

I've built most of my career on Node.js and TypeScript. I still reach for them first. But there are cases where Go is the better tool, and understanding when to switch has made me a better engineer.

Concurrency is Go's killer feature

Goroutines are lightweight. You can spawn millions without running out of memory. Channels provide safe communication between goroutines.

func crawl(urls []string) []Result {
    results := make(chan Result, len(urls))

    for _, url := range urls {
        go func(u string) {
            results <- fetch(u)
        }(url)
    }

    collected := make([]Result, 0, len(urls))
    for range urls {
        collected = append(collected, <-results)
    }
    return collected
}

For workloads that involve heavy concurrent I/O, Go handles this naturally where Node.js requires careful async orchestration:

  • Processing thousands of webhook events.
  • Crawling hundreds of URLs.
  • Handling high-throughput message queues.

Node can do all of these. The difference is that in Go the concurrent version reads like ordinary sequential code, and the runtime spreads the work across every CPU core without you asking.

The deployment story is compelling

Go compiles to a single static binary. No node_modules. No runtime. No dependency hell.

Your Docker image can be FROM scratch, which is literally an empty filesystem with just your binary.

FROM golang:1 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app ./cmd/server

FROM scratch
COPY --from=build /app /app
ENTRYPOINT ["/app"]

The resulting image is often under 20MB compared to 200MB+ for a typical Node.js application. Smaller images pull faster and start faster, and an image with no shell and no packages has very little in it to attack. I cover the Node side of this in Docker for Production: Beyond the Basics.

Performance differs in important ways

Node.js is fast for I/O-bound work thanks to the event loop. Go is fast for everything: I/O, CPU-bound computation and concurrent workloads.

The gap shows up when a service does real work between requests. In Node, a heavy computation on the main thread blocks every other request until it finishes. In Go, it runs on one core while the others keep serving traffic.

If your service does significant data processing, JSON marshaling or computation alongside serving HTTP requests, Go will handle it more efficiently.

A simpler type system

The type system is different from TypeScript but equally valuable. Go's types are simpler: limited generics, no union types, no conditional types. This simplicity is intentional. The code is more verbose but harder to get wrong.

Error handling through multiple return values forces you to handle errors at every call site.

user, err := store.FindUser(ctx, id)
if err != nil {
    return fmt.Errorf("find user %s: %w", id, err)
}

It looks repetitive coming from TypeScript, where an exception can travel silently up the stack. After a while you notice that you always know which calls can fail and what happens when they do.

A production-grade standard library

The standard library is production-grade.

  • net/http is a real HTTP server, not a minimal abstraction.
  • encoding/json handles serialization.
  • database/sql provides a clean database interface.

You can build a production API with just the standard library, which isn't true of Node.js. Fewer dependencies means fewer upgrades to manage and a smaller supply chain to worry about.

Where Go falls short

Where Go falls short: rapid prototyping. The verbose error handling and the less expressive generics, compared to TypeScript, mean more code for simple CRUD operations.

For a typical web API with a database backend, NestJS with Prisma gets you to production faster. I describe that setup in TypeScript Patterns for NestJS APIs. Go's advantages show up as the system grows in complexity and scale.

There is also the team to consider. If everyone already writes TypeScript on the frontend, sharing a language and types with the backend is worth a lot.

How I choose

I reach for Node.js when:

  • The service is request-response with a database.
  • Speed of development matters most.
  • The team is already working in TypeScript.

I reach for Go when:

  • The service involves heavy concurrency.
  • It does background processing or CPU-heavy work.
  • It needs to be deployed in resource-constrained environments.

Both are excellent. The skill is knowing which to reach for, and being comfortable enough in each that the decision comes from the workload instead of habit.