Spring Boot vs Ballerina: Back-end For Front-end (BFF) Service
Well, if you are to write a BFF service and stuck in the above dilemma, this blog post would be a good read. I am writing this as I am learning Spring Boot. So if anyone know better way of writing the below Spring Boot program do let me know :). Spring Boot and Ballerina are both good for writing microservices. But they are very different from one another. The purpose of this blog post is to learn about similarities and differences of these two different technologies. This blog post is based around a simple BFF service which is implemented in both Spring Boot and Ballerina. I will explain the BFF service in a minute. But before that following are few details I was able to gather after writing the same BFF service in both technologies.
Hello-World level comparison of two technologies can be found here!
Interesting enough? Now let’s see what kind of BFF service that ended up with above result.
Performance test were done on a machine with Intel(R) Core(TM) i7–6500U CPU @ 2.50GHz and 8GB memory. Client was JMeter. This test is done only for getting some rough idea.
Details of the BFF service
The BFF service in question represents a microservice in a vehicle renting system. As depicted in the image, this service simply returns back a trimmed version of the original response to the mobile-app upon receiving the HTTP GET request. Last part of the request URL represents a unique ID of each vehicle.
Look and feel of each service
Following is the code for BFF services written in Spring Boot and Ballerina. Please note that I have used IntelliJ IDEA for Spring Boot and VSCode for Ballerina.
Link for the Spring Boot Code and link for the Ballerina Code.
Experience in Each Technology
Your experience is always colored by technologies you use. Therefore, following is a high-level break down of sub-technologies related Spring Boot and Ballerina.
MapStruct is a mapping tool recommended by one of my colleague. Apparently, there are many other technologies and frankly speaking I don’t know which one is the best. But went with MapStruct because it allowed me to implement the requirement in a nifty way.
Few highlights of Ballerina
As Ballerina is built for this purpose, you could directly feel that you are writing a network related application. Ballerina makes you aware and deal with security and network-related failures.
Also, BFF service written in Ballerina is easy to read thanks to its language abstractions and diagram feature. Following is the diagram generated for the written service.
Conclusion
So what is the answer to the dilemma discussed in the beginning of the blog post ? I don’t know. Each individual can decide the answer to that. I hope this blog post is useful in making that decision. In the coming blog post I will be looking into how to deploy this service in Kubernetes and Enable outbound resilliency for each service.