As you adopt a microservice architecture, you’ll experience challenges along the way. We’ve looked at some of these problems in passing already, but I want to explore them further to help give you some forewarning.

What I’m hoping to do with this chapter is give you just enough information about the sorts of issues you may face. I can’t solve them all in this book, and many of the problems I outline here already have a more detailed treatment in Building Microservices , which was very much written with these challenges in mind.

I also want to give you some signs to look for to help you spot when these issues may need addressing, as well as an indication of where along your journey these issues are most likely to arise.

More Services, More Pain

When exactly problems will occur with a microservice architecture is related to a multitude of factors. The complexity of service interactions, size of the organization, number of services, technology choices, latency, and uptime requirements are just a subset of the forces that can bring forth pain, suffering, excitement, and stress. This means it’s difficult to say when, or indeed if, you’ll actually encounter these issues.

In general, though, I’ve realized that the sorts of problems that arise in a company with ten services tend to be quite different from the ones seen at a company with hundreds of services. The number of services seems to be as good a measure as any for indicating when certain issues are most likely to manifest themselves. I should note here that when I talk about the number of services, unless otherwise specified I’m taking about different logical services. When those services are deployed into production, they may then be deployed as multiple service instances.

Don’t think of adopting microservices as flipping a switch; think about it as turning a dial. As you turn that dial, and have more services, you’ll hopefully have more opportunity to get the good stuff out of microservices. But as you turn up that dial, you’ll hit different pain points as you go. As you do, you’ll need to find ways to resolve these problems that might require new ways of thinking, new skills, different techniques, or perhaps new technology.

Figure 5-1 roughly maps the pain points we’ll cover in the rest of this chapter based on where in your service growth these issues are most likely to arise. This is deeply unscientific, and based heavily on anecdotal experience, but I still think it’s useful as an overview.

Showing at a high level where some of the different pain points often manifest themselves

Figure 5-1. Showing at a high level where some of the pain points often manifest

I’m not saying that you’ll definitely see all of these problems at these times, or at all. There are certain variables involved that a simple diagram like this can’t really articulate. One factor in particular that may change when these issues will strike is how coupled your architecture ends up being. With a more coupled architecture, issues around robustness, testing, tracing, and the like may manifest themselves earlier. All I’m hoping to do is shine a light on the potential pitfalls that might be out there.

However, keep in mind that you should use this as a general indicator. You need to make sure you’re building in feedback mechanisms to look for some of the potential indicators I outline here.

Now that I’ve fully caveated the preceding diagram, let’s take a look at each of these issues in a little more detail. I’m going to give you some pointers about which factors are likely to bring these problems to the fore, an understanding of how these issues may impact you, and some pointers for solving these challenges as they come up.

Ownership at Scale

As you have more and more developers working on your microservice architecture, you’ll get to a place where you may want to reconsider how you handle ownership.

Martin Fowler has previously differentiated different types of ownership from the point of view of generic code ownership, and I find that, broadly speaking, they work within the context of microservice ownership too. Here, primarily we’re looking at ownership from a point of view of making code changes, not ownership in terms of who handles deployments, first-line support, and so on. Before we talk about the sorts of problems that crop up, let’s first take a look at the concepts Martin outlines, and put them in the context of microservice architecture:

Strong code ownership

All services have owners. If someone outside that ownership group wants to make a change, they have to submit that change to the owners, who decide whether it is allowed. The use of a pull request for people outside the ownership group is one example of how this could be handled.

Weak code ownership

Most, if not all, services are owned by someone, but anyone can still directly change their modules without resorting to the need for things like pull requests. Effectively, source control is set up to still allow anyone to change anything, but there is the expectation that if you change someone else’s service, you’ll speak to them first.

Collective code ownership

No one owns anything, and anyone can change anything they want.

How Can This Problem Show Itself?

As you grow your number of services and number of developers, you may start to experience problems with collective ownership. For collective ownership to work, the collective needs to be well-connected enough to have a common shared understanding of what a good change looks like, and in which direction you want to take a specific service from a technical point of view.

Left alone, at scale I’ve seen collective code ownership be disastrous for a microservice architecture. One fintech company I spoke to shared stories of a small team experiencing rapid growth, moving from 30–40 developers to over 100, but without any assigned responsibilities for different parts of the system or any concept of ownership other than “people know what is right.”

What emerged was no clear vision for the system architecture as it evolved, and a horribly tangled “distributed monolith.” One of the developers there referred to their architecture as “colander architecture” because it was so full of holes—people would just “punch a new hole” whenever they felt like it by exposing data or just making lots of point-to-point calls. 1 The reality is these sorts of challenges are easier to fix with a monolithic system, but far harder with a distributed system—the cost of detangling a distributed monolith is much higher.

When Might This Problem Occur?

For many teams starting out small, a collective code ownership model makes sense. With a small number of colocated developers (around 20), I’m happy with this model. As the number of developers increases, or those developers are distributed, it becomes harder to keep everyone on the same page regarding things like what makes for a good commit or how individual services should evolve.

For teams experiencing fast growth, a collective ownership model is problematic. The issue is that for collective ownership to work, you need time and space for the consensus to emerge, and be updated as new things are learned. This becomes harder with more people in general, and really hard if you’re hiring new people at a rapid pace (or transferring them to the project).

Potential Solutions

In my experience, strong code ownership is almost universally the model adopted by organizations implementing large-scale microservice architectures consisting of multiple teams and over 100 developers. It becomes easier for the rules of what constitutes a good change to be decided by each team; you can view each team as adopting collective code ownership locally. This model also allows for product-oriented teams; if your team owns some services, and those services are oriented around the business domain, then your team becomes more focused on one area of the business domain. This makes it easier to maintain customer-focused teams who build domain expertise, often with embedded product owners guiding their work.

