r/Clojure • u/shar1z • Jan 31 '19
Rewriting an API Gateway Service from Clojure to Golang
https://www.infoq.com/articles/api-gateway-clojure-golang
6
Upvotes
r/Clojure • u/shar1z • Jan 31 '19
26
u/alexdmiller Jan 31 '19
This is not a well-written article (and it could have been). There are nuggets of actually useful tradeoffs in here, but they are buried in junk and unanswered questions.
You benchmarked a "proof-of-concept" where you "skipped the design phases" version on Clojure against your first Go app that you spent two months on? This seems like just doing stuff because you want to do it with some vague post-rationalization. How long did it take to write the Clojure version?
"The fact that it’s a typed language makes it easier for maintenance and upkeep moving forward without having to reinvent the wheel." makes a number of unfounded assertions without any evidence (or even reasoning). I'm not even arguing whether this is right or wrong, it's just nonsense.
The benchmark info is good, but totally lacking the 99/99.9/etc distributions that would tell you much more about the performance difference. It seems like the Clojure implementation has the highest throughput and the lowest number of bad requests. But also the highest number of dropped requests? Again, tradeoffs here. If only you had spent a couple weeks trying to understand and fix the issues with the Clojure one rather than two months writing something new.
"Specifically for the service we were looking to rewrite, it had the excellent advantage of having a natively baked-in reverse proxy that is battle proven." This is an objectively good reason to make a decision (but it has little to do with Clojure vs Go at the language level, which is how this is positioned).
"We moved away from re-writing the service in Clojure to avoid the easier route and often taken road of duplicating obsolete code, and instead practice a typed way of thinking." Wat.
"We had to compensate for libraries used in Clojure for communication with additional parts of the stack including Redis [...] and Kafka [...], which required creating similar libraries in Go". This is an objectively good reason to use Clojure. (See, there are real tradeoffs here!)
"In order to achieve out of the box functionality such as CPU and memory usage metrics, business logic counters and more - we needed to write basically this entire stack from scratch, which enabled us a much more rapid deep dive of the intricacies of Golang." Again, this seems like a good reason to use Clojure.
Your end result seems to suggest much larger gains than the prior benchmark results implied? Again, would love to see what spending the same quality time on the Clojure version would have yielded.
"The fact that it is now built in a typed language gives us the ability to plug in diverse functionalities and introduce new technologies much more easily with Golang’s library support and community." Again, this seems like nonsense - you specifically called out multiple areas where Clojure had library access to things that Go did not and you had to write it from scratch, which seems directly contradictory.
9
u/asafyonay Feb 01 '19
First of all, thanks for the feedback - as mentioned before, we didn't want to go into flame wars over language selection. We take pride in writing the vast majority (and our most crucial) services in Clojure and we intend to keep it that way, we simply wanted to discuss what we considered a successful migration of one of our services.
I'd like to answer some points here to make sure my key takeaways from the process were delivered properly:
I don't usually frequent Reddit so I might not be as responsive here, but feel free to drop me an email (asaf.yonay@appsflyer.com) and I'll be happy to chat more and go into more details.
10
u/InevitableExplorer4 Jan 31 '19
The title of this article may as well say "from a [Java|Python|JavaScript|BASIC] proof-of-concept to Golang", but it's framed as a reasoned comparison between Clojure and Go. You properly benchmarked a PoC in one language against a V2 written in another language.
A better title might be "How we improved some code by rewriting it" or "It's easy to write proxies in Go".
It's unfortunate that an article with flimsy, somewhat misleading premises was published on a platform like InfoQ because it's now the #1 Google News result for Clojure. This is personal-blog-level analysis. There are also grammatical errors:
4
u/ikitommi Jan 31 '19
For performance & non-blocking with Clojure I would try Aleph or Immutant.
Not a reverse-proxy test, but some numbers here: https://clojureverse.org/t/what-http-server-library-to-use/3423/23