r/programming • • 17d ago

Microservices can work for low-latency workloads

https://madflojo.medium.com/microservices-can-work-for-low-latency-workloads-if-you-design-for-it-ebb19e97bee1?source=friends_link&sk=c2350b171accdb7d8f575da8a017c5a2
81 Upvotes

33 comments sorted by

26

u/Historical_Public751 16d ago

"I don't know what low latency means but I'll say that microservices fit there".

Suuure buddy.

25

u/ArtisticFox8 17d ago

The interesting part would be how to implmenent it. How can I control which underlying connections will be used? I don't think most high level languages allow that. So they wrote some custom networking stack?

19

u/da_supreme_patriarch 17d ago

You don't really need to go that deep. As long as you use a connection pool and your connection pool implementation supports Http2 options, you can configure max streams per connection alongside the min/max pool sizes and idle timeouts, you should be fine as long as you chose sensible values for those

6

u/garnet420 17d ago

For example, if using grpc, you can use streaming calls rather than one time. I've had success using that for latency sensitive sensor data in a robotics application.

2

u/bwainfweeze 16d ago

Consul has a flavor of Get-If-Modified that allows you to wait for a predetermined amount of time for the response to change. You can use that on single values or on entire trees of values. Not streaming per se but there are lots of workloads where writes are infrequent and reads are legion.

One of the ways to hide or amortize latency is to split Source of Truth from System of Record. A library or service call sits between the source and destination and can fiddle with the coarseness of requests. And not just networking latency, also workflow latency. I can make breaking changes to the system of record and maintain an impedance mismatch in an API (library or intermediary), and my users can catch up in an hour or a month.

5

u/GasolinePizza 17d ago

I can't speak for all of course, but I'm fairly certain that at least C# supports configuring this pretty easily.

And a lot of (if not most?) C# SDKs allow injecting a HttpClient or message handler into their clients to allow you to configure the "low level" (relatively) stuff, so I imagine you could do it like that for a lot of the cases where you're not doing the http calls yourself.

Granted, I also haven't had to develop any micro services with true low latency requirements, so I don't know if this works out in practice or if there are other pitfalls with this approach.

113

u/shoot_your_eye_out 17d ago

Or I can just do the simple thing and write a monolithic architecture that lacks the complexity and drawbacks of microservices entirely. And I can change it later if I need to.

Microservices are not a great idea for most applications. You ain’t gonna need it.

33

u/iamapizza 17d ago

If anything this article has convinced me to do the opposite of their conclusion : discount microservices due to the complexity involved in having to do it "right". 

5

u/bwainfweeze 16d ago

I know how to do many, many things and I only talk about some of them once it has been proven that we do in fact have to do the wrong thing because we have a contract in place which demands it. Or because it’ll take two years to unroll what the idiot who left (or we wish had left) did and we have to make the best of the situation while we work the problem.

Much of our effort is about making things less wrong because we can’t make it right for reasons.

13

u/bwainfweeze 16d ago

The author’s advice in keeping calls local removes one of the main advantages of separate deployment versus monolithic, which is the ability to tune resources per problem domain independently.

At the end of the day, you will have certain services that can pile money up and set it on fire. We limit the damage by traffic shaping, insisting that call be slower than other calls. In a monolith the Tragedy of the Commons means noisier neighbors. But you lose any sort of fine tuning you can do when you favor locality. Tuning still exists but it’s not fine, it’s much blockier.

7

u/shoot_your_eye_out 16d ago

All I know is: I prefer to start with a well organized modular monolith. I try to keep the boundaries between "modules" well defined, and if/when I need to break a module out into a separate service, it isn't a crazy lift. The tooling to achieve this sort of thing is actually really good in 2026 too.

I just think it's a massive mistake to start with a complex architecture like microservices for the vast majority of projects. And the reality that I've seen is: most engineering teams lack the coordination and discipline even to do a microservices-based architecture.

edit: also, I should add there are pragmatic arguments that often push me towards "separate service." Example: I'm not going to process video on a web server; that's insane. So I'm very open to "more than one service," but I prefer those arguments to be made with solid evidence and an argument that appeals to pragmatism.

Starting with microservices is often a disaster because it's an ideological division of labor, often in a poorly understood domain.

4

u/bwainfweeze 16d ago

I think it is much more likely, as a monolith is reaching maturity, for the team to be able to pick reasonable boundaries and start carving the application up at that point. The rest of the project is moderately predictable and this the boundaries will have fewer nasty surprises.

If the project somehow manages to survive 10 years, you begin running into a different maintenance problem: finding experts. At which point sharding the code affords you the ability to stretch a smaller number of experts on the old system by reducing its size and replacing subsystems with the New Hotness.