Breaking Changes

A microservice exists as part of a wider system. It either consumes functionality provided by other microservices, exposes its own functionality to other microservice consumers, or possibly does both. With a microservice architecture, we are striving for independent deployability, but for that to happen, we need to make sure that when we make a change to a microservice we don’t break our consumers.

We can think of the functionality we expose to other microservices in terms of a contract . It’s not just about saying, “This is the data I’ll return.” It’s also about defining the expected behavior of your service. Whether or not you’ve made this contract with your consumers explicit, it exists. When you make a change to your service, you need to make sure you don’t break this contract; otherwise, nasty production issues can occur.

Sooner or later, you’ll need to deal with the challenges that breaking changes cause—either because you’ve made a conscious decision to make a backward-incompatible change, or perhaps because you made an innocent change that you thought would impact just your local service, only to find it broke other services in ways you didn’t imagine.

How Can This Problem Show Itself?

The worst occurrence of this issue is when you see production outages caused by new microservices being sent live which break compatibility with existing services. This is a sign that you’re not catching accidental contract breakages early enough. These issues can be catastrophic if you don’t have a fast rollback mechanism in place. The only positive to take out of these failure modes is that they normally manifest quite quickly after a release, unless the backward-incompatible change is made to a part of a service contract that is rarely used.

Another sign is if you start seeing people try to orchestrate simultaneous deployments of multiple services together (sometimes called a lock-step release ). This could also be a sign that this is happening due to trying to manage contract changes between client and server. The occasional lock-step release isn’t too bad within a team, but if it is common, something needs to be investigated.

When Might This Problem Occur?

I find this to be a fairly early growing pain that teams encounter, especially when development is spread across more than one team. Within a single team, people tend to be a bit more aware when they make breaking changes, partly because there is a good chance the developers work on both the service being changed and the consuming service. When you get into situations where one team is changing a service that is then consumed by other teams, this problem can come up more often.

Over time, as teams become more mature, they get more diligent about making changes to avoid breakages in the first place, and also put mechanisms in place to catch problems early.

Potential Solutions

I have a set of rules for managing breaking contracts. They’re pretty simple:

  1. Don’t break contracts.

  2. See rule 1.

OK, I kid, but only slightly. Making breaking changes to the contracts you expose isn’t great and is a pain to manage. You really want to keep it to a minimum if you can. That said, these are more realistic rules:

  1. Eliminate accidental breaking changes.

  2. Think twice before making a breaking change—can you possibly avoid it?

  3. If you need to make a breaking change, give your consumers time to migrate.

Let’s look at these steps in a bit more detail.

Eliminate accidental breaking changes

Having an explicit schema for your microservice can quickly detect structural breakages in your contract. If you expose a calculate method that is used to take two integers as parameters but now takes only a single integer, this is obviously a breaking change, which should be obvious from the new schema. Making this schema explicit to developers can help with early detection of this sort of thing; if they have to go in and make a change to the schema by hand, that becomes an explicit step that will hopefully cause them to pause for a moment and think about a change. If you have a formal schema format, there is the option to handle this programmatically too, of course, although this isn’t done as much as I’d like. protolock is an example of one such tool, which will actually prohibit making incompatible changes to your protocol buffers.

The default choice for many people is to use schema-less interchange formats, with JSON being the most common example. Although theoretically you can define explicit schemas for JSON, these aren’t used in practice. Developers tend to curse the constraints of formal schemas initially—after they’ve had to deal with breaking changes across services, they’ll change their minds. It’s also worth noting that some of the serialization formats that make use of schemas are able to achieve performance improvements in deserializing data because of the formal types—something worth considering.

Structural breakages are only part of it, though. You also have semantic breakages to consider. If our calculate method still takes two integers, but the latest version of our microservice multiplies those two integers whereas it used to just add them, this is also a break in contract. In practice, testing is one of the best ways of detecting this. We’ll look at that shortly.

Whatever you do, the quickest win is to make it as obvious to developers as possible when they make changes to the external contract. This may mean avoiding technology that magically serializes data or generates schemas from code, preferring to hand-roll these things instead. Trust me—making it hard to change a service contract is better than constantly breaking consumers.

Think twice before making a breaking change

If possible, prefer expansion changes to your contract if you can. Add new methods, resources, topics, or whatever that support the new functionality without removing the old. Try to find ways to support the old while still supporting the new. This may mean you end up having to support old code, but that still may be less work than handling a breaking change. Remember, if you decide to break a contract, it’s on you to handle the implications of that.

Give consumers time to migrate

As I’ve been clear about from the beginning, microservices are designed to be independently deployable . When you make a change to a microservice, you need to be able to deploy that microservice into a production environment without having to deploy anything else. For that to work, you need to change your service contract in such a way that existing consumers are not impacted—so it follows that you need to allow consumers to still use the old contract even if your newer contract is available. You’ll then need to give all consumers time to change their services to migrate over to your newer service version.

I’ve seen this done in two ways. The first is to run two versions of your microservice, as outlined in Figure 5-2 : two builds of the Notifications service are available at the same time, each one exposing different incompatible endpoints that consumers can choose between. The primary challenges with this approach are that you have to have more infrastructure to run the extra services, you probably have to maintain data compatibility between the service versions, and bug fixes may need to be made to all running versions, which inevitably requires source code branching. These issues are somewhat mitigated if you are only coexisting the two versions for short periods of time, which is the only situation where I’d consider this approach.

Coexisting two versions of the same microservice to support backward-incompatible changes

Figure 5-2. Coexisting two versions of the same microservice to support backward-incompatible changes

