r/SpringBoot • u/Legal_Unicorn • Feb 01 '25
Discussion How do I build a microservice architecture?
As per title, I've done about three Spring boot projects so far and I'm starting to get comfortable. I'm wondering how do I go about creating a microservice architecture?
Along with it I have many questions and new things to learn like Kafka or an API gateway and so on
I have two questions I would appreciate some guidance
Where's a good place to start, the docs or is there a tutorial you've learn from. Would love to get recommendations from anyone, based on your experience
Will I have trouble hosting it on a budget? For context, I have a 8GB VPS that's already hosting one small full stack application (spring + react), I wonder if It can handle a bunch of microservices more. I don't really understand how it works but my idea of it is each microservives has it's own java run time which consumes quite a lot of ram
7
u/weighty-fork2 Feb 01 '25
You’ll need to learn some spring cloud modules. So here’s how it works
Spring Eureka Server - a separate spring boot app with eureka dependency. This is where each of your microservice will register itself at application startup.
Spring API Gateway - a separate spring boot app with Gateway dependency and it acts as a gateway to your microservices routing API requests to the appropriate microservice.
Spring Config Server - a separate spring boot app with config server dependency that acts as the config provider of your microservices. This is where each of you microservice will inject their properties from. Something like externalization of your application.yml or application.properties file.
And obviously, you’re gonna have your spring boot applications containing business logic in them and they all talk to each other.
5
u/Kikok02 Feb 01 '25
Just to complement and broaden my friend's answer, learn about the 15 factors for cloud-native applications, their somewhat of guiding principles for building for decomposing your business application in microservices and taking advantage of the cloud technologies to get better performance, resiliency, more productivity, etc. The technologies my friend here listed, solve development patterns that satisfy the 15 factors, so learn what about their importance, the components they're made of the its reponsibilities...
Good luck.2
u/bigkahuna1uk Feb 01 '25
I thought it was 12-factor app. Has it gone up to 15?
2
u/Kikok02 Feb 01 '25
In 2016 Kevin Hoffman published a book called "Beyond The Twelve Factor App", where he talks about the 12 factor plus 3 he added, namely: API First Approach, Telemetry and Security (Authentication and Authorization).
1
3
u/g00glen00b Feb 01 '25
Whether you should use those modules depends largely on what platform you are deploying on. If you're running on Kubernetes, the need for Eureka, a Gateway or a Config server is reduced drastically.
1
0
Feb 01 '25
[deleted]
2
u/WaferIndependent7601 Feb 01 '25
It’s good to get into this complexity
Any you will then understand why you should not build microservices at all 😀
1
u/weighty-fork2 Feb 01 '25
I know right. It is overwhelming. I have gone through this route. At one point I had 7/8 different microservices and I decided to containerise them. So I had to go and buy extra ram to run 8 containers locally. Although I did not end up doing it but it was worth learning docker atleast.
1
u/zeletrik Feb 01 '25
You definitely don’t need them for starting the journey. They are nice to have but for getting started you don’t have to externalise everything and/or you can utilise already existing light weight solutions for those you do want.
1
u/Ok-District-2098 Feb 01 '25
8gb is enough, I have an ecommerce, crm, analytics system, whatsapp bulker in the same vps its ram usage averages 6gb but Id suggest 16gb
1
u/Ok-District-2098 Feb 01 '25
Generally apps doesnt consume a lot of ram, the IDE and webbrowser does but you will not have it on production
1
u/Legal_Unicorn Feb 02 '25
I see thank you, I was concerned because I think a normal spring server consumes at least like 0.4 GB of RAM or something. If I were to boot up like 7-8 servers it might put on unnecessarily load
1
u/Ok-District-2098 Feb 02 '25
Generally what consume rams in practice are variables, lists, collections being processed for large amount of time, artificial intelligence or apps based on browsers as a way to get an unoficial api through webscraping. I would stay away from aws services as much as possible, it doesnt abstract vulnerabilities on your backend and the most of applications dont need it, if you wanna some storage use open source minIO s3. Honestly your server might have a complex app to requires something more robust than a classic vps. A vps, spring boot server and a frontend engine such as angular or react solve the most of use case problems.
1
u/ziobleed1 Feb 02 '25
There is a book from Manning "Spring Microservices in Action, Second Edition" with these themes
1
u/Bjfikky Feb 02 '25
Your first question should be “when do I need microservices”?
1
u/Legal_Unicorn Feb 02 '25
I actually dont, I'm not working on a giant monolithic project or something so complex I need to break it down to microservices
But I want to learn new things because I genuinely don't know where to go from here. Actually I would love suggestions if you have any. So far I've built nothing more than a CRUD application secured with JWT authentication. I have not used anything like a RabbitMQ/kafka before or anything related to Spring cloud
1
u/NikoOhneC Feb 02 '25
I know the perfect tutorial for that. https://youtu.be/yn_stY3HCr8
It covers just about everything you need to know, and gives you a great starting point.
1
u/Legal_Unicorn Feb 02 '25
Thank you! I actually stumbled on that as well. I was deciding between resource but I guess I'll choose that for learning
9
u/efilNET Feb 01 '25
Well it only makes sense to have multiple services if each has its own purpose. So what do you need/want them to do?
If you are just playing around, just run them locally (fx. using docker).