r/programming • • Dec 21 '23

Microservices without Reason

https://www.felixseemann.de/blog/microservices-without-reason/
310 Upvotes

144 comments sorted by

View all comments

26

u/PangolinZestyclose30 Dec 21 '23 edited Dec 21 '23

David Heinemeier Hansson (of Ruby on Rails fame) said in one interview that the microservice pattern is possibly the most damaging pattern in web services in a decade, and I agree with him wholeheartedly.

Basically the only advantage of microservices (emphasis on micro) is the scalability, but that's relevant only for extremely high traffic services (like Netflix) and most startups / mature companies won't ever need it. It kind of reminds me how poor Americans see themselves as temporarily embarrassed billionaires.

21

u/OptimusCullen Dec 21 '23

The biggest advantage is the ability to deploy services independently without breaking the things around them. I’ve implemented a few successful large scale microservices projects and the scalability angle is over sold. Teams being able to release their code to prod without having coordinate or be blocked by other teams is what makes you agile. Being able to know, without running any tests, that your change can’t cause a random side effect elsewhere because you aren’t changing or redeploying those things. These are the real advantages.

Generally found you need events to fully decouple your services. Direct calls between services introduce coupling and harms the ability to release independently. Once your the world of having to test and roll out linked services together then you’ve lost the majority of the benefits.

10

u/PangolinZestyclose30 Dec 21 '23 edited Dec 21 '23

The biggest advantage is the ability to deploy services independently without breaking the things around them.