The approach I prefer is to have one running version of your microservice, but have it support both contracts, as we see in Figure 5-3 . This could involve exposing two APIs on different ports, for example. This pushes complexity into your microservices implementation, but avoids the challenges of the earlier approach. I’ve spoken to some teams that are supporting three or more old contracts in the same service years later, due to external consumers being unable to change. That’s not a fun position to be in, but if you do find yourself with consumers who won’t change, I still think this is the best option.

Co-existing two different versions of the same microservice to support backwards incompatible changes

Figure 5-3. One service exposing two contracts

Of course, if the same team handles both consumer and producer, you could do a lock-step release and deploy new versions of both consumer and producer at the same time. It’s not something I’d want to do often, but at least within a single team it can be easier to manage the release coordination—just don’t make a habit of it!

Changes within a team are easier to manage, as you control both sides of the equation. As the microservice you want to change is used more widely, the cost of managing the change becomes greater. As a result, you can be more relaxed about making breaking changes within a team, but breaking an API you expose to third-party organizations is likely to be quite painful.

However you do it, you need good communication with the people who manage the services that consume your service. You’re likely going to inconvenience them (at best), so it’s a good idea to be on good terms with them. Treat consumers of your service like customers—and you should treat your customers well!

Get This Sorted—Fast!

As organizations have increasing numbers of microservices, they eventually work out how to mostly eliminate accidental breaking changes, and come up with a managed mechanism for handling purposeful changes. If they don’t, the impacts become so significant that a microservice architecture is untenable. Put a different way, I highly suspect that small microservice organizations that don’t sort this stuff out won’t last long enough to become large microservice organizations.

Reporting

With a monolithic system, you typically have a monolithic database. This means that stakeholders who want to analyze all of the data together, often involving large join operations across data, have a ready-made schema against which to run their reports. They can just run them directly against the monolithic database, perhaps against a read replica, as shown in Figure 5-4 . With a microservice architecture, we have broken up this monolithic schema. That doesn’t mean that the need for reporting across all of our data has gone away; we’ve just made it much more difficult, as now our data is scattered across multiple logically isolated schemas.

Reporting being carried out directly on the database of a monolith

Figure 5-4. Reporting being carried out directly on the database of a monolith

When Might This Problem Occur?

This one tends to bite fairly early, and normally comes at the stage when you’re starting to consider decomposing a monolithic schema. Hopefully, this is discovered before it becomes an issue, but I’ve seen more than one project where the team doesn’t realize until halfway through that the architecture direction was going to create misery for stakeholders interested in reporting use cases. All too often, the needs for downstream reporting are not considered early enough, as it happens outside the realm of normal software development and system maintenance—out of sight, out of mind.

You may be able to sidestep this problem if your monolith already uses a dedicated data source for reporting purposes, like a data warehouse or data lake. Then all you need to ensure is that your microservices are able to copy the appropriate data to the existing data sources.

Potential Solutions

For many situations, the stakeholders who care about having access to all your data in one place probably also have an investment in a tool chain and processes that expect direct access to the database, normally making use of SQL. It also follows that their reporting is likely tied to the schema design of your monolithic database. This means that unless you want to change how they work, you’re going to still need to present a single database for reporting, and quite possibly one that matches the old schema design to limit the impact of any changes.

The most straightforward approach for solving this problem is to first separate the need for a single database to store data for reporting purposes, from the databases your microservices use to store and retrieve data, as Figure 5-5 shows. This allows the content and design of your reporting database to be decoupled from the design and evolution of each service’s data storage requirements. This also allows for this new reporting database to be changed with the specific requirements of reporting users in mind. All you then need to do is to work out how your microservices can “push” data into your new schema.

A dedicated reporting database with data being pushed to it from different microservices

Figure 5-5. A dedicated reporting database with data being pushed to it from different microservices

We’ve already looked at potential solutions to this problem in Chapter 4 . A change data capture system is an obvious potential solution for solving this, but techniques like views can also be useful, as you may be able to project a single reporting schema from views exposed from the schemas of multiple microservice databases. You may also consider the use of other techniques, like having the data copied to your reporting schema programmatically as part of the code of your microservices, or perhaps having intermediary components that may populate the reporting database by listening to events of upstream services.

I further explore the challenges and potential solutions around this topic in a lot more detail in Chapter 5 of Building Microservices .

Monitoring and Troubleshooting

We replaced our monolith with microservices so that every outage could be more like a murder mystery.

Honest Status Page (@honest_update), http://bit.ly/2mldxqH

With a standard monolithic application, we can have a fairly simplistic approach to monitoring. We have a small number of machines to worry about, and the failure mode of the application is somewhat binary—the application is often either all up or all down. With a microservice architecture, we can have the failure of just one service instance, or just one type of instance to consider—can we pick those up properly?

With a monolithic system, if our CPU is stuck at 100% for a long time, we know that’s a big problem. With a microservice architecture with tens or hundreds of processes, can we say the same thing? Do we need to wake someone up at 3 a.m. when just one process is stuck at 100% CPU?

Working out where you have problems, and understanding whether those problems you are seeing are actually things you need to worry about becomes much more complicated as you have more moving parts. The way you approach monitoring and troubleshooting will need to change as your microservice architecture grows. This is an area that will require constant attention and investment.

When Might These Problems Occur?

It’s a bit trickier to predict exactly when you’ll start having a problem with this. The simple answer can be “the first time something goes wrong in production,” but trying to work out what went wrong where is something developers and testers may have to deal with before you even get to production. You could hit these limitations when you have a couple of services, or perhaps not until you hit 20 or more.

Because it can be hard to predict exactly when your existing monitoring approach will start to let you down, all I can suggest is that you prioritize implementing some basic improvements ahead of time.

How Can These Problems Occur?

This is fairly easy to spot, in a way. You’ll see production issues that you can’t explain or understand, you’ll have alerts that trigger despite the system being apparently healthy, and it will become harder to answer the simple question “Is everything OK?”

