Node.js is Good; Go is Better

Overview

The article discusses the transition from Node.js to Go within SafetyCulture's microservice architecture deployed on Kubernetes. It highlights the challenges faced with Node.js, such as technical debt and performance issues, and illustrates the performance improvements achieved after refactoring services to Go.

What You'll Learn

1

How to refactor a microservice from Node.js to Go

2

Why Go can improve performance in microservices

3

How to implement gRPC endpoints for backward compatibility

Key Questions Answered

What performance improvements were observed after migrating from Node.js to Go?
After migrating to Go, latency was reduced from 10ms to 3ms, CPU usage was cut in half, and memory usage decreased from 180MB to 40MB per pod. These improvements enhance user experience and scalability.
What challenges did SafetyCulture face with Node.js?
SafetyCulture encountered challenges such as increased technical debt due to schema-less JSON and various JavaScript flavors, which made the codebase difficult to manage as the team and product scaled.
What technologies were introduced alongside Go?
Along with Go, SafetyCulture introduced PostgreSQL, Protocol Buffers, and gRPC to enhance their microservice architecture, aiming for better performance and maintainability.

Key Statistics & Figures

Latency reduction
from 10ms to 3ms
This improvement was observed after migrating the service from Node.js to Go.
CPU usage reduction
cut in half
This was a direct result of the refactor to Go.
Memory usage reduction
from 180MB to 40MB per pod
This significant decrease in memory usage was noted after the transition to Go.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Key Actionable Insights

1
Consider refactoring performance-critical services from Node.js to Go to achieve significant latency improvements.
This transition can lead to reduced resource consumption and enhanced scalability, especially for services with high request rates.
2
Implement gRPC endpoints for new clients while maintaining existing HTTP/JSON APIs for backward compatibility.
This approach allows for a smoother transition and ensures that current clients can still interact with the service without disruption.
3
Evaluate the use of schema-less JSON in your applications to avoid potential technical debt as your codebase grows.
As projects scale, the complexity of managing schema-less data can lead to maintenance challenges, making it essential to consider structured alternatives.

Common Pitfalls

1
Relying heavily on schema-less JSON can lead to increased technical debt.
As the codebase grows, managing schema-less data becomes complex, making it harder to maintain and reason about the data structure.