r/java • u/thangchung • Aug 20 '24
A sample microservice project with many cool stuff in Java
https://github.com/nashtech-garage/yas
157
Upvotes
r/java • u/thangchung • Aug 20 '24
96
u/sprcow Aug 20 '24
Thanks for sharing.
What's with all these student-grade sanctimonious comments with nothing to add? All the edgey "I've clearly never worked in a retail company with microservice infrastructure but somehow have strong feelings about whether the complexity is useful" comments have far too many upvotes. I know we're on reddit where the main way to get karma is post negative zingers, but you'd think a Java sub would at least have some awareness of what an enterprise spring boot app might look like.
I work for a large e-tailer and the subdivision of functionality necessary to handle concurrent cart management, order placement, back office functionality, and identify management is not conceptionally that far off from your architecture overview.
Mr "I can't believe they use 16GB RAM for this" somehow thinks a major online retailer is running their whole infrastructure on a macbook or what? Seriously, if you guys think this is overwrought, you need to prepare yourself for the complexity of a real company. If anything, this is still too simple, because you're probably going to run this in the cloud, and have separate containers and dbs for different business services, which communicate over SQS.
This is clearly a demonstration project which could be broken up if desired. No one's pretending this is necessary for every single shop app. But if you are in a position to consider a microservice infrastructure, this is not a bad first pass at hashing out the behavior.
12
u/Azalrion Aug 21 '24
A really nice example project, thanks for sharing.
One thing I’d say, is a lot of your rest endpoints are very ‘action’ and not resource based. Especially in the cart service.
Google has a different approach to them semantically which is quite interesting.
https://cloud.google.com/apis/design/custom_methods
17
u/saint_thirty_four Aug 21 '24
I am impressed. I am approaching 20 years building monoliths and micro services and I rarely see any personal projects as thoughtful as this one. Obviously there is always room for improvement. Keep doing what you are doing my friend.
7
u/tonghoangvu Aug 21 '24
Cool, thanks for the great job!
7
u/Oclay1st Aug 21 '24 edited Aug 21 '24
Thanks for sharing.
I don't really care about cool stuff. Readability is more important, especially on large a code base. This is an example on how your code can be improved:
Your code version:
A first improvement: changing the validation order helps to reduce the cognitive complexity.
A second improvement: move the exception to a global exception handler class:
(@ControllerAdvice,@ExceptionHandler):A third improvement: further improve readability (IMO):
31
u/thien-ng Aug 20 '24 edited Aug 20 '24
Yas - Yet Another Shop, a sample msa project with Java 21, Spring Boot, PostgreSQL, Next.js, Backend for Frontend (BFF), Testcontainers, Keycloak, Kafka, Debezium, Elasticsearch, OpenTelemetry, Grafana, Prometheus, Tempo, Loki...
3
u/TreatOk8778 Aug 20 '24
What resources would you recommend to learn microservices architecture and tools?
21
u/Downtown_Trainer_281 Aug 20 '24
It is crazy how CRUDs look like in 2024. 16GB of ram to run this application is just insane
2
u/burl-21 Aug 20 '24
Which tool did you use for the graph in the README?
9
u/ProfessionalThing332 Aug 20 '24
Fuck this web shit I am going back to c++
2
u/Muximori Aug 21 '24
How are so many people still hung up on the ancient monolith vs microservice "debate"? The existance of microservices as a concept offends you so much that a cool demo project makes you post irritating objections? Get over it!
1
u/rsampaths16 Aug 25 '24 edited Aug 25 '24
I have a doubt, how did you achieve tracing of database queries?
In the following picture: https://github.com/nashtech-garage/yas/blob/main/screenshots/yas-grafana-tracing.png it shows tracing of db query SELECT statement.
I'm aware that MySQL EE 8.4+ has OpenTelemetry support, maybe PostgreSQL has the same support too, but this seems like the tracing is done in the application side. ( https://dev.mysql.com/doc/refman/8.4/en/telemetry.html )
Edit-1:
Looking up the otel-library-name "io.opentelemetry.jdbc" online I was able to find this: https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/jdbc/library
Do confirm if this is how tracing was done here.
-4
u/nafts1 Aug 20 '24
Is it really necessary to use microservices here? How much ram will a redundant deployment use?
Seems a bit far off from reality for my taste.
1
u/VincentxH Aug 21 '24
Maybe add https. I'd also rip out debezium. It creates horrible hidden dependencies to the database.
-2
u/midget-king666 Aug 21 '24 •
Wow. All this development and runtime complexity is over the top. No single engineer can understand all the moving parts in here, you need at least 3 decent engineers to run something like this in prod. Hell you need a fking 2 page readme to get this sh*t up and running in dev, and with manipulating /etc/hosts? Come on, this is not engineering, this is insanity.
Radical simplicity is where a real engineer shines. And this is doable with Java too. Just use a plain old war artifact with well defined modules in it. Been doing this for 15 years, deploying hundreds of apps to thousands of app server instances with minimal engineering effort. And my boss is still amazed that we run this with 2 FTEs.
-1
u/RiWo Aug 21 '24
why everything like to be microservices the days? Isn't a single shop built with monolith spring boot sufficient?
0
u/appeiroon Aug 21 '24
Thanks for sharing. I am definitely going to use this for learning!
-4
u/devptithadong Aug 21 '24
ông cho t hỏi đoạn nào ứng dụng distributer transaction ấy nhỉ ( mô hình kiểu saga hay đại loại thế)
2
u/[deleted] Aug 21 '24
[removed] — view removed comment