Potential Solutions

A multitude of mechanisms—some easy to implement, others more complex—can help change how you monitor and troubleshoot problems with a microservice architecture. What follows is a nonexhaustive overview of some key things to consider.

Log aggregation

With a small number of machines, especially machines that are long-lived, when we needed to check logs, we would normally go to the machines themselves and fetch the information. The problem with a microservice architecture is that we have many more processes, often running on more machines, which can be short lived (e.g., virtual machines or containers).

A log aggregation system will allow you to capture all your logs and forward them to a central location where they can be searched, and in some cases can even be used to generate alerts. Many options exist, from the open source ELK stack (Elastic search, Logstash/Fluent D, and Kibana) to my personal favorite Humio , these systems can be incredibly useful.

Tip

Strongly consider implementing log aggregation as the first thing you do before implementing a microservice architecture. It’s incredibly useful, and is a good test of your organization’s ability to implement change in the operational space.

Log aggregation is one of the simplest mechanisms to implement, and it’s something you should do early on. In fact, I suggest it’s the first thing you should do when implementing a microservice architecture. This is partly because it’s so useful right from the start. In addition, if your organization struggles to implement a suitable log aggregation system, you might want to reconsider whether you’re ready for microservices. The work required to implement a log aggregation system is fairly straightforward, and if you aren’t ready for that as an organization, microservices are likely a step too far.

Tracing

Understanding where a sequence of calls between microservices failed, or which service caused a latency spike can be difficult if you can analyze information only from each service in isolation. Being able to collate a series of flows and look at them as a whole is incredibly useful.

As a starting point, generate correlation IDs for all calls coming into your system, as shown in Figure 5-6 . When the Invoice service receives a call, it is given a correlation ID. When it dispatches a call to the Notification microservice, it passes that correlation ID along—this could be done via an HTTP header, or a field in a message payload, or some other mechanism. Typically, I’d look to an API gateway or service mesh to generate the initial correlation ID.

When the Notification service handles the call, it can log information about what it is doing in conjunction with that same correlation ID, allowing you to use a log aggregation system to query for all logs associated with a given correlation ID (assuming you put the correlation ID in a standard place in your log format). You can, of course, do other things with correlation IDs, such as managing sagas (as we discussed in Chapter 4 ).

Using correlation IDs to ensure that information about a specific chain of calls can be collected

Figure 5-6. Using correlation IDs to ensure that information about a specific chain of calls can be collected

Taking this idea further, we can use tools to also trace the time taken for calls. Due to the way log aggregation systems work, where logs are batched and forwarded to a central agent on a regular basis, it isn’t possible to get accurate information to allow you to determine exactly where time may be getting spent during a chain of calls. Distributed tracing systems like the open source Jaeger , shown in Figure 5-7 , can help.

The more latency sensitive your application is, the sooner I’d be looking to implement a distributed tracing tool like Jaeger. It’s worth noting that if you’ve worked correlation ID generation and use into your existing microservice architectures (which in general is something I advocate for well before you need a distributed tracing tool), then you’ve likely already got the places in your existing service stack that can be easily changed to push data to a suitable tool. The use of a service mesh can also help, as it can at least handle inbound and outbound tracing for you, even if it can’t do much about instrumenting calls inside individual microservices.

Jaeger is an open source tool for capturing information for distributed traces and analyzing the performance of individual calls

Figure 5-7. Jaeger is an open source tool for capturing information for distributed traces and analyzing the performance of individual calls

Test in production

Functional automated tests are typically used to give us feedback before deployment regarding whether or not our software is of sufficient quality to be deployed. But once it hits production, we still want that same feedback! Even if a given feature worked once in production, a new service deployment or environmental change could break that functionality later on.

By injecting fake user behavior into our system, in the form of what is often called synthetic transactions , we can define the behavior we expect, and alert accordingly if this isn’t the case. At one of my previous companies, Atomist, we had a somewhat complex onboarding process for new customers that required authorizing our software with both their GitHub and Slack accounts. There were enough moving parts that early on this process would hit issues, with things like being rate limited against the GitHub APIs. One of my colleagues, Sylvain Hellegouarch, scripted enrollment of fake customers. On a regular basis we would trigger a sign-up process for one of these fake customers, which scripted the whole process end to end. When this failed, it was often a sign that something was wrong in our systems and it was much better catching this with a “fake” user than a real one!

A good starting point for testing in production could be to take existing end-to-end test cases and rework them for use in a production environment. An important consideration is to ensure that these “tests” don’t cause unforeseen impact in production. With Atomist, we created GitHub and Slack accounts that we controlled for use in the synthetic transactions, so no real human was involved or impacted, and it was easy for our scripts to clean up these accounts afterward. On the other hand, I did hear reports of a company that ended up accidentally ordering 200 washing machines to be delivered to their head office because they hadn’t properly accounted for the fact that the test orders would actually end up getting sent out. So be careful!

Toward observability

With traditional monitoring and alerting processes, we think about what might go wrong, collect information to tell us when this is the case, and use this to fire off alerts. So we are primarily setting ourselves up to handle known causes of problems—disk space running out, a service instance not responding, or perhaps a spike in latency.

As our systems become more complicated, it becomes increasingly difficult to predict all the nasty ways in which our system might let us down. What becomes important at that point is to allow us to ask open-ended questions of our systems when these issues occur, to help us in the first instance to stop the bleeding and make sure the system can continue to operate, but to also allow us to gather enough information to fix the problem going forward.

So we need to be able to gather lots of information about what our system is doing, allowing us to after the fact ask questions of the data that we didn’t know we’d have to ask in the first place. Tracing and logs can form an important source of data from which we can ask questions and use real information rather than conjecture to determine what the problem is. The secret is in making this information easy to query and view in context.

