Pros and cons of microservices architecture
· 3 min read
Cons
Microservices bring many problems that do not exist in monolithic applications or are much easier to solve. What challenges will you have?
- Data consistency is difficult to achieve. Distributed transactions result in poor performance. The trade-off is eventual consistency but asynchronous communications is often not easy to accept
- Error handling becomes more complicated because of distributed nature of the system. Failure in one service may require to trigger undo operation in another service
- Synchronous dependencies between services reduce performance and availability. Calling service waits until called service will do its stuff. In case of synchronous communication SLA of the system is multiplication of its micro services (0.99 SLA in service one x 0.99 SLA in service 2 = 0.9801 SLA of the system composed of 2 services)
- Remote calls between services are over network, usually HTTP, so data serialization is required what reduces performance
- Bigger effort must be put into integration tests
- Fault tolerance needs a lot of attention
- Fully automated build and release pipelines are a must because of large number of deployment units. Manual management would be too time-consuming and too error-prone
- Application monitoring, metrics, alerts and self-healing mechanisms must be implemented to successfully manage production environments. It is absolutely counter-productive to manually search logs in tens or hundreds of running application nodes
Pros
Why to take the burden then? When it is beneficial to choose micro-services over monolithic app?
- Divide and conquer principle. System split into smaller highly independent parts is easier to manage and maintain. It is like splitting large complicated problem into many smaller and easier problems
- Teams can be smaller and work more independently. Ownership is bigger because teams feel responsible for their parts. In large monolithic app responsibility is often diffused
- Failures affect smaller parts of the system, other components may be still functional
- Each system part can be planned, developed and deployed quite independenty.
- Different parts of the system may use different technology what allows to update technology stack more often and use different tools for different problems
- Each part of the system can scale independently. It is easier to identify bottlenecks
- With mature dev ops culture it is easy to spin up a new service and provision new computing resources. It is often much more effective and less risky than modifying existing service
- Microservices can be a medicine pill for tired teams. Sometimes teams just need to start from the scratch, leave old buggy system aside for a while and do something smaller that they can be proud of and have fun with
Summary
Microservices are technically harder to develop but in some situations it pays off to take that extra effort. This architecture would be a more natural direction for larger organizations with proven business model and mature teams who are committed to devops culture. For smaller products and start-ups which are still discovering their business model the extra burden brought with microservices may not help but be counter-productive.