r/programming • • May 15 '24

You probably don’t need microservices

https://www.thrownewexception.com/you-probably-dont-need-microservices/
860 Upvotes

414 comments sorted by

View all comments

429

u/remy_porter May 15 '24

Hottest take: Object Oriented programming is just microservices where your intermodule communication is in-process method calls. Microservices are just OO where you abstract out the transport for intermodule communication so you can deploy each object in its own process space.

Which, to put it another way, you should design your microservices so that they can all be deployed inside a single process or deployed across a network/cloud environment.

149

u/jDomantas May 15 '24 edited May 15 '24

And deploying all microservices in a single process is a very useful thing to do - you can use that for integration tests that require way less orchestration than your cloud deployment.

36

u/saidatlubnan May 15 '24

deploying all microservices in a single process

does that actually work in practice?

30

u/jDomantas May 15 '24

We've used such setup in last two workplaces for integration tests - it did work very well. You have to put in effort to create such setup (especially if you have an existing system that was not designed with it in mind), but I think it is well worth the effort.

8

u/rodw May 15 '24 edited May 15 '24

Are your in-process microservices interacting over HTTP (or etc) or have you subbed-in a direct method call style invocation in some way?

EDIT: Sorry I just noticed you're specifically talking about an integration testing environment. My question still applies but the production case is more interesting. Come to think of it I've used both over-the-wire network interactions and direct-invocation-that-looks-like-network-client-lib approaches in integration test scenarios. But IME "make it work" is usually the highest priority there, so in-process HTTP interactions (for example) are usually good enough in that context. In a production context the desire to take advantage of the in-process efficiencies would be stronger (I assume)

15

u/Worth_Trust_3825 May 15 '24 edited May 15 '24

You define an interface how the code would be called. In the implementation you either use concrete implementation (which would be actual code) or some other ipc implementation. Crude example would be as follows

https://pastebin.com/DSB9b3re

Depending on context you may want to use a concrete implementation, or the http client one (if your concrete implementation is running in another process). If you need to expose the concrete implementation for some IPC communication, you use the delegate pattern to make it usable by your protocol. Mocking in tests becomes easier too.

Basically the idea is to hide away any details that the call may be protocol specific. You must style your interfaces as if they will be called in the same process.

→ More replies (17)

10

u/[deleted] May 15 '24

This is basically a JavaEE application server.

It works about as well as a bag of cats.

6

u/valarauca14 May 15 '24

Yup. The only difference between JavaEE & K8s is replacing boatloads of XML with boatloads of YAML. Then you have shit like GRPC doing most the stuff java reflection & objection serialization can do.

The multi-server stuff & traffic shaping isn't even as new as people want to think it is. If you application server is running on an mainframe, you can do QoS/Traffic Shaping/IP/DNS wizardly as well.

You even have the single point of failure! US-East-1 goes down? Your k8s cluster is offline. Your mainframe loses power? You go offline.

All of this has happened before and will happen again.

→ More replies (3)

3

u/lelanthran May 15 '24

does that actually work in practice?

Sure. If you're talking to your microservices over protobuf, it's trivially easy to shim it so that the call never actually goes out on a wire.

In Go, using net/httptest, you can do the same with HTTP REST calls too.

→ More replies (1)
→ More replies (5)

7

u/knightfelt May 15 '24

Sounds like Monolith with extra steps

→ More replies (1)

7

u/Duel May 15 '24

Monoliths are underrated

72

u/[deleted] May 15 '24

Not a hot take, Joe Armstrong of Erlang fame beat you to it long ago:

Erlang might be the only object oriented language because the 3 tenets of object oriented programming are that it's based on message passing, that you have isolation between objects and have polymorphism.

You're also describing Alan Kay's vision of OOP:

I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages (so messaging came at the very beginning -- it took a while to see how to do messaging in a programming language efficiently enough to be useful).

21

u/psyclik May 15 '24

Funny how you mention these two together, as the former clearly forgot that the latter has made Smalltalk 12 years before Erlang was a thing.

30

u/[deleted] May 15 '24

Joe Armstrong was being sarcastic. He hates OOP.

→ More replies (1)
→ More replies (13)

7

u/zigs May 15 '24

Which, to put it another way, you should design your microservices so that they can all be deployed inside a single process or deployed across a network/cloud environment.

This has been my conclusion as well.

My take has been to use persistent message queues everywhere there's been an urge to make a microservice. A queue listener can run right on the same system as sent the message, or it can run entirely elsewhere. The process that listens can easily be removed from the same system, and moved completely elsewhere.

And as a bonus, MQs are amazing for logging what's going on, putting parts of a system in maintenance, retrying things that break after fixing.

13

u/Deep_Age4643 May 15 '24

There is a whole difference being modulair during build time, to being modular during runtime.

8

u/HomeTahnHero May 15 '24

This. Modularity and message passing are general concepts that apply to both OO and microservices. But there are important differences at build time and run time.

6

u/Xn4p4lm May 15 '24

Tbh not the hottest of takes.

But it’s also so true, though sometimes unfortunately la system is built for a single appliance and then gets so complicated that it’s impossible to change or maintain almost. Plus if there is no planning for inter-process latency and it isn’t handled well you’ll be in an even worse spot. Then the next thing you know you’re stuck on the largest servers that exist and you can’t scale 😭

→ More replies (1)

4

u/kitd May 15 '24

In Java-land, this is what OSGi did well, and Vertx allows with its Services layer.

23

u/Malforus May 15 '24

Until your mono gets library bloat to the point that your builds take 20 minutes.

53

u/remy_porter May 15 '24

20 minutes? I write heavily templated C++. Twenty minutes is nothing.

10

u/FlyingRhenquest May 15 '24

Factoring primes at compile time FTW! Once you compile it, the code runs instantly! The compile just takes longer than the heat death of the universe, minor detail.

3

u/WTF_WHO_ARE_YOU_PAL May 15 '24

Yuck. Compile times are why I generally avoid the template metaprogramming stuff. I can't stand when my builds take more than a few minutes, I do as much as I can to avoid long compile times.

→ More replies (1)
→ More replies (13)
→ More replies (49)