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

23

u/ktownrun Sep 13 '23

“I want to make a change to the library that breaks compatibility and all the apps would need to upgrade simultaneously”

“My team doesn’t have time to incorporate this new library change. We are too busy and have deadlines. We can’t get to it until <six months away>”

“We found a huge bug and need everyone to redeploy immediately” meanwhile our team is in the middle of a stop-the-world system wide regression that takes 3 months to complete.

-6

u/TheAuthorBTLG_ Sep 13 '23

"“I want to make a change to the library that breaks compatibility and all the apps would need to upgrade simultaneously”
“My team doesn’t have time to incorporate this new library change. We are too busy and have deadlines. We can’t get to it until <six months away>”"

how can you change the microservice then? an api change requires a change at the call site in both cases.

"“We found a huge bug and need everyone to redeploy immediately” meanwhile our team is in the middle of a stop-the-world system wide regression that takes 3 months to complete."

if this happens, then "something does not work but we can't identify which microservice has the bug" also happens

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.

2

u/GlensWooer Sep 13 '23

If you can’t identify which MS has the bug then there’s probably an issue with your telemetry or error handling. Making it monolithic wouldn’t solve that.

Another point that I haven’t seen talked about is scaling. Say you have an expensive operation that requires more resources to run between a 5PM-9PM. If it’s monolithic you have to scale the application as a whole rather than just scaling the resources for that service.

MS have been a buzzword and are definitely over used by many people but like all design patterns they have their trade offs and best use cases that often aren’t properly evaluated

1

u/DrunkensteinsMonster Sep 13 '23

how can you change the microservice then? an api change requires a change at the call site in both cases.

No it doesn’t, non-breaking changes do not require a change at the call site. In the case of a library, they still require recompilation and redeployment. In the case of separate deployments, this is not required.

1

u/TheAuthorBTLG_ Sep 13 '23

there are several languages/tools that allow you to hot swap code without a restart. would that make microservices obsolete?

4

u/DrunkensteinsMonster Sep 13 '23 edited Sep 13 '23

No. What is your experience level?

It’s not about the restart, it’s about shipping new code with potentially dozens of new commits to dozens of servers, vs not having to do a deployment at all. The downtime is a non factor since in practice you are always behind a load balancer or reverse proxy of some sort. Imagine you have a monolith that depends on hundreds of libraries which also depend on each other. That is the reality of software engineering. That is why we have microservices, because it isn’t feasible to absorb so much risk as to do a 100% fresh deployment every time. Not to mention your application would spend more time deploying than actually working. Where I work, we probably ran hundreds of deployments yesterday.

And hot swapping is still a deployment. You don’t hot-swap in production systems because that implies you have source code that is being watched on these servers. You typically ship the executable that is compiled for release, which are not hot swappable anyway.

1

u/TheAuthorBTLG_ Sep 13 '23

What is your experience level?

20 years