How to transition to a microservices architecture

When you hit scalability issues or find it has become costly and hard to release regular updates to your monolithic applications, it’s time to move to the microservices approach. Here’s how

How to transition to a microservices architecture
Kyoshino / Getty Images

By this point, you know what microservices are and how they work. Now it’s time to get down to brass tacks: namely, the very critical topic of how to approach the transition to microservices.

The need for microservices transition

A monolithic application is very large (in terms of lines of code) and complex (in terms of functions interdependencies, data, etc.), serving hundreds of thousands of users across geographical regions and requiring several developers and IT engineers. A monolithic app may look something like Figure 1.

Sometimes, even with all these characteristics, the application might run fine at first. You may not encounter challenges in terms of application scalability or performance. But with time and usage, issues will arise, and they may be different for different applications.

For example, for a cloud or web application, you may hit scalability issues due to more users consuming your services, or it may become costly and hard to release regular new updates due to longer build times and regression testing. As shown in Figure 2, monolithic application users or developers may experience one or more issues listed on the right.

microservices and containers book fig1 Pearson Addison-Wesley

Figure 1. Basic structure of a monolithic app

microservices and containers book fig2 Pearson Addison-Wesley

Figure 2. Potential issues with a monolithic app

That’s when a migration to microservices may start sounding like more than a trendy idea; it will sound like a lifesaver. The transition will look something like the application shown in Figure 3.

microservices and containers fig3 Pearson Addison-Wesley

Figure 3. Transition from monolith to microservices

So, how do you go about making such a change? There are two possible scenarios:

  • Creating a brand-new application.
  • Converting or migrating a monolithic application that already exists.

The latter scenario is far more likely, but it is worth knowing the ins and outs of both scenarios regardless of your current situation.

Creating a new application with microservices

I have not seen many real-world scenarios of building a microservices-based application from scratch. Typically, an application is already in place, and most applications I have worked on are more of a transition to a microservices architecture from a monolithic architecture. In these cases, the intention of architects and developers has always been to reuse some of the existing implementation. But as skills become readily available in the market and some successful implementations are published, we will see more examples of building microservices-based applications from scratch, so it is certainly worthwhile to explore this scenario.

Let’s say you have all the requirements figured out and are ready to go into the architecture design of the application you are going to build. There are many common best practices you need to think about as you get started, which are covered in the following sections.

Organizational readiness

The first question you have to ask yourself is whether your organization is ready to transition to microservices. That means the various departments of your organization now need to think differently about building and releasing software in the following ways:

  • Team structure. The monolithic application team (if one exists) needs to be broken down into several small high-performance teams aware of or trained in microservices best practices. As you saw in Figure 3, the new system will consist of a set of independent services, each responsible for offering a specific service. This is one key advantage of the microservices paradigm: It reduces the communication overheads, including those multiple nonstop meetings. Teams should be organized by business problems or areas they are trying to address. The communication then becomes about the timing and set of standards/protocols to follow so that these microservices can work with each other as one platform.
  • Each team must be prepared to function independently of others. They should be the size of a standard scrum team; otherwise, communication will become an issue again. Execution is the key, and each team should be able to address the changing business needs.
  • Tools and training. One of the key needs is the organization’s readiness to invest in new tools and people training. The existing tools and processes, in most cases, would need to be retired and new ones picked up. This will require a large capital investment as well as investment in hiring people with new skills and retraining existing staff members. In the long term, if the decision is right to get on microservices, organizations will see savings and recoup the investment.

Services-based approach

Unlike with monolithic applications, with microservices you need to take a self-sustained services-based approach. Think of your application as a bunch of loosely coupled services that communicate with each other to provide complete application functionality. Each service must be thought of as an independent, self-contained service with its own life cycle that can be developed and maintained by independent teams. These teams may select from a variety of technologies, including languages or databases that best suit their services’ needs.

For example, for an e-commerce site, the team would write a completely independent service, such as a shopping cart microservice, with an in-memory database, and another one, such as an ordering microservice, with a relational database. A real-world application may use microservices for basic functions such as authentication, account, user registration, and notification with the business logic encapsulated in an API gateway that calls these microservices based on the client and external requests.

Just a reminder: A microservice may be a small service implemented by a single developer or a complex service requiring a few developers. With microservices, the size does not matter; it all depends on one function that a service has to provide.

Other aspects that must be considered at this point are scaling, performance, and security. Scaling needs can be different and provided on an as-needed basis at each microservice level. Security should be thought of at all levels, including data at rest, interprocess communication, data at motion, and so on.

Interprocess (service-to-service) communication

