What are Microservices exactly and how can you use them to work to your advantage? IT teams are always wanting to build new applications enabling specific functions for the ease of processes or customers. Sometimes, to balance projects, they allow distributed teams to work on focused targets using reusable assets, templates, and best practices. While decentralizing and democratizing application development helps, managing security can be a task for strategizing different Lines of Business (LoBs) and functional business partners.
Enter microservices. They are supposed to be the next great leverage of modern and lucrative businesses. What are they exactly and how can you use them to work to your advantage?
It was a natural course of evolution in the software industry that pushed microservices to the top of the list. Whereas there are scenarios where the more orthodox monolith and service-oriented architecture (SOA) are applicable and more beneficial, for most of the dynamic and fast-reacting business microservices remain the preferred choice.
So, what is wrong with monolith and SOA? The problem behind the traditional multilayered monoliths is that their components are tightly coupled, they depend on each other. Changes are usually expensive, hard to implement, and deploying them to the end-users takes lots of time.
In comparison with a monolith, service-oriented architecture is a milestone step towards flexibility and dynamic. Besides offering better scalability and decoupling, modifications, testing, and deployment are less costly in time and money; however, the components are led by a central, governing module. This can be an advantage or disadvantage, depending on the project.
Microservices are decentralized, the components cooperate and exchange data, but are independent in their tasks. This way, the system is resilient. In case of a failure of one component, in most cases, the others can continue delivering services.
There is no need for a messaging middleware between the components since they use mutually comprehensible APIs, not a specific programming language. Because of that, adapting new or mixing multiple technologies into the project is relatively easy. All of those characteristics make microservices that powerful in their flexibility.
The goal of microservices is creating a harmonious ecosystem of small components, each with well-defined responsibility and light-weight communication.
Individual microservices are a great fit to follow unique - or specific - business use cases. Each microservice can be implemented in any language or framework. Indeed, the only thing that matters is the service’s API.
As a result, the most important thing to decide about your microservices architecture is not how each service will be implemented. Instead, focus on how those services will communicate (synchronous, asynchronous) and what protocol they’ll use to do so (REST, message queues, etc.).
Within each service, there is an API gateway, the business logic of the service, and the service’s datastore. Also, most architectures include some load balancing solution that knows when and how to spin up a new instance of the service in cases of high request volume. The microservice is a self-contained mini-application that handles only one business case.
Microservice implementation will be different for every company, but the challenge of making the switch is worth the reward.
Most often the best way to implement microservices is to gradually separate parts of your application into new services. As a result, developers can work in parallel on separate business concerns, making your application more resilient and less reliant on proprietary solutions since components can easily be swapped out.
Before embarking on your first microservice, consider whether the architecture can contribute to the business. So where do you begin…
Scalability – Arguably the biggest benefit. Acquiring or limiting your number of resources to critical components like computer power, memory, servers and generally adjusting to the business' growth is driven by analytics which will quickly identify priority candidates for scaling up.
High availability – The servers remain responsive and users are bound to receive answers promptly.
Reliability – Microservices are less prone to failure in comparison to other architectures.
Flexibility – Modifications are fairly easy and cost-effective to implement and can easily merge into the existing product. The impact of changes on the other components is often minimal.
Direct communication between components is achieved via language-agnostic API — The most popular means are RESTful APIs and HTTP protocol, which are fast and efficient. Exchanging data is achieved via light-weight formats like JSON.
Fast Continous Deployment — Instantiating the new version of a microservice and retiring the old version is fast since there are few dependencies between components.
Fast development — Understanding and maintaining a set of smaller projects, each with well-defined responsibilities is less demanding, making the plunge into the project for the new team members smoother. Granularity can also boost productivity, although, productivity hits a wall when a certain number of services are reached.
Team autonomy — Well-separated components are divided between independent teams.
Effective human communication — Naturally, a microservice team will be relatively small, making communication easy. Often a team is fully responsible for end-to-end development, creating an environment in which most developers thrive.Cons
Following messaging flow – Dealing with complexity is unavoidable, we all know that! When a greater number of components reach a certain threshold, it is hard to follow the flow of calls between them. When data is exchanged and modified through many layers of services, finding bugs can often become cumbersome.
Possible latency – If messaging between the components creates a long chain (eg. data has to go through four services before reaching the client), the calls may accumulate and take more than expected to reach their final destination.
Consistency — The latest updates may not be available immediately. Accessing data storage is a complicated beast and microservices architecture usually requires using various techniques such as sharding (which is dividing data into many databases with possible duplicates). Duplicates may not at all times contain the latest changes leading to a conundrum: Compromise consistency of data over availability?
Transaction safety is hard or impossible to achieve — Delegating data between many receivers can often create undue headaches in tracking down changes made to data.
Used effectively, microservice architectures allow you to scale your application as the number of developers working on your application increases. The key is to build applications without creating a complex, unwieldy beast at the macro level. That means keep tracking each time a new service is added to your system or a new connection between microservices is made.
It also means examining the complexity increase and making sure it is warranted and well understood. Regularly examining the entire application system is critical to keep an interconnected set of microservices working effectively and reliably.
You should consider microservices if:
Microservices will do more harm than good if:
The road to microservices is paved with good intentions. But more than a few teams are jumping on the bandwagon without analyzing their needs first. Microservices are powerful. They should be in your toolbox! Just make sure you consider the tradeoffs. There’s no substitute for understanding the business drivers of your applications; this is essential to determining the proper architectural approach.
Several providers offer solutions to support microservice architecture. The development process is similar to any other kind of application development. Any IDE of the developer's choice, like Eclipse or IntelliJ, a text editor like the atom (open-source) and any of the version control systems from the client-server model (svn, perforce) or distributed model (Git, Visual Studio Team Service) can be used. To connect the dots and make them work, you should take advantage of more high-level solutions.
For those who seek expedience - who doesn’t like a shortcut? - several new technologies can do the job too. A selection of some of the best breed tools include
Previously published at https://dzone.com/articles/microservices-under-the-microscope
Create your free account to unlock your custom reading experience.