What are Microservices? Introduction to Microservices Architecture

December 26, 2019

Introduction

In the past decade, application development has been rapidly evolving to keep up with technological advances and consumer needs.

While traditional development relied on one large chunk of code, most apps today are constructed from several mini-applications or microservices, each responsible for a single functionality of the app.

Together they form a system referred to as the microservice architecture.

what-are-microservices

What are Microservices?

Microservices, or rather the microservice architecture, is a system used to develop an application, built on a selection of individual services working together to ensure seamless and highly responsive performance.

If you are building a web application using the microservice architecture, you divide it into individual functionalities, developing, and deploying each as a separate app.

As opposed to monolithic development, where everything is merged and, therefore, dependent on one another, the microservice architecture consists of multiple modules of autonomous components. It is a type of architecture relying on the system of loose coupling.

Note: Loose coupling is structuring a system in which the elements are unaware of one another, but can communicate.

For example, an e-commerce website requires many different services, including online payments, returns, user profiles, and so on. To create the website, the developers would break up into teams, each responsible for building one of the microservices in use.

How do Microservices Talk to Each Other?

Once you have comprehended the structure, you may wonder how these separate entities come together to create one harmonious service or application. The answer comes down to establishing direct, fast, and flawless communication between all the services. Hence, microservices communicate with each other through APIs.

Application Programming Interface (API) is an access point of each modular functionality that allows modules to interact. A microservice uses this interface to send and respond to requests from other modules.

Each microservice needs to have a clearly defined API endpoint (one end of a communication channel) to ensure it is always accessible for inquiries. In most cases, these are stateless REST APIs. Without distinctly defined endpoints, the system doesn’t know where to seek the information it needs.

Therefore, DEV teams would use official standards and patterns to share endpoints among themselves. It is their responsibility to establish the REST API through collaboration and clear communication.

Graph explaining Microservices from Client and Server side

The Difference Between Traditional Architecture and Microservices Architecture

To get a better understanding of microservices, let’s compare them to the system used prior to their development – monolithic architecture.

Monolithic architecture worked fine for traditional server-side systems. These are systems based on a single application. All the functionalities reside in one structure, use the same file system, communicate with the same server, and are eventually deployed on the same machine.

This kind of architecture allows developers to create applications faster, as they only need to build the essential features to which they would later add-on other functionalities. Also, the performance was faster as the process doesn’t involve APIs.

With the expansion of web applications came the need for agility and consistent uptime. Monolithic architecture had too many obstacles to keep up with these demands.

The difference between monolithic architecture and microservices architecture

Cons of Monolithic Architecture

As these systems had a tightly coupling process, any changes made to the code could potentially endanger the performance of the entire application. The functionalities were too interdependent for a new technological age that demanded constant innovations and adaptation.

Another issue with monolithic architecture was its inability to scale individual functionalities. One crucial aspect of successful businesses is their ability to keep up with consumer demands. Naturally, these demands depend on various factors and fluctuate over time.

At some point, your business will need to scale only a certain function of its service to respond to a growing number of requests. With monolithic apps, you weren’t able to scale individual elements but rather had to scale the application as a whole.

Benefits of Microservices

The introduction of microservices solved many issues that monolithic development could not.

1. Highly Flexible

First, the microservice architecture is highly flexible. Since each microservice is independent, programmers can build modules using different languages or platforms. These modules will be able to communicate with each other thanks to APIs.

Furthermore, with microservices no organization has to commit long-term to a technology stack. Thus, developers can always work with the latest technology.

2. Reusable Functionality Modules

Moreover, this feature allows developers to reuse functionality modules and apply them to other applications. Utilizing already refined microservices saves company resources, and lets developers focus on other projects.

3. Resilient to Changes

Another significant feature is that the system is quite resilient to changes. Loosely coupled, the functionalities within an app are not as codependent. Developers can efficiently add new features or modify existing ones. They alter the code of one module instead of the entire application.

4. Scalable

Unlike monolithic apps, microservices are excellent for scaling. They ensure your application is up and running at all times, without wasting any money on unused modules. Since you deploy functionalities on different servers, the system allows you to scale only the resources needed.

5. Faster Development Cycles

In a distributed model, the app is broken down into smaller services. If your organization has adopted agile development, your teams can more easily update it and speed up development cycles.

From a business perspective, faster development cycles are one of the greatest improvements introduced by microservices.

6. Transparent Model

New employees, for example, will more easily understand and modify the code. This builds upon the fact that the app is distributed among numerous services. Handling one microservice at a time is easier than tackling an entire integrated system.

Drawbacks of Microservices

1. Complexity

The number one drawback of microservice architecture is its complexity. Compared to monolithic applications, the newly developed system has many more components. These components (microservices) have to work flawlessly on their own and inside the system.

2. Expenses

This system is also more expensive. Because services are deployed on multiple servers, the application ends up requiring a more significant number of CPUs and more runtime environments. In addition, due to their need for constant communication, microservices make many remote calls. These and other factors add up, thus requiring an expanded budget for development.

3. Security

Microservices also require higher security measures. As mentioned above, services talk to each other via APIs. This means they exchange information over the network, which is always a potential threat. For this reason, maintenance and upgrades need to be impeccable.

4. Performance

The complexity of the architecture also influences its performance. As microservices include multiple JVM (Java Virtual Machine) instances and inter-process communication, their efficiency can be slower than with monolithic apps.

