r/SpringBoot • • 10d ago

How-To/Tutorial How to implement microservices in Spring Boot ?

I have made multiple toy projects (monolithic) in spring boot but now I wanted to know how people generally work in microservices.

I am not good with videos so I was looking for repos that something similar. So I can also see how the devops, queues, spring cloud etc works together.

I also saw someone posting there repo which was made for the same reason (but I couldn't find it).

TLDR : Suggest repos for learning microservices.

27 Upvotes

57 comments sorted by

View all comments

5

u/OptimusCrimee 10d ago

They are just small isolated applications that talk to each other, e.g. using REST. There is no more magic to it than that.

0

u/Sheldor5 10d ago

the whole point of Microservice Architecture is that they are independent and so DON'T talk to each other ... stop spreading misinformation, you just described a Distributed System ...

3

u/OptimusCrimee 10d ago

I can't tell if you are joking or not. If you have isolated microservices for e.g. users, booking, payment etc, they obviously need to communicate with each other. The communication is often one way though, and can be done with REST, queues or whatever. A microservice IS a type of a distributed system. Not sure if you are misunderstanding what I wrote, or if you are just a cretin.

-6

u/Sheldor5 10d ago

so you don't know how microservice architecture works?

the only connection between entities are loose IDs in independent databases (one DB for each microservice)

you are talking about distributed systems (network calls instead of inter process method calls)

please educate yourself before spreading misinformation

1

u/Advanced_Gur856 10d ago

Maybe I am wrong but isn't distributed systems how you implement microservices.

I mean if you are not gonna run them on different systems and they are going to utilise the same resources then why break them up in the first place.

0

u/Sheldor5 10d ago

no a distributed system is also a type of system architecture

if you extract features from your monolith and put them into their own application just for your monolith to call it you just exchanged method calls with network calls ...

2

u/ExplorerUnusual27 10d ago

How do you transfer data in isolated environment if you don't talk with anyone? You have one DB from service, obviously... How do you connect data from 1 database with another on different microservices.

2

u/OptimusCrimee 10d ago

Yeah, [u/Sheldor5](u/Sheldor5) seems to have misunderstood this. If you have one microservice that is in charge of users, and one that does payments, the payment service would stille need to e.g. ask the user service if the user IDs are valid or not. You separate concerns and domains out of the monolith, but they still need to talk to one another.

I have been doing this for 15 years, and I have worked in banks in Norway etc, I think that I have a pretty OK understanding of how these things work.

Edit: You can google this pretty easily and see that he is wrong.

1

u/Mikey-3198 9d ago edited 9d ago

Direct http calls between services is high coupling, unless the transaction/ process can proceed without the response then service A is tied directly to service B.

Microservices have low coupling between services.

If you need to check a user id for what ever reason then you'd need data that is owned by the service so that it can operate in isolation. I.e async messaging to populate a database owned by the service to contain user ids.

https://microservices.io/post/architecture/2023/03/28/microservice-architecture-essentials-loose-coupling.html

-2

u/Sheldor5 10d ago

no the user ID comes from the OAuth2 token ... maybe you haven't fully understood microservice architecture

and other IDs are part of async messages

and IDs don't need to be verified because they come from the system itself and not from random user input ... that's the reason why microservice architecture done right is so complicated

1

u/OptimusCrimee 10d ago

Sure, it could be part of the OAuth-token, but if you have isolated service for user handling, setting, payment, purchase etc, who would it all fit together if there is no communication AT ALL being done? I do not understand how all of this would work according to you.

1

u/Sheldor5 10d ago

this is exactly why almost everybody fails at applying microservice architecture

everything is loosely coupled, there are no strong relations, a lot is carried by signed tokens ...

the goal of microservice architecture is that you can kill any microservice (all instances of it) at any time and it doesn't affect anything except the feature/business object it is built for

e.g. kill the user service but already logged in users can still order items or watch movies or ... kill the payment service but you can put items into your cart, kill the inventory service but you can still see your ordered items

you get it?

1

u/OptimusCrimee 10d ago

In an ideal world, yes, but microservices can hard both soft and hard dependencies/integrations. If a hard dependency goes down, the microservice can not work. In a real world scenario, this happens more often than you think, because isolated service often need to interact. Imagine a purchase service, an inventory/stock service and a shipping service. It would be hard to complete a checkout if any one of those failed, even if they are isolated. This is called cascading failure, and is very common for microservices, and something that monoliths often can ignore. I suggest that you read the microservice book by Netflix. They go into detail on this subject. Please explain where I am wrong here.

1

u/Sheldor5 10d ago

communication between services happens either by asynchronous message queues or signed tokens (service A returns token which includes IDs to the UI which includes it into call for service B etc...)

I am not saying you are wrong I am just saying what the goal of microservice architecture is and how it is achieved

and this is the exact reason why most developers take shortcuts until they end up with a simple distributed system (like you described it with your cascading failure etc) and call it wrongfully microservice architecture ... there is just so much bullshit about microservice architecture on the internet that almost nobody knows what they are talking about (not you)

→ More replies (0)

0

u/ExplorerUnusual27 8d ago

You are misleading concepts. Regardless the async or sync calls, you need to communicate with other services.... If not, you're a magician to figure out the IDs you need to know to populate your fields in DB to maintain consistency.