What are Microservices and When to Use Them?
Microservices architecture, or simply microservices, is a software development life cycle (SDLC) approach for building large applications as a collection of small functional modules.
Microservices have become the preferred platform for cloud application development.
“70% of organizations are either using or thinking about using microservices, with almost a third of companies currently using them in production,” Nginx.
Gartner, a global research and consulting company, defines microservice as:
A service-oriented application component that has a narrow scope, strong encapsulation, loose coupling, independent deployment, and independent scaling.
This article will address microservices. Let’s get it started.
What are Microservices?
Microservices architecture, or simply microservices, is an SDLC approach for building large applications as a collection of small functional modules. These functional modules independently deploy, scale, target specific business goals, and communicate with each other using standard protocols such as HTTP, APIs, and lightweight asynchronous messaging.
The main advantage of microservices architecture is that modules can be implemented using different programming languages; they can have their own databases and be deployed in different software environments, both on-premises and cloud.
Advantages of Microservices
There are many advantages to microservices that really give developers an edge over monolithic applications. Here are just some of them.
- Multiple services can be deployed independently in different environments such as on-premises or in the cloud;
- Several services can be developed independently based on functionality;
- If any of the services fails, the other services will continue to run, which helps isolate the failure.
- With microservices, it is easier to scale individual components as the scaling of other components is not required, unlike a monolithic architecture;
- Several different technologies can be used to develop different components within a single application.
Disadvantages of Microservices
Although microservices are gaining traction and pretty trendy today, this type of software architecture has its flaws. In general, the main disadvantage of microservices is the complexity of any distributed system.
Here is a list of some potential problem areas and other weaknesses associated with microservice design:
- The communication between services is complex: since everything is now independent, you must carefully handle the requests that move between your modules.
- More services mean more resources: multiple databases and transaction management can be difficult.
- Global testing gets harder: testing a microservices-based application can be cumbersome. Each dependent service must be validated prior to testing.
- Debugging issues: each service has its own set of logs that needs to be reviewed.
- Deployment issues: the product may require coordination between multiple services.
- Large and small product companies: microservices are great for large companies, but can be slower to implement and too complex for small companies that need to create and iterate quickly and don’t want to get bogged down in complex orchestration.
Monolithic vs. Service-Oriented vs. Microservices Architecture
- A monolithic architecture is like a large container in which all the software components of an application are gathered together and tightly packed.
- A service-oriented architecture is a set of services that interact with each other through a simple transfer of data or two or more services that coordinate a particular activity.
- Microservice architecture is an architectural style that structures an application as a collection of small, self-contained services modeled around a business domain.
When Does It Make Sense to Use Microservices?
It’s best to use Microservices:
- When you are working with a monolithic application and it grows to the point where scaling issues arise,
- When you cannot reuse components across projects or platforms, and
- Introducing new features becomes painfully complex and error-prone.
When launching new applications, you will definitely want them to be easily scalable, maintainable, deployable, and testable. By using microservices, all of the above can be implemented more efficiently and used across multiple platforms.
Netflix: Hundreds of Microservices for One Giant Product
Let’s try to understand what microservices look like from the technological point of view using the following example.
Let’s say your navigation app constantly tracks your location and stores complex information about your movements in the locations.txt file. You’ve created an app called LocoList that looks for the locations.txt file on your smartphone and shows all of those locations in a simple list. It works perfectly well.
But then your developers decide that it would be better to store your geolocation information elsewhere. They update the app so that it won’t store this file on your phone anymore. Now when LocoList cannot find the locations.txt file, you cannot get this information from maps. LocoList has stopped working.
As a result, all your work on LocoList is wasted because a small change broke your application. It might not seem like a big deal, but on a huge service like Netflix, a change in one part will not only ruin the user experience, but also cause other parts to have to be rewritten to accommodate the change. This is called monolithic architecture.
About a decade ago, Netflix revolutionized the microservices architecture, where any application, code, and resource is independent of each other. If two applications need to communicate, they use an API, a specific set of rules that applies to both programs. Developers can make changes to each application as long as the API conforms. And since the programs are familiar with each other’s API, the exchange of information will not stop because of the changes being made.
Netflix estimates that the service uses about 700 microservices to control every part of the product: one microservice stores information about the TV shows watched, another charges the monthly fee from the card, the third one provides your device with the necessary video files, the fourth one examines your history to suggest a list of movies you may like, and one more provides titles and images of these movies for the main menu. This is just the tip of the iceberg. Netflix developers can make changes to any part of the app, confident that the service will continue to work properly.
Why is Microservices Architecture Crucial to Netflix?
To run all of these services, you need a powerful server network. Netflix previously had their own hardware, but realized that at this rate of growth, it would be difficult for them to build scalable systems that would support their service. The company has made the bold decision to ditch its own servers and move everything they have to the cloud, that is, run everything on the servers of another company that will take care of the hardware while Netflix developers write programs and deploy them to servers. They chose Amazon Web Services (AWS) for their infrastructure.
Wait…Amazon? The company that runs Prime Video? How can Netflix trust its competitor with everything? Well, many companies follow certain conventions that they work for each other, while competing in the same categories. Samsung, for example, competes with Apple for smartphones, but at the same time, it produces some parts of the iPhone. Netflix was an AWS customer before Prime Video came along, but that doesn’t mean they have to feud with each other.
It turns out that the Netflix-Amazon partnership is a win-win situation for both companies. Netflix is one of the largest AWS customers and is constantly pushing for the best of them, innovating in ways to use AWS servers for its own purposes: running microservices, storing movies, and driving traffic.
AWS, in turn, is improving systems to enable Netflix to handle the enormous workload and is using the acquired knowledge to serve thousands of other corporate customers. AWS prides itself on Netflix as its main customer, and Netflix can quickly improve its services and remain stable with AWS. Regardless of whether Netflix influences the popularity of Prime Video or vice versa.
10 Steps To Implementing Microservices
Step 1: Determine if your application really needs a microservices architecture.
Step 2: If yes, analyze your existing infrastructure.
Step 3: Prepare your team to implement this type of architecture (e.g. make sure to hire a solutions architect if you don’t have one yet).
Step 4. If you are moving from monolithic to microservices architecture, check with the data administrator if they are well informed and understand the task.
Step 5: Select a programming language and platform.
Step 6. Configure the basic architecture using services, containers, and virtual machine templates.
Step 7: If you have a monolithic architecture, split the database into many smaller databases.
Step 8: Implement API Gateways.
Step 9: Track and display what is happening.
Step 10: Perform automated testing.
Stay tuned with Software Focus!