But on a new project it’s immediate balkanization, and teams refusing to change their APIs for petty reasons. It’s generally taken as self-evident that the people “closest to the problem” know more than the armchair critics, but the customer is usually the problem, and the person calling your code is closer to the customer. In a monolith it’s easier to filibuster to get a change through, because there’s nobody to refuse to deploy your changes.

1

u/edgmnt_net 16d ago

I would argue even modularity is a bad idea, at least the one that involves overly hard module boundaries. There are tremendous benefits in writing things in a truly monolithic way like the Linux kernel does, using relatively soft and malleable boundaries that allow easy refactoring.

Also people write absolutely awful code and blame it on monoliths.

2

u/shoot_your_eye_out 16d ago edited 16d ago

I think we might be having a semantic quibble; in my mind, "modular" can still mean "relatively soft and malleable boundaries that allow easy refactoring." If you're talking very explicit modularization (like, defined interface/heavy sandboxing/etc.) sure: I agree.

edit: also, 100% people write god-awful code and then decide it's "because it was a monolith." That drives me insane too.

1

u/edgmnt_net 16d ago

Yeah, completely agreed. I mention it because I usually see people bring up so called "moduliths" or "modular monoliths" and never even consider good old monoliths and good old modularity and abstraction. Meaning they intend to write monoliths much like microservices minus serialization, often even claiming it makes it easy to extract a microservice later on (nevermind that in an actual distributed system any call can fail much more readily, you no longer have low-latency helper calls and so on).

1

u/TheChildOfSkyrim 17d ago

I feel like the proposed solution looks a lot like monolith in disguise, with a replica in each AZ.

16

u/SkinBoogerHybrid 16d ago

This isn't what I would call a microservices architecture, this is a distributed monolith. As the article points out it has replaced function calls with network calls but is otherwise the same.

When you have the Client calling Service A, which calls Service B, which calls Service C, you are missing one of the fundamental benefits of microservices: independent operation. If Service C goes down, Service B which depends on it goes down, and in turn Service A, which depends on Service B, goes down - you are no better off than if you had a monolith but everything is much slower.

The way to make microservices work is to make them self contained. Don't have any synchronous downstream calls to other services. Have each service keep a copy of all the data it needs to do its job, in its own database which it owns, and use a separate mechanism to keep data up to date across the whole system.

That way your service can scale and operate independently, even if the whole of the rest of the system is down.

1

u/DynamicHunter 15d ago

How is that not better than monolith, outside of your one case? If service A goes down, service B and C can still run though, and instead of your whole site/app being down just that one functionality fails.

Maybe I’m missing something. Also with micro services instead of whole site being down, that service A can restart in a new pod and become operational silently as soon as the client calls again.

Imagine YouTube but the search and home page suggestions don’t load, but you can still view your history, playlists, and channel subscription list.

1

u/robert_7524 8d ago

How stale can those service-owned copies be? Async propagation buys independence only if stale reads and reconciliation fit the data.

-1

u/kiteboarderni 15d ago

Such a bad way of looking at this. Those independent services can be striped / have different performance profiles / run different versions. Very basic way of thinking from you.

8

u/garnet420 17d ago

Ok, maybe you can lower latency to be competitive with a more monolithic architecture, but what's the actual benefit? And don't say "robustness" or "modularity"

10

u/f3xjc 17d ago

Modular monolith absolutely are a thing so modularity is not even an advantage of micro services.

But one real advantage is to allow the different team to deploy independently. Architecture cost that is paid to reduce organizational friction.

1

u/bwainfweeze 16d ago

That is often robbing Peter to pay Paul, because we ignore the burgeoning deployment time because it’s smeared out across everybody, and each team has to have expertise in the deployment vagaries instead of a monolith having to sustain a single team or just a bus number of three to reach the same level of support.

You’re also putting a noose around the neck of your cross domain people because they now have to monitor the lifetimes of four separate services instead of a single one to make sure their changes roll out together properly - and are not subsequently rolled back - before enabling feature toggles. It’s hard enough to get people to watch one telemetry dashboard, I don’t even know how to begin to advise someone to watch four at once. I can manage three myself but the third one gets forgotten daily.

1

u/f3xjc 16d ago

Hey at least I recognize services count as a liability instead of a more = better target. Deploy is a signal of thing and infrastructure as code or a shared template most use are good.

And if there's truly cross services coupling then yes placing the boundary elsewhere maybe around that cluster is probably good.

1

u/bwainfweeze 16d ago

Business people and customers are always eyeballing the proverbial peanut butter and chocolate and thinking about how great it would be to combine them.

Features will always be requested that blur the lines of whatever separation you set out to achieve. Some will just be stubbornness, but some will be lucrative.