Don’t assume you know the answers up front. Rather, adopt the view that you can and will get surprised, so get good at asking questions of your system, and make sure you use toolchains that allow for ad hoc querying of information. If you’d like to explore this concept in more detail, I recommend Distributed Systems Observability as an excellent starting point. 2

Local Developer Experience

As you have more and more services, the developer experience can start to suffer. More resource-intensive runtimes like the JVM can limit the number of microservices that can be run on a single developer machine. I could probably run four or five JVM-based microservices as separate processes on my laptop, but could I run ten or twenty? Probably not. Even with less-taxing runtimes, there is a limit to how many things you can run locally, which inevitably will start conversations about what to do when you can’t run the entire system on one machine.

How Can This Problem Show Itself?

The day-to-day development process can start to slow down, with local builds and execution taking longer, due to more services having to be stood up. Developers will start requesting bigger machines to handle the number of services they have to handle, and while that might be OK for a short-term fix, that will only buy you some time if your service estate continues to grow.

When Might This Occur?

When exactly this will manifest itself is likely a function of the number of services a developer wants running locally, combined with the resource footprint of those services. A team using Go, Node, or Python may well find they can have more services running locally before hitting resource constraints—but a team using the JVM may hit this problem earlier.

I also think teams practicing collective ownership of multiple services are more susceptible to this problem. They are more likely to require the ability to switch between different services during their development. Teams with strong ownership of a few services will mostly focus only on their own services, and will be more likely to develop mechanisms for stubbing out services that are outside their control.

Potential Solutions

If I want to develop locally but reduce the number of services that I have to run, a common technique is to “stub out” those services I don’t want to run myself, or else have a way to point them against instances running elsewhere. A pure remote developer setup allows for you to develop against lots of services hosted on more capable infrastructure. However, with that comes associated challenges of needing connectivity (which can be a problem for remote workers or frequent travelers), potentially having slower feedback cycles with the need to deploy software remotely before you can see it working, and a potential explosion in resources (and associated costs) needed for developer environments.

Telepresence is an example of a tool that is aiming to make a hybrid local/remote developer workflow easier for Kubernetes users. You can develop your service locally, but Telepresence can proxy calls to other services to a remote cluster, allowing you (hopefully) the best of both worlds. Azure’s cloud functions can be run locally too, but connected to remote cloud resources, allowing you to create services made out of functions with a fast local developer workflow, while still having them run against a potentially extensive cloud environment.

Seeing how the developer experience changes as the number of services increases is important—so you need feedback mechanisms put in place. You’ll need to continually invest to ensure that developers remain as productive as possible as the number of services they are working with increases.

Running Too Many Things

As you have more services, and more service instances of those services, you have more processes that need to be deployed, configured, and managed. Your existing techniques for handling the deployment and configuration of your monolithic application may well not scale well as you increase the number of moving parts that need to be managed.

Desired state management in particular becomes increasingly important. Desired state management is the ability for you to specify the number and location of service instances that you require, and ensure that this is maintained over time. You may currently manage this with your monolith using manual processes—but that isn’t going to scale well when you have tens or hundreds of microservices, especially if each of them has a different desired state.

How Might This Problem Show Itself?

You’ll start to see an increasing percentage of time spent managing deployments and troubleshooting the issues that occur during these deployments. Mistakes will always be made if processes rely on manual activities—and the impact to distributed systems of innocent mistakes can be hard to predict.

As you add more services and service instances, you’ll find yourself needing more people to manage the activities associated with deploying and maintaining your production fleet. This could result in requests for more people to support your operation team, or perhaps seeing a higher percentage of time being spent on deployment concerns by your delivery team.

When Might This Problem Occur?

This is all about scale. The more microservices you have, and the more instances you have of those microservices, the more manual processes or more traditional automated configuration management tools like Chef and Puppet no longer fit the bill.

Potential Solutions

You want a tool that allows for a high degree of automation, that can allow developers ideally to self-service provision deployments, and that handles automated desired state management.

For microservices, Kubernetes has emerged as the tool of choice in this space. It requires that you containerize your services, but once you do, you can use Kubernetes to manage the deployment of your service instances across multiple machines, ensuring you can scale to improve robustness and handle load (assuming you have enough hardware).

Vanilla Kubernetes isn’t what I would consider developer-friendly. A multitude of people are working on higher-order, more developer-friendly abstractions, and I expect that work to continue. In the future, I expect that many developers who are running software on Kubernetes won’t even realize, as it will just become an implementation detail. I tend to see larger organizations adopt a packaged version of Kubernetes, such as OpenShift from RedHat, which bundles Kubernetes with tooling that makes it easier to work with within a corporate environment—perhaps handling corporate identity and access management controls. Some of these packaged versions also provide simplified abstractions for developers to work with.

If you’re lucky enough to be on the public cloud, you could use the many different options there to handle deployments of your microservice architecture, including managed Kubernetes offerings. Both AWS and Azure, for example, offer multiple options in this space. I’m a big fan of Function-as-a-Service (FaaS), a subset of what is called serverless . With a suitable platform, developers just worry about code, and the underlying platform handles most of the operational work. While the current crop of FaaS offerings do have limitations, they nonetheless offer the prospect of drastically reduced operational overhead.

For teams I work with who are already on the public cloud, I tend to not start with Kubernetes or similar container-based platforms. Instead, I’ve adopted an approach of serverless-first—try to make use of serverless technology like FaaS as a default choice, because of the reduction in operational work. If your problem doesn’t fit the limitations of the serverless products available to you, then look for other options. Not all problem spaces are equal, obviously, but I feel that if you’re already on the public cloud, you may not always need the complexity of a container-based platform like Kubernetes.

Warning

