Some time last year, I decided to dabble with Go, the programming language, not the board game. As much as people hyped it up as being simple and elegant, I was not exactly fond of the syntax. Certain things threw me off like:
- Types after method arguments
func sayHi(name string){
- Variable declaration using “:”
name := "sam"
- Pointers
Eventually, I was able to wrap my head around it and made a basic web API. The API had one endpoint that accepted a URL for an Rss feed, fetched the feed, cached it in memory and returned it in a response. I was dabbling with making an Rss reader app with Ionic, when I ran into CORS errors with some sites. This Rss Proxy API was set up to be a way around that.
I implemented the API twice. First time in Go and second time in C#/Asp.net core. They both performed well, however there was a noticeable difference when I tried to containerize them.
The Go image (22.6MB) was under 1/10th of the size of the Dotnet image(358.51mb). The Go image could have been smaller but I added a Swagger User Interface, to mimic the functionality that Dotnet provides out of the box. Its resting memory utilization was also much smaller than Dotnet, with the Go container using 6% of RAM while the Dotnet container used 18% or RAM.
There are probably some ways to optimize the Dotnet image. I tried using chiseled containers , but ran into issues getting it to work. With time I imagine the difference in image size between Dotnet and Go APIs would decrease.
Leave a Reply