Spring boot and kotlin as full stack framework as an alternative to rails, nextjs and laravel.

Spring boot and kotlin as full stack framework as an alternative to rails, nextjs and laravel.

Spring boot is an extremely powerful and enterprise ready Java based framework which also works well with Kotlin. However learning curve for Spring boot hass been steep and that has intimidated many individual developers from exploring this powerful framework. However in this tutorial we will take you on a step by step guide to setup a basic Spring Boot application with basic features and then deploy it on Google Cloud Run.

Table of content

  1. Why spring boot ?

  2. Spring boot for full stack development

    1. Advantages of using Spring Boot as fullstack framework.
    2. Disadvantages of using Spring Boot as fullstack framework.
  3. Spring boot compared to Ruby on Rails

  4. Spring boot compared to Laravel

  5. Spring boot compared to NextJs

  6. Conclusion

Why spring boot ?

Among all the major web frameworks Spring boot is one of the most performant framework. It can run on simple small server with tiny memory and CPU footprint. But not just that, it is used in major large companies and has libraries for every possible scenario your application might ever face. Not only that, it is under very active development and has exceptionally large community.

But the real reason to use Spring Boot is that it is a very lindy framework. Unlike NextJs you will never be told that Spring boot should not be used for any reason what so ever. Unlike Rails, Spring boot is very performance focused and unlike Laravel it supports very modern language like Kotlin.

Spring boot is not too opinionated. It is a bit like Lego set where you can chose what you want and then do mix and match. For example you can use wide variety of ORMs with Spring or ust directly write your own JDBC code. You can use mustache, thymeleaf or freemarker as templating engine or sipmply chose to build somehting of your own. It can be easily containarized using a Dockerfile that is like 3-4 lines long.

Spring boot for full stack development

Spring boot has all the neccessary features to run a full stack site. The only problem is that you need to build such a site by picking up from wide variety of options you have right from the choice of programming language. You can either chose Java or Kotlin, for templating there are choices like Thymeleaf, Freemarker and Mustache. For Database you can use JPA/Hibernate or simply roll out something else or noSql databases.

Not only it is perfectly possible but all these different components are battle tested by probably millions of websites all around the world.

Advantages of using Spring Boot as fullstack framework.

  • Highly scalable and containarizable application.
  • Very easy to build as micro services architecture.
  • Battle tested by many large companies
  • Requires very little server resources compared to any other framework.
  • Spring boot has excellent support for enterprise grade security and lots of libraries to acheive complex integrations.
  • Kotlin has excellent support to create multi threaded applications using coroutines. An important feature missing for say PHP.

Disadvantages of using Spring Boot as fullstack framework.

  • There are far too many choices to solve any one problem.
  • Development might be little slower due to complexity of languages like Java or Kotlin.
  • Too many libraries and need to ensure comptibility.
  • Lack of sample code with exact combinations of libraries you need.

Spring boot compared to Ruby on Rails

If you are Ruby on Rails developer you will miss Rail's convention based configuration aspect. Rails nicely packs all the neccessary libraries together to give you one way to do everything. It all just works right out of the box. With Spring boot you will spend a lot of time fiddling with diferent aspects. For example how do I set my ORM ? Should I use JPA or something else etc.

On other hands you will notice that it takes literally few seconds to deploy a Spring boot app into the cloud, tests are simple and fast and the Spring boot server does not need anything like Nginx or Apache. It can scale very easily to very high QPS.

Rails has scaffolding which can generate lot of boilerplate code for you. However Spring boot does not come with any such feature. You will have to rely on your IDE to achieve this for you.

Spring boot compared to Laravel

Laravel is a popular PHP based framework. PHP is a language primarily designed for web applications and hence much simpler than Java or Kotlin to learn for this specific purpose. It is very easy to setup a PHP based website. However it is an interpreted language and hence is not as performant as JVM based spring boot.

Laravel also, provides a lot of common web features in one single framework and does not offer much options. This makes life easier for developers but less flexible. Millions of websites are developed using Laravel today. But scaling with it remains an issue and Spring boot has an edge over Laravel in this regard.

Spring boot compared to NextJs

I have built many web applications using NextJs. The problem with nextjs is that it is primarily a frontend framework which happens to have full stack capabilities. However it is much slower than Laravel and Spring Boot but faster than Rails. Another disadvantage of nextJS is that it is extremely resource intensive and has features like static site generation and server side rendering along with edge caching which makes it a bit complicated for full stack developers to make sense of.

Overall, I think it is best to avoid NextJS as full stack alternative but rather use it as front end for a spring boot based backend.

Conclusion

You can indeed chose Spring Boot for full stack development however it is also true that it is primarily used to build APIs which run as micro services. It has the primary advantage of performance but is poor in development velocity compared to Rails or Laravel.

Choose Spring Boot if you are building an API. Choose Rails or Laravel if you care about building a small app which you want to launch quickly.