I do see people reaching for Kubernetes and the like a bit too early in the process of adopting microservices, often assuming it is a prerequisite. Far from it—platforms like Kubernetes excel at helping you manage multiple processes, but you should wait until you have enough processes that your current approach and technology are starting to strain. You might find that you need only five microservices, and that you can happily handle this with your existing solutions—in which case, great! Don’t adopt a Kubernetes-based platform just because you see everyone else doing it, which can also be said for microservices!

End-to-End Testing

With any type of automated functional test, you have a delicate balancing act. The more functionality a test executes—the broader the scope of the test—the more confidence you have in your application. On the other hand, the larger the scope of the test, the longer it can take to run, and the harder it can be to work out what is broken when it fails.

End-to-end tests for any type of system are at the extreme end of the scale in terms of functionality they cover, and we are used to them being more problematic to write and maintain than smaller-scoped unit tests. Often this is worth it, though, as we want the confidence that comes from having an end-to-end test use our systems in the same way a user might.

But with a microservice architecture, the “scope” of our end-to-end tests gets very large. We are now having to run tests across multiple services, all of which need to be deployed and appropriately configured for the test scenarios. We also have to be prepared for the false negatives that occur when environmental issues, such as service instances dying or network time-outs of failed deployments, cause our tests to fail. I’d argue that we are much more vulnerable to issues outside of our control when running end-to-end tests against a microservice architecture than we are with a standard monolithic architecture.

As the scope of the tests increase, you’ll spend more of your time fighting the problems that arise, to the point where trying to create and maintain end-to-end tests becomes a huge time sink.

How Can This Problem Show Itself?

One sign is that your end-to-end test suite grows, taking longer and longer to complete. This is caused by multiple teams being unsure of what scenarios are covered and adding new ones “just in case.” You see more failures in the end-to-end test suite that are not highlighting issues with your code—and developers often just run the tests again to see if they pass.

The amount of time being spent on end-to-end tests takes longer and longer, to the point where you start seeing pressure for more testers and perhaps even a separate test team.

When Might This Problem Occur?

This problem tends to sneak up on you, but I see it most keenly felt in situations where the work for different user journeys is handled by multiple teams. The more isolated each team is in its work, the easier it is for them to manage their own tests locally. The more you need to test cross-team flows, the more problematic end-to-end, large scoped tests become.

Potential Solutions

I outlined a number of options for helping change how you handle testing in Building Microservices , and in fact have a whole chapter dedicated to it, but here is a brief summary to get you started.

Limit scope of functional automated tests

If you are going to write test cases that cover multiple services, try to ensure that these tests are kept inside the team that manages these services—in other words, avoid larger-scoped tests that cross team boundaries. Keeping ownership of tests within a single team makes it easier to understand what scenarios are properly covered, ensures that developers can run and debug the tests, and more clearly articulates responsibility for who should make sure the tests run and pass.

Use consumer-driven contracts

You may want to consider the use of consumer-driven contracts (CDCs) to replace the need for cross-service test cases. With CDCs, you have the consumer of your microservice define their expectations of how your service should behave in terms of an executable specification—a test. When you change your service, you ensure that these tests still pass.

As these tests are defined from the consumer point of view, we get good coverage for picking up accidental contract breakage. We can also understand our consumer requirements from their point of view, and importantly understand how different consumers might want different things from us.

You can implement CDCs by using a simple development workflow, but this can be made easier through the use of tooling designed to support this technique. The best example is probably Pact .

It’s worth noting that I’ve seen some teams have huge success with this approach, but it’s been difficult for others to adopt. The idea is sound, and I know it can work well, but I haven’t yet fully understood the challenges that some people have had in adopting this technique. It remains a poorly underused practice for solving a really difficult problem.

Use automated release remediation and progressive delivery

With automated testing, we are typically trying to find problems before they impact production, but it can become increasingly difficult to do that as your system becomes more complex. Therefore, it can be worth spending effort in reducing the impact of production issues if they do occur.

As we touched on in Chapter 3 , progressive delivery is the umbrella term for controlling how you roll out new versions of your software incrementally to your customers. The idea is that you can assess the impact of your new release with a smaller group of customers, deciding if and when to continue or revert the rollback. An example of a progressive delivery technique could be a canary release.

By defining acceptable measures for how your service should behave, it then becomes possible to control the progressive delivery in an automated fashion. As a simple example, you might define an acceptable threshold for 95th percentile latencies and error rates, and continue the rollout only if these measures are met. Otherwise, you may automatically roll back the latest release, giving you time to analyze what happened.

Many organizations use these automated release remediation techniques. Netflix, in particular, has spoken at length about using this idea. It developed Spinnaker as a deployment management tool partly to help control progressive delivery for its services, but there are many other ways you can put these ideas into practice.

I’m not saying you should consider automated release remediation instead of testing, just that you should think about where you get the best return on your effort. You may end up with a far more robust system by putting some work into catching problems if they do occur, rather than just focusing on stopping problems from happening in the first place.

It’s important to note that while these techniques work well together, even if you think automated remediation isn’t something you can do right now, there is still huge value to be had from implementing some form of progressive delivery. Even manually controlling progressive delivery can be a big step up from just rolling the new software out to everyone.

Continually refine your quality feedback cycles

Understanding how and where you should test is an ongoing challenge. You need people who have the context to look holistically across the development process to adapt how and where you are testing your application. This means having people who can identify the need to add new tests to cover areas of the system where they are seeing an increase in production defects, but also who can remove tests when there is already coverage in an effort to improve feedback cycles.

In short, it’s about balancing the need for fast feedback with safety. You need to be just as willing to identify, and remove or replace, the wrong test as you are to add a new test.

Global Versus Local Optimization

