Microservices in Production: 5 Challenges You Should Know
Microservices present many challenges, these can be offset by proper isolation, monitoring, logging, version management and dependency management between services.
Join the DZone community and get the full member experience.Join For Free
the dark side of microservices
it seems like everyone is into microservices these days, while monolith architectures are just as popular as crumbling down old and abandoned castles.
the public attention certain trends get is often exaggerated and doesn't reflect what's going on in practice, but this time, it feels more like a consensus. microservices iterate over the basic separation of concerns principle and put a name on insights from teams of engineers who crafted solutions to real problems they needed to solve.
in this post, we'll play the devil's advocate, share some insights from the community and our users, examine the top issues with microservices in production — and how you can solve them.
the flip side of microservices
separation of concerns is not a new concept, and neither is distributed computing. the benefits are huge, but they come at a price , which usually translates to higher ops costs both in time and money. mix the two, and you get a petri dish of all sorts of awkward problems. put it in production, and the problems quadruple. debugging to the rescue, but oh wait… debugging is not about making problems go away.
as bryan cantrill points out on his talk in qcon , "debugging devolved into an oral tradition, folk tales of problems that were made to go away." when in fact, it is more like a science, understanding how the system really works and not how we think it works.
debugging is not just minor side task, it's a fundamental issue. sir maurice wilkes, debugger of one of the first programs ever created, already realized the major role debugging is going to play for developers:
"in 1949, as soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. debugging had to be discovered. i can remember the exact instant when i realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."
we were trained into thinking that it's just about making problems go away. but the real challenge is about understanding how the system really works.
problem #1: as if monitoring a monolith wasn't hard enough
whether you're gradually breaking down a monolithic app to microservices or building a new system from scratch, you now have more services to monitor. each of these is highly likely to:
use different technologies/languages.
live on a different machine/container.
have its own version control.
the point is that as far as monitoring goes, the system becomes highly fragmented, and a stronger need arises for centralized monitoring and logging to have a fair shot at understanding what's going on.
for example, one of the scenarios described in a recent continuous discussions podcast was a bad version that needs to be rolled back. mostly a straightforward procedure for monoliths. but… we have microservices now. so we need to identify which of the services needs to be rolled back, what would be the impact of the rollback on the other services, or maybe we just need to add some capacity, but then it could just push the problem to the next service in line.
takeaway #1: if you thought monitoring a monolith architecture was hard, it's 10 times harder with microservices and requires a bigger investment in planning ahead.
problem #2: logging is distributed between services
logs, logs, logs. gbs of unstructured text is generated by servers on a daily basis. the it equivalent of carbon emission in the shape of overflowed hard drives and crazy splunk bills/elk storage costs.
with a monolith architecture, your logs are probably already scattered in different places — because even with a monolith mindset, you probably had to use a few different layers that probably log to different places. with microservices, your logs break further down. now, when investigating a scenario related to some user transaction, you'll have to pull out all the different logs from all the services that it could have gone through to understand what's wrong.
in takipi, our team solves this by using takipi … on takipi. for all log errors and warnings coming from production jvms, we inject a smart link into the log, which leads to the event's analysis. that includes its full stack trace and variable state at every frame, even if it's distributed among a number of services/machines.
takeaway #2: microservices are all about breaking things down to individual components. as a side effect, ops procedures and monitoring are also breaking down per service and lose their power for the system as a whole. the challenge here is to centralize these back using proper tooling.
problem #3: one service's issue can cause problems elsewhere
if you follow up on some broken transaction in a specific service, you don't have the guarantee that the same service you're looking at is to blame. let's assume you have some message passing mechanism between your services, like rabbitmq, activemq, or maybe you're using akka.
there could be several possible scenarios going on, even if the service behaves as expected and there's no problem to be found:
the input it received is bad, and you need to understand what made the previous service misbehave.
the recipient of its result returned some unexpected response, and you need to understand how the next service behaves.
what about the highly likely scenario where these dependencies are more complex than 1:1? or there's more than one service that benefits to the problem?
whatever the problem is, the first step with microservices is to understand where to start looking for answers. the data is scattered all over the place and might not even live within your logs and dashboard metrics at all.
takeaway #3: with monoliths, you usually know that you're looking at the right direction. microservices make it harder to understand the source of the issue and where you should get your data from.
problem #4: finding the root cause of problems
alright, let's carry on with the investigation. the starting point now is that we've nailed down the problematic services, pulled out all the data there is to pull — stack traces and some variable values from the logs. if you have an apm (like new relic, appdynamics, or dynatrace, which we also wrote about here and here ) you might also get some data about unusually high processing times for some of the methods/do some basic assessment of the severity of the issue.
but… what about… the actual issue? the real root cause? the code that's actually broken.
in most cases, the first few bits of variable data you hopefully get from the log won't be the ones that move the needle. they usually lead to the next clue, which requires you to uncover some more of the magic under the hood and add another beloved log statement or two. deploy the change, hope for the issue to reoccur, or not, because… sometimes merely adding a logging statement seems to solve issues. some sort of a diabolical reverse murphy's law. oh, well.
takeaway #4: when the root cause of an error in a microservice spans across multiple services, it's critical to have a centralized root cause detection tool in place.
takipi's error analysis dashboard – variable values overlaid on the actual code at every frame in the stack
problem #5: version management and cyclic dependencies between services
another issue that was mentioned in the continuous discussions podcast that we'd like to highlight here is going from a layer model in a typical monolithic architecture to a graph model with microservices.
two problems that can happen here relate to keeping your dependencies in check.
1. if you have a cycle of dependencies between your services, you're vulnerable to distributed stack overflow errors when a certain transaction might be stuck in a loop.
2. if two services share a dependency, and you update that other service's api in a way that could affect them, then you'll need to update all three at once. this brings up questions like, which should you update first? and how to make this a safe transition?
more services mean different release cycles for each of them, which adds to this complexity. reproducing a problem will prove to be very difficult when it's gone in one version and comes back in a newer one.
takeaway #5: in a microservice architecture, you're even more vulnerable to errors coming in from dependency issues.
debugging immediately gets you in the mindset of making problems go away — this is literally the direct meaning of the word debugging. when you think of it with the system's context in mind, there's much more to it than ad hoc problem solving. it's about understanding the system as a whole, what makes it tick, and how things really are versus how you hope they'd be.
at the bottom line, it's all about the tools you use and the workflows you employ.
Published at DZone with permission of Alex Zhitnitsky, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Micro Frontends on Monorepo With Remote State Management
How Agile Works at Tesla [Video]
Which Is Better for IoT: Azure RTOS or FreeRTOS?
Best Practices for Securing Infrastructure as Code (Iac) In the DevOps SDLC