PROSCONS
Independence of services. Each service container has its own business logic and focuses on single business capability. The architecture supports individual deployable units independent from each other.Intricate Setup.  Due to their individualism, setting up the system requires more configuration and resources, resulting in operational overhead.
Flexible/agile deployment. Each microservice can be scaled independently with the opportunity to use different technologies and run on different stacks and products.Operational complexity. It is more difficult to troubleshoot, debug, and trace transactions through the microservice ecosystem. Addressing issues in the system demands high levels of automation.
Fault tolerant. Microservices are loosely coupled units that can be automatically restored. These units are not co-dependent, allowing developers to increase availability of each unit, when needed.Security risk. Although isolated services are more fault tolerant, the same feature may raise security issues during transactions between units.
Supports CI/CD. Since microservices are independently deployed, multiple instances can be developed and deployed simultaneously.  Hence, it leads to faster and more frequent software releases.Codependent interfaces. Services communicate over interfaces that are interdependent. It is impossible to modify one interface without adjusting the other.
Streamlines adding new features. It is easier to add new features by changing existing services or adding new ones without disrupting the performance of other services.Slower Performance. Compared to monolithic applications, microservices need more time to perform tasks due to their complex architecture and inter-process communication.

Challenges to Adopting Microservices

1. Designing a Distributed Model

The initial challenge to adopting microservices is designing a reliable and sustainable model. Microservices use a loosely distributed system, so chances are that you are going to end up with a complex design. All system dependencies must be carefully considered and taken into consideration.

2. Integration Testing

Another challenge is integration and end-to-end testing. Testing becomes more difficult and yet more important than ever. Microservices have to communicate and support one another, so all services need to be bug-free. A bug in one service can cause a fatal error in another. This is why continuous testing with microservices is paramount.

3. Deployment

If you are still deploying manually, your team will initially have to invest time in automating the process. Due to the complexity of distributed models, deploying manually becomes far too complex.

4. Monitoring and Logging

Organizations adopting microservices must establish a centralized monitoring and logging system. If not configured, identifying and debugging issues becomes impossible.

5. Debugging

Due to all of the above-mentioned factors and other complexities, such as load balancing and latency, debugging issues, in a distributed system, is complex. There is no simple answer to what approach works best, and it will surely take some time before you find what works best for your project.

6. Other Considerations

Finally, your organization needs to adapt to adopt a microservice model. The way your teams work and cooperate will need to change. Drive a change in your company culture to prepare your teams for microservices.

Examples of Microservices

Microservices in Java

You can develop microservices using different languages. However, Java is still considered one of the top choices for building applications with such architecture.

There are multiple microservices frameworks used for developing with Java, including:

  • Spring Boot
  • Swagger
  • Jersey
  • Dropwizard
  • JHipster
  • Vert.x
  • Play

In addition, the microservice setup is often used to support a machine learning (ML) environment as it allows multiple machine learning frameworks in the workflow. TensorFlow, Apache Mahout, and Apache Singa are all examples of ML frameworks used with Java.

By collecting, aggregating, and analyzing data flow, the frameworks can predict outcome and provide comparison between models.

Microservices in Docker

Docker is another great software for building microservices. As it uses containers to run virtual environments, the platform allows several ways of organizing microservices:

  • Each container may be dedicated to an individual service.
  • A single service can be separated into multiple containers for separate processes within the service.

Containers are a practical way of isolating microservices. They are lightweight, deployable, and scalable to various operating systems and infrastructure.

If you are running a multi-container Docker application, Docker Compose is a tool that can help you manage and configure all your microservices. This is all done with a single yaml and performs the tasks of launching, executing, communicating, and closing containers with a single coordinated command.

Multi-container applications with numerous Docker hosts are best managed with a container orchestration platform, such as Swarm or Kubernetes. Both platforms allow you to administer clusters of servers each with multiple services on them. To learn more about their differences, please refer to our article Kubernetes vs Docker Swarm.

The following is an illustration of how to manage container clusters with Swarm and Compose collaborating in a unified system.

How to use Docker Swarm and Compose for microservices architecture

Conclusion

When deciding on the architecture, bear in mind the type of application you are building. Take into account the pros and cons discussed in this article. In most cases, the size and complexity of the app you want to develop should determine its architecture.

The traditional monolithic approach works fine for smaller-scale applications. However, if you want to create a complex, multi-functional app, microservices are the better choice.

Was this article helpful?
YesNo
Sofija Simic
Sofija Simic is an experienced Technical Writer. Alongside her educational background in teaching and writing, she has had a lifelong passion for information technology. She is committed to unscrambling confusing IT concepts and streamlining intricate software installations.
Next you should read
What is Kubernetes? Complete Guide
April 20, 2023

If you are using Docker, you need to learn about Kubernetes. It is an open-source container orchestration...
Read more
How to Commit Changes to a Docker Image with Examples
November 14, 2019

Docker allows users to run a container based on an existing image. This feature is both time efficient and...
Read more
Understanding Kubernetes Architecture with Diagrams
November 12, 2019

The article explores Kubernetes Architecture and the concept of Container Deployment. All elements of a...
Read more
Docker Image vs Container: The Major Differences
October 31, 2019

Docker images and containers are elements in Docker's platform-as-a-service software. They are both essential...
Read more