Assuming you embrace the model of teams having more responsibility for local decision-making, perhaps owning the entire life cycle of the microservices they manage, you’ll get to the point where you start to need to balance local decision-making with more global concerns.

As an example of how this problem might manifest, consider three teams who manage the Invoicing, Notifications, and Fulfillment services. The Invoicing team decides to use Oracle as a database, as they know it well. The Notifications team wants to use MongoDB because it fits their programming model well. Meanwhile, the Fulfillment team wants to use PostgreSQL, as they already have it. When you look at each decision in turn, it makes perfect sense, and you understand how that team would have made that choice.

If you step back and look at the big picture, though, you have to ask yourself whether or not as an organization you want to build skills, and pay license fees, for three databases with somewhat similar capabilities. Would you be better off adopting just one database, accepting that it isn’t perfect for everyone, but is good enough for most? Without the ability to see what is happening locally, and being able to put this into a global context, how would you ever be able to make these sorts of decisions?

How Can This Problem Show Itself?

The most common way I’ve seen this problem come to light is when someone suddenly realizes that multiple teams have solved the same problem in different ways, but were never aware that they were all trying to fix the same issue. Over time this can be incredibly inefficient.

I remember speaking to people at REA, a real estate company in Australia. After many years building microservices, they got to the point where they realized that there were many ways that teams would deploy services. This caused problems when people moved from one team to another, as they had to learn the new way of doing things. It also became hard to justify the duplicate work that each team was doing. As a result, they decided to put some work into coming up with a common way to handle this.

You’ll typically find out about these things accidentally, after a passing comment you overhear at lunch, perhaps. You can spot these problems much earlier if you have some sort of cross-team technical group, such as a community of practice.

When Might This Problem Occur?

This problem tends to arise in multiteam organizations over time, especially in organizations that give teams more freedom in how they go about their work. Don’t expect to see this issue early on in your microservice journey. You’ll start out probably with a clear shared understanding of how things should be done. Over time, each team will be increasingly focused on their local problems, and will optimize how they solve problems based on this, so that core shared view of “this is how we do things” will start to shift.

I often see this problem being raised and discussed after organizations have gone through a period of scaling. The influx of a lot of developers in a short space of time makes it harder for ad hoc information sharing to scale. This can lead to more information silos that may need to be bridged.

If you practice collective ownership of services, that will likely help avoid or at least limit these problems, as collective ownership of services requires a degree of consistency in terms of how problems are solved. Put another way, if you want collective ownership, you have to solve this problem; otherwise, your collective ownership won’t scale.

Potential Solutions

We’ve already touched on some ideas that can help in this area. In Chapter 2 , we explored the idea of irreversible and reversible decisions, as shown again in Figure 5-8 . The higher the cost of change, the larger the impact, and the more you’ll want a broader consensus behind decision-making. The smaller the impact, the easier it is to roll back, and the more decisions can be left to local teams.

The differences between Irreversible and Reversible decisions, with examples along the spectrum

Figure 5-8. The differences between irreversible and reversible decisions, with examples along the spectrum

The trick is helping people in teams realize where their decisions might tend toward the irreversible or reversible ends of this spectrum. The more a decision tends toward irreversible, the more important it might be for them to involve other people outside their team boundary in their decision-making. For this to work well, teams need to have at least a basic understanding of the bigger-picture concerns to see where they may overlap, and they’ll also need a network where they can surface these issues and get involvement from their colleagues in other teams.

As a simple mechanism, having at least one technical leader from each team being part of a technical cross-cutting group where these concerns can be addressed is a sensible approach. This group may be chaired by a CTO, chief architect, or other person who is responsible for the overall technical vision of the company.

This cross-cutting group can work both ways. In addition to offering a place where teams can surface local issues that they want to discuss in a larger forum, it is also somewhere people can pick up cross-cutting issues. Without some communication between teams, how would we realize that we’re solving problems in different ways locally, and that perhaps solving them at a global level might make more sense?

Depending on the nature of your organization, you may be able to rely on a more ad hoc, informal process. At Monzo, for example, people can submit free-form documents referred to internally as “proposals.” These are published into a shared space that in turn alerts the whole company via Slack that a new proposal is available. Interested parties can then discuss the proposal and help refine it. The expectation is that these proposals aren’t the finished artifact, and in fact must be open to change. This seems to work well for Monzo, in part because of its culture around communication and sharing of responsibility.

Fundamentally, each organization needs to find the right balance between global and local decision-making. How much responsibility are you happy to push into the teams? How much control do you want to hold centrally? The more responsibility you push to the teams, the more you’ll get the benefits of greater autonomy, but the trade-off is that you may have less consistency in how problems are solved. The more you drive things from the center, the more you’ll need to build consensus and that will likely slow you down. I can’t tell you how to achieve balance between these two forces in a way that is right for you; you’ll need to work that out for yourself. You just need to be aware that this balance exists, and you need to make sure you’re gathering the right information to make sure you can adjust this balance over time.

Robustness and Resiliency

Distributed systems can exhibit a whole host of failure modes that may be unfamiliar to you if you are more accustomed to monolithic systems. Network packets can get lost, network calls can time out, machines can die or stop responding. These situations may be rare with simple distributed systems, such as a traditional monolithic application, but as the number of services increases, rare occurrences become more commonplace.

How Can This Problem Show Itself?

These problems are, unfortunately, most likely to arise in a production setting. During traditional development and test cycles, we’re re-creating production-like circumstances only for short periods of time. Those rare occurrences are less likely to emerge, and when they do, they often get dismissed.

When Might This Problem Occur?

I’ll be honest here—if I could tell you in advance when your system will suffer from instability I wouldn’t be writing this book, as I’d likely be spending my time on a beach somewhere drinking mojitos. All I can say is that as the number of services increases, and the number of service calls increase, you’ll become more and more vulnerable to resiliency issues. The more interconnected your services are, the more likely you’ll suffer from things like cascading failures and back pressure.

