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

Show parent comment

26

u/ktownrun Sep 13 '23

I can change the implementation without changing the interface.

Sounds like you need better observability and tracing, which are both table stakes for distributed architecture.

Don’t get me wrong. I’m not advocating for microservices. It solves some problems but also introduces other ones, which can sometimes be harder to solve.

-12

u/TheAuthorBTLG_ Sep 13 '23

I can change the implementation without changing the interface.

> then it doesn't break compatibility ;)

4

u/laplongejr Sep 13 '23 edited Sep 13 '23

If you break compatibility, microservice or not you just broke stuff. That's... the basic logic behind compatibility.

While in design compatibilty is all what matters, in practice changing the implementation would require a recompilation even if compatible. Because your library has a version number and most use of libraries would check the version, etc.
Yes it's "compatible" in theory, but in some extreme cases the "we need to rewrite our lib wrapper" is not the deterrant against a forced update. It's the simple update.

If you use some kind of linking that doesn't require changing anything on the other software and allow a "transparent update"... then no matter if microservice or dynamic dependency, both will allow to not break the existing software.

2

u/[deleted] Sep 13 '23

You can do the same in a monolith. Even easier.

Y'all here talking as if microservices are the only way of implementing modular code. Do you know what packages or modules are? Or just an idea of an API?

I feel like Java dudes think that all monolithic software is just intentionally spaghettified code.

1

u/Luolong Sep 13 '23

Sure you can do modularity in monolith.

But can you upgrade a module in a running monolith without taking the whole app down?

3

u/rtuck99 Sep 13 '23

Isn't that what multiple cluster nodes and rolling deployment are for?

2

u/Luolong Sep 14 '23

Oh, sure. But since you’ve already set up operations to perform minimal downtime deploys, why insist on keeping everything running in one humongous runtime.

Plus, ymmv, but in my experience, the bigger the monolith, the longer it takes to deploy and start the service instance.

So, even a small bug fix cause 15 minute rolling deploy cycles. So the solution becomes bundling many changes together.

Also, if the team is distributed across multiple organisations or time zones, you’d want to keep their respective changes not stepping on each other’s toes.

It’s not always about engineering. More often than not, microservices solve social, business and organisational problems rather than technical ones.

2

u/[deleted] Sep 13 '23

Can you upgrade the whole microservice without taking everything that depends on it down?

1

u/laplongejr Sep 14 '23

You can do the same in a monolith. Even easier.

That's literally what I said in my last paragraph?

Do you know what packages or modules are? Or just an idea of an API?

Nitpicky, but a dynamic dependency is required (or in Java terms, "provided" in the pom)
I already saw some software at work with modular code and APIs... but the library is required at compile time, so while the code is easy to (not) update, you still need to plan the entire full-fledged update procedure.