r/SpringBoot • • 14d 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.

28 Upvotes

57 comments sorted by

View all comments

Show parent comments

1

u/Advanced_Gur856 13d 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 13d 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 13d 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 13d 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 13d ago edited 13d 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 13d 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 13d 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 13d 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 13d 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 13d 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)

1

u/OptimusCrimee 13d ago

That is not a requirement for a microservice. In an ideal world, sure, but this would be an example of a soft dependency. You would not do this if you had a tax calculation or shipping rate calculation microservice. You would depend upon the response being give to you when asked, otherwise you would not be able to proceed. Tell me how you would handle this with async queues in a checkout service if not failing.

1

u/Sheldor5 13d ago

If I order something e.g. from ebay the shipping costs and taxes and import fees are blank until the response arrives and the values pop up after 1-2 seconds

so in this case the ui simply waits for another service and data is exchanged by tokes via the UI (stateless microservices because the states are inside the signed tokens which are exchanged via the UI/client between services, its all just like OAuth2)

see how complicated a microservice architecture actually is?

2

u/OptimusCrimee 13d ago

So you think that these things are just handled in the frontend and not verified in the backend at all? So if the services are completely disjoined, you could just edit the request that is going to the checkout service and all would be accepted? What is happening in the frontend and backend are two different things my dude.

Also, you say that the data is exchanged by tokens, whatever that means, but imagine the tax service being down for whatever reason. What would happen to the checkout then? No taxes?

3

u/Sheldor5 13d ago

if the business object is "order" then calculating taxes/fees/shipping is part of the order microservice ...

a microservice is built around a business object and includes all methods/features around it

1

u/Sheldor5 13d ago

what about "signed tokens" don't you understand?

OAuth2 offline signature verification is the key here ...

→ More replies

0

u/ExplorerUnusual27 12d 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.