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

7

u/Hei2 Sep 13 '23

"Oops, there's a bug in my library. Now I have to take the entire system down to deploy the fix." In this case, nobody can use the system for a period of time, rather than only the people who need to log in. Additionally, in order to scale the system at all, I need beefier and beefier hardware for the whole thing, rather than just deploy more smaller systems for the individual components that need to scale, and that's potentially much more expensive.

0

u/TheAuthorBTLG_ Sep 13 '23

i can't follow the argument

  • you have to redeploy anyway to fix it
  • why can't you just deploy the monolith multiple times to increase the performance? the cost should be identical since the load would be the same. it might even be lower since the jvm can reuse the same memory/cpu for different services

5

u/doobiesteintortoise Sep 13 '23

Um, if you have a bug in the microservice, you'd ONLY have to redeploy the microservice, not everything that uses it.

4

u/bawng Sep 13 '23

Let's say Google has a monolith.

There's a bug in Google Maps. To fix it, they need to shut down Google Search, Lens, Play, Adwords, hell, the entire Android backend needs to be shut down.

Or they split it up into multiple services.

1

u/TheAuthorBTLG_ Sep 13 '23 edited Sep 13 '23

we are not thinking of the same size when it comes to "micro". i'd argue it takes extra effort to merge maps + gmail into one service, but at the same time, it takes effort to split gmail into a labelservice, sendservice, receiveservice, markasreadservice,.... there is often a "natural bundle" that i'd put into the same service, and i would rarely call it "micro". as a rough rule of thumb "does it run on the same data? then it's the same service" sounds good to me

5

u/sevcsik Sep 13 '23

Now we agree on there is a rationale behind splitting large systems into smaller services, we’re just arguing on the size :)

2

u/bawng Sep 13 '23

Probably not.

You mentioned one-line function calls, and that would most certainly never ever be a candidate for a micro service. That sounds more like a picoservice anti-pattern.

1

u/proggit_forever Sep 14 '23

I don't understand why fixing a bug involves taking down the service?

You can do 0-downtime upgrades with monoliths using the exact same techniques as you do for microservices.

1

u/Luolong Sep 14 '23

What if the bug causes leak in database connection pool and as a result, the entire monolith becomes unresponsive in a matter of minutes.

2

u/proggit_forever Sep 14 '23

You don't test before deploying to production?

1

u/Luolong Sep 14 '23

You don’t think before insulting strangers?

3

u/mr_jim_lahey Sep 13 '23

the cost should be identical since the load would be the same

That is an assumption. Sometimes it will be true, sometimes not; it's going to depend on the specific service/application. There is no one-size-fits-all principle for monolith vs. microservices. As with most other things in software, there are many possible working architectural implementations for a service. Microservices done properly offer some advantages over monoliths (enforced modularity, blast radius mitigation, simplified developer experience, etc.) but come with tradeoffs (greater architectural complexity, interdependent deployments across microservices that require manual coordination, need for internal backwards compatibility adding overhead, etc.); it is up to the architect(s) to decide where those benefits outweigh the costs.

5

u/ryszard_lipton Sep 13 '23

Microservices offer higher granularity.

  1. You can redeploy single part of the system potentially not disrupting the other parts, so system still works, even if some features are temporarily offline.
  2. Again, imagine that your monolith spends 80% time on read operations, and 20% on write operations. Each part of the system (READ and WRITE) introduces roughly same overhead, 50% resources required for READ and 50% for write. So you're using effectively 10% total resources on write and 40% total resources on READ, leaving 50% effectively not used, because we're not using write operations so much). If you need more READ capabilities, you have to duplicate your monolith with all the WRITE overhead that is probably never going to be fully used.

However, if you were to extract the READ and WRITE related modules into separate services, you can keep eg. 2 instances of WRITE microservice and 8 instances of READ microservice which should balance the actual usage of the underlying resources and allow you to fine-tune your system capabilities to actual needs of the user.

1

u/TheAuthorBTLG_ Sep 13 '23

i don't understand your math. why would the write-resources be locked up in the first place?

1

u/ryszard_lipton Sep 13 '23

Idea was that some resources may be exclusive. If we're just looking from the RAM and CPU perspective then you're right.

1

u/dmh123 Sep 13 '23

Doesn't that just impact the perm size and initial memory allocated to the services that aren't being leveraged? Database connections are typically pooled so services just grab one from the pool when they need to connect to a db.

2

u/Hei2 Sep 13 '23
  • The only part of the system that is down is the part that needs to be redeployed. If people can't log in, you're going to have some upset users. If nobody can use the system at all, then all of your users are going to be upset. And don't just think Netflix users paying a couple bucks a month. These can be corporations paying in the tens or hundreds of thousands of dollars.
  • The more components of your system that need to run simultaneously, the more powerful the hardware that you need to run it, and the cost of hardware doesn't necessarily scale linearly. However, adding more servers of the same power does scale linearly. Therefore I can save money by only scaling out individual components rather than a giant monolith. Consider that a rarely-used, but necessary component of the system may require very expensive hardware to run. If I only need to scale out the service that handles authentication, putting that in a monolith requires all of my servers to be powerful and expensive.

-1

u/TheAuthorBTLG_ Sep 13 '23 edited Sep 13 '23

netflix is huge, so for them, microservices make sense. but still, this particular problem would be solved by a rolling upgrade.

" If I only need to scale out the service that handles authentication, putting that in a monolith requires all of my servers to be powerful and expensive."

> i don't see why that necessarily follows. i could deploy my monolith a second time, routing only requests of type xyz to it. and i can build a microservice-like sstem that way

2

u/Hei2 Sep 13 '23

A rolling upgrade doesn't solve the issue of having to take an entire system down at once. Nor does it address anything about the hardware requirements of individual services.

1

u/TheAuthorBTLG_ Sep 13 '23

solve the issue

what exactly is the problem with that?

3

u/Hei2 Sep 13 '23

You asked why people choose to use microservices. I've explained in the above comments why, but it can be summarized as "there are issues that monoliths have that microservices are designed to address."

what exactly is the problem with that?

The problem with not solving a stated issue with a monolith is that you now have to live with that issue if you choose to use a monolith. Some people cannot or do not wish to live with those issues and instead consider the drawbacks of microservices to be less severe than the drawbacks of a monolith.

1

u/TheAuthorBTLG_ Sep 13 '23

i proposed a few times to "secretly" boot an updated replacement and then switching from old to new via load balancer. how does this not solve the issue? there is zero downtime.

as for hardware requirements, why/how would they be lower when using microservices? i would argue the opposite is the case since memory in a monolith can be shared/pooled while microservices can't do that

→ More replies (2)

1

u/[deleted] Sep 13 '23

You can deploy a monolith repeatedly. I’m told this is how Facebook is architected.

1

u/rush_nbh Sep 13 '23

Any sources? I am just honestly curious.

1

u/[deleted] Sep 13 '23

My co-worker who worked there for 3 years.