Is Spring Boot a Feasible Option for Front-End Development?

Is Spring Boot a Feasible Option for Front-End Development?

Introduction

Spring Boot is a Java and Kotlin-based full-stack/microservices-focused framework that is incredibly powerful and enterprise-ready. It has been powering millions of websites at scale. But is it a viable alternative to other technologies like Next.js and others? In this article, we discuss the pros and cons of both.

Table of contents

  1. Why spring boot ?
  2. What is this enterprise grade ?
  3. Spring is harder to setup, harder to build basic building blocks, easier to maintain
  4. Spring boot can play well with other frontend libraries like react, angular or vue
  5. Spring Boot as an outlier in frontend world
  6. Conclusion

Why spring boot ?

Before delving into Spring Boot, it's essential to discuss why it's worth considering. Why not use popular options like Next.js, Svelte, and others?

This is a valid question. Spring Boot is older than most frameworks available today. It may be handling more traffic than many other frameworks and, more importantly, is used to solve almost every kind of problem on the internet with enterprise-grade solutions.

What is this enterprise grade ?

Developing a solution for a small team of four people is quite different from building something for a 400-person team. Over the years, this larger team will involve more than 4,000 different individuals. The products they create will be used by millions of users, face thousands of security attacks, and encounter numerous fraudsters attempting to breach and exploit their creations.

The quality bar for enterprise-grade solutions is higher, not only in terms of technology but also as a people problem. Take security, for example. If security is complex, individual developers might make mistakes. Therefore, it's essential to make it extremely simple. As a result, it's acceptable to invest significant effort in building security primitives initially, as long as they are easy to use later on.

For many enterprise-grade frameworks, this is the challenge you will encounter. They are more difficult to learn, set up, and configure. However, once everything is in place and ready, daily operations become much easier to manage.

I often use the example of microwave ovens and CNC machines in engineering workshops. Microwave ovens have many buttons that we use daily. Typically, the 30-second button is the most frequently used, but we also use other functions. However, if you visit a factory and observe some of the machines, you might be surprised. They may have only three buttons. Two are for configuration, which is done perhaps once a year. A specialist flies to your factory, presses those two buttons in different combinations to achieve a specific result, referring to a 1,000-page manual. Then, they fly back. Your shop floor worker presses the third button for the rest of the year. The reason for this is that all the complex work is done by a highly specialized engineer once, making the life of the less skilled shop floor worker incredibly simple. Most of us prefer microwaves and would never want to touch a CNC machine because the oven is easier to use.

Spring is harder to setup, harder to build basic building blocks, easier to maintain

Spring Boot can be somewhat challenging to use. When starting a new project, you may find that much of it seems like pure magic. Adding something to the application.properties file can significantly alter the behavior of various aspects. Annotations, though small, conceal a great deal of complexity. Even form validations can be entirely handled by annotations.

Spring supports a wide range of security and authentication mechanisms. You can integrate with LDAP, OAuth, and many other systems using just a few lines of code. However, it may not always be clear where all the code is located.

If you encounter an issue, you will likely find at least 100 people facing the same problem, each solving it in a different way. When something doesn't work, debugging can be frustrating due to all the hidden complexities.

However, once you have all these pieces aligned and everything is functioning properly, it won't break easily. The jar can be deployed in the cloud, and it can run for years without requiring any upgrades.

Spring boot can play well with other frontend libraries like react, angular or vue

There is a common misconception that Spring Boot restricts your rendering options and forces you to use ThymeLeaf, Spring's templating language. This is not true. Spring Boot is primarily a microservices-focused framework that often renders raw API responses like JSON, but it can support almost any templating library available. It is widely used with FreeMarker if you do not like Thymeleaf.

But lesser known aspect is that you can also use webpack, node and react etc. with Spring Boot. You can indeed setup your pipeline where you can make your javascript code part of your spring project, build the final assets as part of Spring's build process and and deploy the bundles into the Jar.

This can be achieved using wide variety of methods but people find it is simpler and easier to either

Simply use Freemarker and avoid React and other complexity altogether.

Use springboot purely for JSON output and let a separate frontend server like NextJS based server render the templates.

Generally you will find above two options better than making react/angular part of spring project itself.

Spring Boot as an outlier in frontend world

One reason Spring Boot is not typically viewed as frontend-friendly is because its approach to handling frontends differs significantly from other frameworks. In Spring Boot, developers must become familiar with a variety of templating languages, such as Thymeleaf and Freemarker. The chosen language dictates the structure of your frontend code. You'll create elements like fragments and macros to help build webpages, but these concepts are not similar to those found in frameworks like NextJS.

Thus, despite being equally expressive and powerful, frontend engineers familiar with Node.js might find themselves somewhat perplexed when examining Freemarker code.

It is also easier these days to have backend of frontends, having a nextjs based lightweight server that just renders UI by talking to a more robust Spring boot backend is a more common architectural model than purely spring powered webpage rendering.

Conclusion

Spring Boot itself isn't designed for building full-fledged frontends. It is a powerful backend tool that can also provide frontend features. The more common architectural pattern is to have a separate frontend server for your frontends and rely on Spring Boot for backends. However, its powerful templating language and other features can very well support frontend building, and where server-side rendering is critical, this can also be quite useful.

Here are our helpful articles about deploying nextjs on google cloud run and deploying spring boot applications on google cloud run.

Please email us requests for posts frontendeng@wiselandinc.com.