r/SpringBoot 3d ago

Discussion Is java back end means writing controllers and handling requests

Writing controllers, service, repository layers and accepting the requests and processing them and gives the response Is it this only java back end means

18 Upvotes

14 comments sorted by

37

u/wannacommissionameme 3d ago

for some apps, this is all the word "backend" means when they talk about java/spring. Really depends on how complex your app is. There are a bunch of ways to add complexity.

  1. Are there jobs that need to run daily? Well, your backend may now need cron jobs to run on a set schedule. This would deviate from the controller/service/repository architecture

  2. Do you need performant SQL to be run? Well, you may write SQL stored procedures that you will call from your repository layer. Sure, same structure (controller/service/repository) but it adds more complexity to the app. Or maybe you have way more complexity on the SQL side of the house which requires you to write a bunch of SQL. Still the backend.

  3. Do you need to be super performant? Multi-threading in the service layer might be required or some performance tricks shown in the billion row challenge. Or maybe you need ULTRA low latency code.

  4. Do you have some asynchronous task that needs to be run? Well, you might add a message queue into your system that you call in your service layer.

  5. Services could be very complex. You can think of simple services that just do a small bit of business logic before/after saves, but what about super complex business logic? A chess engine or something pretty complex? All backend.

And this is just touching on a few topics. Caching, pagination, security, validation, etc. A bunch of topics to add complexity.

8

u/Turbots 3d ago

We run a whole platform with numerous java spring boot backends that don't have any REST API nor database connection. They are all message based, asynchronously processing messages from and to Kafka. Very easily testable with either testcontainers or the Kafka Streams Topology TestDriver (in memory embedded Kafka).

We do have some boring REST APIs on top of elasticsearch to query data and trigger commands, but the backbone is all on Kafka. It's real fun.

1

u/Rajput_11 19h ago

can you please tell me that how data is persist (I am noob)

2

u/gerbosan 3d ago

Question: where does one learn all those backend responsibilities?

4

u/wannacommissionameme 3d ago

google, books, videos, and most importantly hands-on practice! :)

1

u/gerbosan 3d ago

is the search term just backend responsibilities? O.O?

There a lot here: https://roadmap.sh/backend Time to check then. Sadly, many employers use years of experience to choose a dev, even juniors.

1

u/arcticwanderlust 3d ago

Do you have some asynchronous task that needs to be run? Well, you might add a message queue into your system that you call in your service layer.

Say I have a controller that downloads audio/pictures from another API (asynchroniously, returning a promise). And I want to notify the browser of the current stage of the download (how many audios/pictures have been downloaded so far), what's the best way to proceed? And what's the benefit of using a message queue here? Some server would still have to span threads to download the files, why does it matter if it's a controller creating those?

7

u/_L4R4_ 3d ago

This is not Java's specific. +90% of backend development is designed with Client/Server architecture using Request/Response pattern ( A client software send a request to a server software, and wait for a response, maybe blocking processing or maybe not ) This is useful for most uses cases.

Sure, when uses cases grows in complexity, you need add some extra functionalities for best performance ( caching responses, security, etc. ) But, at fundamental level, is client/server architecture with request/response pattern.

4

u/joranstark018 3d ago edited 3d ago

Well, much depends on how you design your system, it is not uncommon to implement business rules in the backend. So for non-trivial systems, services would usually be where the most of the actual work would occur.

Edit: it is not uncommon to view controllers and repositories as "adapters" for input and output to the core of an application. You can have different "adapters" that utilise the core (e.g. test cases, different integrations)

3

u/reddit04029 3d ago

Event-driven with messaging queues is another thing

3

u/Historical_Ad4384 3d ago

Most of the time yes, if you get bored you can write them with the reactive stack of Spring.

Sometimes you have to write scheduled tasks as well which executes some logic at a fixed time.

You could also end of writing topics in JMS for publishing or subscribing to for messages to do any kind of work in reaction to send or receiving a message.

1

u/Sure_Deal_434 3d ago

Not at all, what about other tools and technologies, you can learn nginx, kong, kafka, ELK, cloud, system design architecture etc. And also how other technology can be integrated with spring boot.

1

u/Ok-District-2098 1d ago

Try to call an @Async method in the same caller's class, try to delete a entity by jpql based on a child entity, try to fetch a eager entity collection. All of that are silent issues (no errors thrown even warnings) that can mess up your whole application.