Whatever your boundaries are now, they will by necessity change as the team and feature count rise. Ian Cooper has by far the most coherent explanation of how this happens. But as a rule of thumb your module counts and sizes will end up wanting to be proportional to the square root of the whole project size. And that will frequently necessitate dividing two APIs into three and shunting the code that doesn’t “fit” off into the third. Or once in a while, converting three into two to facilitate a shared concern between them.

https://youtube.com/watch?v=j2AQ9eTZ3-0

1

u/edgmnt_net 16d ago

Independent deployment is not a given. It's actually really easy to end up with a huge mess of microservices that need to be redeployed together to a large degree (and that typically takes longer than a monolith). And there's often no good way to fix it in typical business applications, especially cohesive ones, even though particular usecases may lend themselves to such an architecture (common platform + multiple completely separate apps, for example).

18

u/da_supreme_patriarch 17d ago

But that's the entire point of microservices. You don't ever build a distributed system if there is no reason to distribute your workloads. The industry certainly has this problem of using specific architectures when they don't have the problems that those architectures are supposed to be solving, that doesn't mean those problems don't exist in general

1

u/bwainfweeze 16d ago

To my eternal confusion, it seems that the pedagogy hasn’t even remotely caught up with the realities of modern software development and most curricula don’t have a distributed computing track as an elective, let alone as a requirement. We aren’t even teaching kids enough to be afraid of distributed computing, and so they are out here trying to pet lions.

At the end of the day, the premium we pay to Amazon or Google for hardware is mostly spent on maintaining the illusion that the Eight Fallacies don’t exist. And I think if you ignore that and build your own guards on top of their services, you’re paying nearly double what you should to the vendor.

See also Netflix doing their own job queue over the top of AWS and achieving close to 2x the throughput per instance.

1

u/garnet420 17d ago

Distributing your workloads can be an end in and of itself, and may be the best reason to use microservices.

They do not add robustness except in very limited circumstances and are orthogonal to modularity except maybe in a security/data access context.

6

u/da_supreme_patriarch 17d ago

You are thinking about logical boundaries, microservices provide physical boundaries. You would need good logical boundaries(modularity as you described) to have good physical boundaries(otherwise you end up with the so-called distributed monolith), but physical separation - the ability to pacakge certain modules together and deploy those separately, gives you scalability if you have certain background jobs that would benefit from additional parallelism and you'd like to scale that on demand without duplicating your entire app. You also benefit from physical separation if you'd like to put certain things somewhere closer to your users, ind different availability zones, while keeping your admin service etc. just in one zone. If you don't have these type of concerns, then you are correct, there is absolutely no need for microservices

2

u/bwainfweeze 16d ago edited 16d ago

Caveat: Low-latency is subjective; designing a system for single-digit milliseconds vs. double- or triple-digit milliseconds will differ, since every additional digit changes your tolerance.

Every problem is simple if you underestimate it. This article is a preface to an actual useful article, and I can’t tell from this vague-to-the-point-of-harm article whether the author has the aptitude for it or is a lost cause.

The author talks obliquely about fanout but misses the problem of call depth that real microservices invite. Making a call that makes calls that make calls that eventually hit a database, latency is not the only problem, because you’ve now turned bandwidth into additional latency. Marshaling the questions and unmarshaling the responses takes time, but also we generally don’t begin unmarshaling until the last byte of the payload has been received, and that’s a matter of bandwidth. The translation time then adds CPU throughput to the latency. And that is why protobufs exist, and BSON before them, to try to reduce that overhead enough that you can sustain a wider and taller mess. They don’t fix the problem, they just make the shitshow smaller.

The AZ observation is important, but they have replaced magical thinking with different magical thinking. The two reasons we divide services are impedance mismatches for deployments, and scaling services independently. The moment you do single zone routing, you have to round the number of copies of Service A that are running to a multiple of three. If four copies of the service aren’t quite keeping up with demand, you have to spool up a fifth, which is a 25% increase in hardware costs for that service. That decision is made independently in each AZ. But across the entire region, ten copies might be almost sufficient to the load and spinning up an eleventh might ease the oversubscription enough to prevent alarms. Which is a 10% increase.

And this is already a lot here without getting into the stranded resources That EC2 so often represents because the number of CPUs to memory is quite fixed and so the more segregated the services the more twisted they become to try to either avoid using or heavily use memory in order to make the math work. Kubernetes or Terraform can only do so much and especially when you refuse to cross AZs with traffic.

This all gets much more complex when you have a mix of workloads that vary in complexity by an order of magnitude, because now Queuing Theory runs into more corner cases, which is again more latency.

Also they are ignoring Split Brain issues. Cross AZ doesn’t fix them, but at least doesn’t ignore them.

1

u/WindHawkeye 16d ago

Ah here's the hoard of people writing applications that serve 10 customers to argue against microservices.

1

u/daidoji70 5d ago

Yeah but why though?