Introducing microservices

Microservices, which are a variation of SOA, have become more and more appealing. Many projects have embraced this architecture, and it's not difficult to understand why. With the constant increase in demand for information, applications become more complex, especially with more information being transferred from new data sources to new data visualization devices.

New communication technologies have emerged, social communities spring up like mushrooms, and people expect an application to be able to merge into today's cyber lifestyle.

Microservices come to the rescue by defining a simple strategy: break every complex service into a small, simpler service that is aiming for common functionality. The idea is that services should be small and lightweight - so small that they can be easily maintained, developed, and tested, and so lightweight that they can be responsive and scale more easily:

Example of a simple microservices architecture

The preceding diagram is an example of an application that has been split into small microservices (marked as green and blue), with one for the frontend interface, another one for the API, and one just for authentication.

The idea is to decompose the business logic into small and reusable parts, easily understandable in separate chunks, enabling parallel development by different teams or groups. This way, people can develop parts without being worried about breaking an other's code. Each part should be considered a black box to other parts.

It is only important that communication is well-described. It's common for microservices to communicate over HTTP and use JSON as the data format. There are other formats available, such as XML, but they have fallen into desuetude. It's also common to use AMQP as an inter-service communication, but usually not as a public API service.

To summarize, there are several advantages of using this architecture:

  • Maintenance: Services, when separate, become easier to develop, test, and deploy because they should be simpler and small
  • Design enforcement: A proper and good design is enforced on the application being developed
  • Knowledge encapsulation: Services will have specific objectives, such as delivering emails, which will lead to service re-usage and knowledge about specific tasks being grouped together in services
  • Replaceable: Services become easier to swap because their functionality and communication is well-known
  • Technology agnostic: Each service can be developed using the best tools and languages to build it correctly
  • Performant: Services are small and lightweight, and, as mentioned previously, use the best tools available
  • Upgradable: Services should be interchangeable and upgradable separately
  • Productivity: When complexity starts to grow, productivity will be better than in a monolith application

There are also costs associated with this architecture, namely:

  • Dependencies: Because of this architecture being technology agnostic, different dependencies for different services may arise
  • Complexity: For small applications, the bootstrap complexity is bigger compared to the monolith
  • End-to-end testing: It becomes more complex to test the application from end to end as the number of services to inter-connect is definitely bigger than in a monolith application
Variation in productivity as complexity grows for both monolith and microservices architecture

The graph is not to be taken very seriously; it's just an approximation of the difference between monolith and microservice architectures. In the beginning, when complexity was just beginning, productivity for microservices was poor as the architecture bootstrap demanded more work and thought.

As complexity started to increase, monolith applications became more difficult to manage and productivity began to decrease. On the other hand, as the microservices architecture started to separate services, productivity increased as the bootstrap already passed and each service was easier to manage.

Some may argue that microservices productivity will not grow as complexity will eventually also hit every service, but that's not true if a team follows the number one rule: if the complexity of a service is too much, split the service into smaller ones.

This architecture design brings long-term advantages if used correctly and across several applications. Services can be reused, which can potentially lead to more intensive usage, which will eventually lead to a more resilient and better-tested service.

Also, future applications can bootstrap faster if a development team has already bootstrapped one before. Previous services can also be integrated, which might lead to gaining an initial application testbed faster.

Using a microservices approach also helps to eliminate any long-term commitment to a technology stack. In the near future, when a team feels the need to change the stack, they can start new services using the new stack, and upgrade the old services one by one if they want to, without compromising the entire application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset