Microservices Architecture, advantages and disadvantages

In this article I will explain the advantages and disadvantages of the microservices. Why choosing the microservices architecture. Which technologies to use with the microservices. Which design patterns to use with the microservices.

Content:

  • Microservices vs Monolith architecture
  • Advantages and disadvantages
  • Technologies
  • Design patterns

Find all the videos about Microservices Architecture in the following playlist.

And you can find all the related code in this repository.

This is the introduction article where I will build a microservicies architecture for a webpage, how to create microservices with Spring Boot and Spring Cloud, and how to handle the microservices with Docker and Kubernetes.

Microservices vs Monolith architecture

Let’s start by the use case, by a website of a bookstore. Where users can search for books or authors. The webpage will display the prices. I can add items to a basket and buy them. I won’t talk about the frontend part, just the backend. Then, the emails will be sent to the users, to indicate the order ID, the shipping information and the bill.

Requests to a single server
Requests to a single server

And now, I have to handle the user’s request, the user’s visits to my website. One of the main requirements of having a website nowadays, is to have it available 24 hours a day 7 days a week and all the days of the year. But it must be available even if the number of users visiting my website increases. The problem, when the amount of visits increases significantly, is that I must adapt my resources, my hardware resources, to accept gracefully this load. But if the website doesn’t accept this load, it will become unavailable.

Requests saturation to a single server
Requests saturation to a single server

To avoid this, the modern website architectures tend to have multiple instances of the same application. But what happens if I have multiple instances of a big fat application? It will need a lot of time to start up. It will need a lot of hardware resources. And from my experience, I don’t think the application will correctly work with multiple instances of itself. Here came the area of microservices. Instead of having one big fat application, I will split it into multiple small applications: to search the book’s information; to calculate the prices; to save the orders; to send the emails; and etc. But all of those microservices will need an orchestration.

Requests dispatching in microservices architecture
Requests dispatching in microservices architecture

Advantages and disavantages

When to call each one, handle permissions, and build a pretty response for the user. For that, i will need some kind of router, a public entry, a public backend. Will this architecture be better than the previous one? There are some advantages and some disadvantages. Each microservices will be redundant, will be duplicated, to ensure the continuity of the service if some error occurs. But having the same application splitted in several microservices, will cause duplications. I have to define the same object in multiple services to allow the correct reception. I have to define the object in the book service and in the router, to be correctly received. Having small services, i can run multiple instances without consuming a lot of hardware resources. This will help me to be more tolerant over failovers. But i have to build more complex architectures to ensure the stateless of the requests, to manage the IP changes, and more. And finally, i split the services by features. I separate the responsibilities. This way, i can even have specialized teams to handle each microservice. But to respond to a single request from a user, multiple calls between microservices must be made. That may increase the response time of a request.

Technologies

Now that i have chosen this architecture, I have to choose the technologies. I’m a Java developer with more than 10 years of experience, so I will do it with Java. When talking about web applications in Java, the second thought goes to Spring Boot. A lot of useful tools are available in the Spring Cloud libraries. And each microservers will be running in a Docker container. And to orchestrate all of these, Kubernetes, of course. With all of this, I can have this architecture in any cloud: AWS, GCP, Azur, or even in a traditional server. Kubernetes allows me to run this on any platform.

Which microservices may I need in a bookstore website? As i said, the public router. I will name it backend-user, it’s a backend, it’s an entry point of all the requests. And user, because it’s the entry point of the user request. I may have another application for admin users or for B2B users, which will be backend-admin or backend-b2b. This first microservice will be the only one with public access. Which means that this one will handle most of the security. Then, the internal microservices, the private microservices. To access those microservices, i must go through the backend. Because they are in a private network, unreachable from the outside. For the books information, for the prices, for the orders, emails and more. Every time a new functional need appears, i can add and deploy a new microservice. I don’t need to allocate a new server. Kubernetes will distribute the resources to manage a new servers.

Design Patterns

But to manage all of this, I will need to implement some complicated design patterns. I will focus in this serie of articles on:

Conclusion

The microservices architecture is being one of the most used architecture nowaday. Nevertheless, it needs caution when designing, as I can easily come into a mess of requests going from one microservice to another. Which will lead to increase the response time.

Follow this serie of articles to know which are the question to ask when designing a complete microservices architecture.

Repository


Never Miss Another Tech Innovation

Concrete insights and actionable resources delivered straight to your inbox to boost your developer career.

My New ebook, Best Practices To Create A Backend With Spring Boot 3, is available now.

Best practices to create a backend with Spring Boot 3

One response to “Microservices Architecture, advantages and disadvantages”

  1. […] i said in the introduction article, i want to build a microservice architecture for a bookstore website. I will start with a dummy web […]

    Like

Leave a reply to Build you Spring Boot Microservice with Kubernetes – The Dev World – by Sergio Lema Cancel reply

Discover more from The Dev World - Sergio Lema

Subscribe now to keep reading and get access to the full archive.

Continue reading