Potential Solutions

A good starting point is to ask yourself a couple of questions about each service call you make. First, do I know the way in which this call might fail? Second, if the call does fail, do I know what I should do?

Once you’ve answered these questions, you can then start looking at a host of solutions. Isolating services more from each other can help, perhaps including the introduction of asynchronous communication to avoid temporal coupling (a topic we touched on in Chapter 1 ). Using sensible time-outs can avoid resource contention with slow downstream services, and in conjunction with patterns like circuit breakers, you can start failing fast to avoid problems with back pressure.

Running multiple copies of services can help with instances dying, as can a platform that can implement desired state management (which can ensure that services get restarted if they crash).

To restate a point made in Chapter 2 , resiliency is more than just implementing a few patterns. It’s about a whole way of working—building an organization that not only is ready to handle the unforeseeable problems that will inevitably crop up, but also evolves working practices as necessary. One concrete way you can put this idea into practice is by documenting production issues when they arise and keeping a record of what you learned. All too often I see organizations move on too quickly once the initial problem has been solved or worked around—only for those same problems to come back again some months later.

To be honest, I’ve just scratched the surface here. For a more detailed examination of these ideas I recommend reading Chapter 11 in Building Microservices , or taking a look at Release It! by Michael Nygard (Pragmatic Bookshelf, 2018).

Orphaned Services

It seems odd, given some of the amazing technology that we have and the incredibly complex and massively scalable systems we are now building, that we also still see problems with some of the most prosaic issues. One example is that I see many organizations struggle with knowing exactly what they have, where it is, and who owns it.

As microservices become even more focused in their purpose, you’ll find more and more services have been happily running for weeks, months, or perhaps years without any changes being made to them. On the one hand, this is exactly what we want; independent deployability is such an appealing concept partly because it allows the rest of the system to remain stable, and maintaining stability of the parts of our system that don’t need to change is a good idea.

I refer to these services as orphaned services , as fundamentally no one in the company is taking ownership or responsibility for them.

How Can This Problem Show Itself?

I remember hearing (perhaps apocryphal) stories of old servers being discovered walled up in old offices. No one remembers they were there, but they are still happily running, doing whatever it is they do. As no one remembers exactly what these newly discovered computers do, people are scared to turn them off. Microservices can exhibit some of the same characteristics; they’re out there and they’re working (we assume), but we have the same problem that we may not know what to do with them, and that fear can put us off changing them.

The fundamental problem is that if this service does stop working, or does require a change, people are at a loss as to what to do. I’ve spoken to more than one team that shared stories of not knowing where the source code was for the service in question, which is a pretty big problem.

When Might This Problem Occur?

This problem typically occurs with organizations that have been using microservices for a long period of time—long enough that the collective memory regarding what this service did has long since diminished. The people involved with this microservice have either forgotten what they did to it or perhaps left the company.

Potential Solutions

I have an (untested) hypothesis that organizations that practice collective ownership of services might be less prone to this problem, primarily because they will already have to have implemented mechanisms to allow developers to move from service to service and make changes. These sorts of organizations already probably restrict language and technology choice to reduce the cost of context switching between services. They may also have common tooling around making changes to a service, testing it, and deploying it. If those common practices have changed since the service was last changed, of course this may not help.

I’ve spoken with a number of companies that have had these issues, and that ended up creating simple in-house registries to help collate metadata around services. Some of these registries simply crawl source code repositories, looking for metadata files to build up a list of services out there. This information can be merged with real data coming from service discovery systems like consul or etcd to build up a richer picture of what is running, and who you could speak to about it.

The Financial Times created Biz Ops to help address this problem. The company has several hundred services developed by teams all over the world. The Biz Ops tool ( Figure 5-9 ), gives them a single place where you can find out lots of useful information about their microservices, in addition to information about other IT infrastructure services like networks and file servers. Built on top of a graph database, they have a lot of flexibility about what data they gather and how the information can be modeled.

The Financial Times Biz Ops tool, which collates information about its microservices

Figure 5-9. The Financial Times Biz Ops tool, which collates information about its microservices

The Biz Ops tool goes further than most I have seen, however. They calculate what they call a System Operability Score, as shown in Figure 5-10 . The idea is that there are certain things that services and their teams should do to ensure the service can be easily operated. This can go from making sure the teams have provided the correct information in the registry to ensuring the services have proper health checks. These scores are calculated, allowing teams to see at a glance if there are things that need to be fixed.

An example of the Service Operability Score for a microservice at the financial times

Figure 5-10. An example of the Service Operability Score for a microservice at The Financial Times

Having something like a service registry can help, but what happens if your orphaned service predates your registry? The key thing is to bring these newly discovered “orphaned” services into line with how other services are managed, and that requires you to either assign ownership to an existing team (if practicing strong ownership), or raise work items for the service to be improved (if practicing collective ownership).

Summary

What we’ve covered in this chapter isn’t meant to be an exhaustive list of all the issues that microservices can cause, nor have I listed all the potential solutions. Instead, the focus has been on the most common problems that I see people struggle with.

I hope I’ve also made it clear that there isn’t a hard-and-fast rule about exactly when you’ll see these problems. Every situation is different, and a multitude of factors come into play. What I’ve tried to do is highlight that while you can’t see the future, you can at least be forewarned. What is more challenging is finding the right balance between fixing problems before they occur versus spending time fixing problems you’ll never have. I hope you walk away from this chapter knowing what warning to watch for.

1 A colander is a bowl with lots of holes, used for straining pasta, for example.

2 See Cindy Sridharan, Distributed Systems Observability (Sebastopol: O’Reilly Media, Inc., 2018).