Key aspects that must be thought of are security and communication protocol. Asynchronous communication is the way to go, because it keeps all requests on track and does not hold resources for extended periods of time.

Using a message bus such as RabbitMQ may prove to be beneficial for this kind of communication. It is simple and can scale to hundreds of thousands of messages per second. To prevent the messaging system from becoming a single point of failure if it goes down, the messaging bus must be properly designed for high availability. Other options include ActiveMQ, which is another lightweight messaging platform.

Security is key at this stage. In addition to selecting the right communication protocol, industry standard tools such as AppDynamics may be used to monitor and benchmark the interprocess communication. Any anomalies must be reported automatically to the security team.

When there are thousands of microservices, it does become complex to handle everything. I explain how to address such issues through discovery services and API gateways in Chapter 3.

Technology selection

The biggest advantage of transitioning to microservices is that it enables choices. Each team can independently select the language, technology, database, and so on that are the best fit for the given microservice. Usually in a monolithic approach, the team does not have this flexibility, so make sure you do not overlook and miss the opportunity.

Even if a team is handling multiple microservices, each microservice must be looked at as a self-contained service, and it needs be analyzed. Scalability, deployment, build time, integrations and plugins operability, and so on must be kept in mind when choosing the technology for each microservice. For microservices with lighter data but faster access, an in-memory database may be most suitable, whereas others may share the same relational or NoSQL databases.


Implementation is the critical phase; this is where all the training and best practices knowledge comes in handy. Some of the critical aspects to keep in mind include the following:

  • Independency. Each microservice should be highly autonomous with its own life cycle and treated as such. It needs to be developed and maintained without any dependencies on other microservices.
  • Source control. A proper version-control system must be put at place, and each microservice must follow the standards. Standardizing on a repository is also helpful, because it ensures that all the teams use the same source control. It helps in various aspects, such as code review, providing easy access to all the code in one place. In the long term, it makes sense to have all the services on the same source control.
  • Environments. All different environments—such as dev, test, stage, and production—must be properly secured and automated. The automation here includes the build process; that way, the code can be integrated as required, mostly on a daily basis. There are several tools available, though Jenkins is widely used. Jenkins is an open source tool that helps automate the software build and release process including continuous integration and continuous delivery (CI/CD).
  • Fail-safe. Things can go wrong, and software failure is inevitable. Handling failures of downstream services must be addressed in the microservice development. Failure of other services must be graceful to the extent that the failure should be invisible to the user. This includes managing service response times (time-outs), handling API changes for downstream services, and limiting the number of auto-retries.

With microservices, don’t be shy about reusing the code by using copy and paste, but do it within limits. This may cause some code duplication, but it’s better than using shared code that may end up coupling services. In microservices, you want decoupling, not tight coupling. For example, you will write code to consume the output response from a service. You can copy this code every time you call the same service from any client. Another way to reuse code is by creating common libraries. Multiple clients can use the same library, but then each client should be responsible for maintaining its libraries.

It can sometimes become challenging when you create too many libraries and each client is maintaining a different version. In that case, you may have to include multiple versions of same library, and the build process may become difficult due to backward compatibility and similar concerns. Depending on your needs, you can go either way as long as you can control the number of libraries and versions by clients and put a tight process around them. This will certainly save you from lot of code duplication.

Given the sheer number of microservices, debugging a problem may become difficult, so you need to do some kind of instrumentation at this stage. One of the best practices is to tag each request with a unique request ID and log each one of them. This unique ID identifies the originating request and should be passed by each service to any downstream requests.

When you see issues, you can clearly track back through logs and identify the problematic service. This solution will be most effective if you establish a centralized logging system. All the services should log in all the messages to this shared system in a standardized format so that teams can replay the events as required all from one place, from infrastructure to application. A shared library for centralized logging is worth looking into. There are several log management and aggregation tools out there in the market, such as ELK (ElasticsearchLogstash, Kibana) and Splunk, that are ideal.


Automation is the key during deployment. Without it, success with a microservices paradigm is almost impossible. There may be hundreds to thousands of microservices, and for the agile delivery, automation is a must.

Think of deploying thousands of microservices and maintaining them. What happens when one of the microservices goes down? How do you know which machine has enough resources to run your microservices? It becomes very complicated to manage this without automation in place. Various tools, such as Kubernetes and Docker Swarm, can be used to automate the deployment process.


The operations part of the process needs to be automated as well. Again, I am talking about hundreds to thousands of microservices—organizational capabilities need to mature enough to handle this level of complexity. You’ll need a support system, including the following:

1 2 Page 1
Page 1 of 2
How to choose a low-code development platform