Blog

Microservices Architecture — When to Use Them?

A senior web developer once told me, “Whenever you can use microservices architecture — use it.”

Since microservices were totally new to me, I couldn’t help but wonder about his enthusiasm for microservices.

Now, after months of using microservices, I understand what he meant. And yet, many developers still decide not to use it.

In this post, I will provide you with some basic facts about microservices, including the pros and cons which make this kind of architecture suitable for certain projects and not as much for others. Hopefully, this will help you decide whether your current situation calls for the use of the microservices architecture.

What are Microservices?

Since there is no formal definition of microservice architecture, we can describe it as method of developing software systems and applications utilizing independent, small, modular and loosely associated services.

Communication between these independent services that run their own processes is achieved via a lightweight but well-defined mechanism. The specific mechanism will depend on application requirements although the HTTP/REST and JSON combination has become the weapon of choice for many developers.

Wide usage of Microservices

In recent years, we have seen microservices grow in popularity across the board.

Many large-scale applications evolved from monolithic to microservices architecture. Some of them are truly household names, such as Amazon, Netflix, eBay, PayPal, Twitter and Soundcloud, just to name a few.

Netflix is a great example as it went from monolithic to microservices — receiving more than a billion calls to its API on a daily basis, from various devices (around 800 different types) . Every API call received prompts on average five additional calls to the backend service.

Amazon and eBay underwent a similar transition due to the growing requirements of an ever-expanding user base.

Why you should use Microservices

Like anything else, microservices have pros and cons and whether or not you should use it depends on the specific requirements you are dealing with.

Benefits of using microservices include the following:

  • Each microservice can be developed independently
  • A microservice can be deployed independently
  • Different languages can be used to write different services
  • Simple integration
  • Business capabilities are used to guide the code
  • A microservice doesn’t require a big team to develop
  • It is possible to change and redeploy only the related service instead of modifying and redeploying the entire application
  • Easy adoption and application of new technologies
  • Fault isolation — a fail of one microservices will not cause fails of other services (whereas one fault on a monolith application can put the entire system in danger)
  • Faster, automatic deployment
  • Easy to understand and modify for developers, enabling new team members to start contributing early
  • Microservices are easily scaled and integrated with third-party services

Why microservices may not be the solution for you

Like always, there are cases in which the use of microservices may not be the best idea. In order to avoid using microservices in cases when that kind of an architecture isn’t suitable for your project, here is a list of cons that you should consider before making the wrong decision.

  • Distributed deployment can result in more complex and tiresome testing
  • Information barriers can appear as the number of microservices increases
  • The architecture adds complexity (mitigating fault tolerance, dealing with load balancing and network latency)
  • As new services are introduced, integration efforts and product management can get complex
  • Possibility of different teams doing the same thing due to a distributed system
  • Implementing communication between different services can require additional work
  • Cross-service use cases without distributed transactions require a lot of effort and elaborate communication when being handled
  • Possibility of duplicate code on multiple services
  • Possible increase in memory consumption

Conclusion

Every project and every system has different requirements and there is no formal pattern for deciding if you should go with microservice architecture or not. You should gather all requirements and do serious research to find out if microservices can meet your needs.

Whatever you decide, keep in mind that choosing microservices in the right circumstances can really make your life easier and give you a lot of benefits. That being said, be careful since using microservices in unsuitable situations can be costly.