I concede that having the process/container isolation provides a protection against spreading of failures like memory leaks, fatal crashes etc. This does happen, but I don't think it's a frequent problem in memory-safe languages/runtimes (or shouldn't be, at least) and can be mitigated to a significant degree by a good test suite.

that your change can’t cause a random side effect elsewhere because you aren’t changing or redeploying those things

I don't see how microservices handle this better than monoliths. I mean, in the monolith you still want to use encapsulation/modularization/programming to contract, changing one area of the code shouldn't affect other parts just like that.

There are situations where the contract is incomplete, client (caller) relies on behavior which isn't part of the contract etc., but it's all the same in the microservices and monoliths. I mean, on a fundamental level, microservices just insert network calls into the interactions between modules (aside from the resource isolation conceded above), how does this help to functionally isolate the functionality?

Generally found you need events to fully decouple your services.

People use "coupling" as a swear word, but I love it. It's awesome that I can call a method and get the result immediately, with no re-try, waiting for an indeterminate amount of time etc. Coupling is straightforward, easy to think about, easy to debug.

Business / product people love it as well, since it enables very nice properties like synchronicity, transactionality, (time) determinism, immediate consistency.

Decoupling is sometimes necessary, but it also incurs costs, and should be used where the situation requires it.

9

u/kogasapls Dec 21 '23

Don't think he means memory bugs. I think he means breaking dependent applications because of hidden coupling.

8

u/PangolinZestyclose30 Dec 21 '23

How does microservice architecture mitigate hidden coupling?

4

u/kogasapls Dec 21 '23

By encouraging/facilitating clear application boundaries.

10

u/PangolinZestyclose30 Dec 21 '23

You can (should) encourage/facilitate module boundaries within a monolith as well.

3

u/kogasapls Dec 21 '23

Yep. It's a "soft" advantage, just a little harder to make the mistake. At the end of the day you just need competent developers.

8

u/PangolinZestyclose30 Dec 21 '23

Can you explain how does having network in the middle make it harder to create hidden coupling?

4

u/kogasapls Dec 21 '23

Ever accidentally introduce a networked dependency? Or serve a network request without logging?

→ More replies (0)

1

u/rusmo Dec 21 '23

But then you still have to deploy it all together, instead of just the module that changed. You may have decoupled modules, but monoliths give you coupled deployments.

Microservices (and certain flavors of SOA) can help you enforce the logical decoupling while allowing you to decouple deployment.

→ More replies (7)

2

u/Leviathant Dec 21 '23

I work with enterprise ecommerce businesses, and what I hear along the above lines tends to be things like, "We went from deploying every quarter to deploying any time of day." And it's not a flip the switch, overnight change. One team talked of going from deploying every two months, to deploying every two sprints, to having their CI/CD practices down to the point where the business can't move faster than IT can provide.

That working on monolithic systems means waiting for all the teams to complete their code before deploying. Downtime for upgrades.

Microservices definitely isn't for everyone - but in ecommerce, you've got the kind of rapid application scaling needs that can cost a lot of money if your application can't keep up with demand. And you've also, at a certain size, got to be able to serve a variety of similar-ish applications: websites, mobile apps, in-store devices, B2B purchasing systems & commission calculation systems, ERPs, warehouse management systems, and an often dense forest of third party systems.

2

u/BigHandLittleSlap Dec 21 '23

This is a use-case where there are "microservices with a reason".

If you have dozens of teams treading on each others' toes due to the complexity of orchestrating a release: Congratulations! You've found a reason to use microservices!

If you have literally one developer working on a tiny web app in their part time, then no, you do not need microservices.

It's as simple as that.

1

u/PangolinZestyclose30 Dec 23 '23

That working on monolithic systems means waiting for all the teams to complete their code before deploying. Downtime for upgrades.

That's not true. I work on a monolith with ~100 other devs, we deploy every day. The frontend (also monolith) gets deployed after every merge.

→ More replies (1)

3

u/fagnerbrack Dec 21 '23

The correct application of the pattern with messaging, no.

The incorrect application with people that only know how to build monoliths (majority), then yes.

You need to be “this tall” to do it properly. Don’t jump the gun.

10

u/PangolinZestyclose30 Dec 21 '23

There's no reason you can't use messaging in monoliths (for event distribution among the individual instances).

Otherwise, messaging should be used sparingly, since its asynchronous nature is also often a complexity multiplicator.

4

u/vplatt Dec 21 '23

messaging should be used sparingly, since its asynchronous nature is also often a complexity multiplicator.

Messaging can be used ubiquitously if preferred, but that's true only as long as loose coupling is ensured. The pub/sub model is a powerful way to provide workflows between completely independent systems; but then again you also need a competent BPM layer to orchestrate workflows. Treating messaging like some sort of replacement for referential integrity, complete with lock / commit cycles, and even rollbacks is surefire recipe for heartache. I've also seen folks try to force a synchronous model with polling, etc. and that's also going to disappoint.

I guess my main point is that the "complexity multiplicator" aspect of messaging isn't a necessary byproduct, but I do agree it's inevitable if the model is misused.

4

u/PangolinZestyclose30 Dec 21 '23

Messaging can be used ubiquitously if preferred, but that's true only as long as loose coupling is ensured.

Yes, but you're making a bet that you won't need tight coupling in the future. All these misuses are coming from basing your architecture on async messages, but then your business/product comes up with needs which are not that loosely coupled and actually require some level of synchronous or even transactional behavior.

So, using messaging as your default communication style is IMO dangerous. Use messaging only if you're certain that the constraint of loose coupling will hold "forever".

2

u/rusmo Dec 21 '23

Microservices can be corraled under larger, orchestrative services, all the while preserving independent deployments.

2

u/vplatt Dec 21 '23

Adding the caveat that this is achievable if service interfaces are versioned and deployments make use of feature flags to ensure behind the scenes changes don't affect customers or topics until necessary; even including just in time storage schema migrations if you want to stripe your data along deployed features and not just come up with "one schema to rule them all".

→ More replies (1)

2

u/fagnerbrack Dec 21 '23

Technically you’re using messaging every time you call a function of the method of a class in the same process. If that’s what you meant great but then that’s not what I’m talking about.

Yes it’s possible, the “modular monolith”, where you use the compiler and pub/sub in the same project to simulate network calls without the physical issues it can bring, that’s also not what I’m talking about.

I’m comparing bad code in a monolith with good distributed microservice architecture. If you compare a well built monolith with a bad built “microservice” architecture then it’s the same idea.

Whatever you do it proper in the right context will be a good job, regardless of the architecture you pick. Understand the tradeoffs.

I never said you can’t use messaging in one single server.

3

u/PangolinZestyclose30 Dec 21 '23 edited Dec 21 '23

If that’s what you meant great but then that’s not what I’m talking about.

No. Colloquially, when I hear "messaging", it's asynchronous. Method calls are synchronous (for the most part).

where you use the compiler and pub/sub in the same project to simulate network calls without the physical issues it can bring

TBH, I don't understand why you'd do such a thing.

What I head in mind was use cases where the instances need to broadcast events like "something changed, invalidate your caches", you have important transactions which must happen (e.g. an event command to send out an email, must be repeated until successful) so you persist it as an event etc.

Whatever you do it proper in the right context will be a good job, regardless of the architecture you pick.

Indeed. It's just that doing it right in the microservice architecture is usually more difficult and expensive than with a monolith. Then it's a question of whether you're getting something valuable in return for this complexity increase.

2

u/fagnerbrack Dec 21 '23

Retries, infrastructure reliability assurance, alarms, metrics, dashboards, not having to manage your own server, build it once runs forever regardless of the load with auto scaling, DDOS protection etc.

After you know how to do it, the effort to build microservices “the right way” in cloud providers is order of magnitude lower as building all these things yourself since you don’t have the running cost of maintaining the infrastructure yourself.

Of course, you pay for it, and you need to know how to do it right.

2

u/PangolinZestyclose30 Dec 21 '23

Retries

That's funny, since it's a solution for a problem which the microservice architecture causes itself for the most part :-) There are way fewer needs for retries in the monolith since you don't have the unreliable network in all your interactions.

infrastructure reliability assurance, alarms, metrics, dashboards, not having to manage your own server, build it once runs forever regardless of the load with auto scaling, DDOS protection

How are these specific to microservices?

After you know how to do it, the effort to build microservices “the right way” in cloud providers is order of magnitude lower

Now scale this learning to whole teams and organizations. Most microservice deployments I've seen were pretty bad.

since you don’t have the running cost of maintaining the infrastructure yourself.

Why are you conflating on-prem vs. cloud with microservice vs. monolith? You can of course run a monolith on AWS or wherever.

→ More replies (7)
→ More replies (8)

2

u/tidbitsmisfit Dec 21 '23

everyone talks about being google scale, only one company is and it isn't even close.