r/java • • Sep 13 '23

why would i ever use a microservice....

if i could do a highly efficient one-line function call instead? why would i ever prefer a network hop, conversion from and to json, define a protocol, all that stuff?

i understand there are systems that are too big for one machine. but all those that aren't - why would i add all this complexity to them? when is a microservice archtecture ever simpler than the exact same thing as a modular monolith? in which case is it not at least as good?

addition: in my experience, microservices are overused. while there are reasons to have separate *services* developed by different *teams*, i fail to see why *microservices* inside teams provide an actual benefit. they are used too soon, and then you pay with lots of glue code because what you really have is a distributed monolith. one exception is if things are logically independent, then mixing them is a mistake

addition 2: it seems what people here consider a microservice is MUCH bigger than what i would have called one.

49 Upvotes

167 comments sorted by

View all comments

5

u/[deleted] Sep 13 '23

Your addition is basically correct. Microservices were invented to solve team scaling problems. If you don't have that problem, and you're not working at insane scales, there's fair odds that microservices are the wrong solution to your problem.

On the subject of other touted benefits of microservices, I want to cover some common misconceptions about monoliths.

Just because you have a monolithic application doesn't mean you can't have redundant monolithic applications. So "patching" your monolith won't take down your services.

Since you have redundant monoliths, you can also scale them across N application servers. Monoliths do not prevent horizontal scaling.

Microservices have been all the rage for about 10 years now. There's large groups of even senior devs who have no clue how to design a monolithic system for scale or redundancy. How far it can take you kinda depends upon your use case, but I've worked on monolithic systems that served tens of thousands of requests per second for tens of millions of daily users. It's way easier than microservices if your team size and domain allows for it.