avatarDineshchandgr - A Top writer in Technology

Summary

The provided content offers an in-depth exploration of Microservices architecture, contrasting it with Monolithic architecture, detailing its design patterns, and discussing its advantages and drawbacks.

Abstract

The article "Do you know about Microservices and their Design Patterns?" delves into the Microservices architectural style, emphasizing its modular approach where individual services collaborate through synchronous and asynchronous communication methods. It highlights the properties of Microservices, such as independent deployability, scalability, and resilience, and contrasts them with the tightly coupled, monolithic application structure. The piece further examines the transition of Netflix from a monolithic to a microservices architecture, showcasing the benefits of horizontal scaling and fault tolerance. It categorizes Microservices design patterns into decomposition, integration, database, observability, and cross-cutting types, illustrating their role in addressing challenges inherent to distributed systems. The author also outlines the advantages of Microservices, including faster time to market and improved fault isolation, while acknowledging the complexity and resource overhead they introduce. The article concludes by summarizing the key points and inviting readers to explore related topics through the author's other articles.

Opinions

  • The author posits that Microservices architecture is superior to Monolithic architecture in terms of scalability, maintainability, and time to market.
  • Microservices are presented as a solution to the challenges faced by Netflix's infrastructure, suggesting that large, complex applications can significantly benefit from this architectural style.
  • The article suggests that understanding and applying Microservices design patterns is crucial for designing robust and scalable systems.
  • There is an emphasis on the importance of observability patterns for effective monitoring and telemetry in Microservices architectures.
  • The author implies that while Microservices offer numerous benefits, they also introduce complexity in terms of communication, testing, and deployment, which must be carefully managed.
  • The author encourages further learning on Microservices communication, frameworks, configuration management, and distributed transaction management, indicating these as key areas of expertise for developers working with Microservices.

Do you know about Microservices and their Design Patterns?

Image Source: https://taazaa.com/wp-content/uploads/2021/06/microser4vices-1536x864-1.webp

Hello everyone. In this article, we are going to see about Microservice Architecture and how it is different from a Monolithic application. Then we are going to see what are Microservices Design Patterns and the different types. We will then see about the advantages and drawbacks of Microservices architecture to conclude this article. Let’s get started

What are Microservices?

Microservices is an architectural style for developing a software application that runs as individual services which communicate with each other through the following ways

  1. Synchronous communication using API calls
  2. Asynchronous communication through Publish and Subscribe/event-based mechanism — i.e using Message Queues

These microservices possess the following properties

  • Independently deployable
  • Highly scalable to loads
  • Can be developed using multiple programming languages — i.e polyglot
  • Loosely coupled
  • Organized around the business domain
  • Owned by small and self-contained teams
  • Highly maintainable and testable
  • Continuous Delivery through automated CICD pipelines and faster time to market
  • Resiliency from failures

Using microservice architecture, we can enable the rapid development and delivery of large complex applications i.e time-to-market

Monolith vs Microservice

Image Source: https://www.openlegacy.com/hubfs/Picture1.webp

In traditional monolithic architecture, the entire application is tightly coupled into a single codebase making it tightly coupled. There will be different layers like presentation, business logic, and Database persistence in this single codebase connected to a single database. This application is built as a single fat jar that contains the class files and all the required dependencies to run it.

While the Monolithic application is very easy to build, test, and deploy, it faces various challenges like tight coupling and scalability. The individual modules cannot be scaled separately on load and hence we need to scale the entire application again using a technique called Vertical Scaling. The Monolith application is also the single point of failure.

In 2009 Netflix faced a lot of infrastructure issues as it could not keep up with the demand for its rapidly growing video streaming services. From then Netflix decided to migrate its infrastructure from its private data centers to the AWS cloud and replaced its monolithic architecture with a microservices architecture.

They were the early pioneer in transitioning from a monolith architecture to a microservices architecture. They have even open-sourced their own frameworks and tools used to build the microservices, which are famously called Netflix OSS Stack and later renamed to Spring Cloud Netflix.

The microservice architecture, the modern application development methodology, consists of smaller running services that are developed based on the domain. These services have their own database or schema and will contain only the relevant domain data.

Image Source: https://microservices.io/i/Microservice_Architecture.png

As seen in the diagram above, the microservices are segregated based on the business domain i.e Account Service, Inventory Service, Shipping Service, etc which connect to their own database. These services can also connect to each other either synchronously or asynchronously to get any needed data.

These services are deployed as independent small jar files in their own machine and deployed independently unlike a Monolithic application. The deployment can be done in an on-premise server, cloud server, or docker container.

This architecture is independently scalable using a technique called Horizontal Scaling i.e only scaling the services that have higher loads. Moreover, these services are fault-tolerant and resilient and do not have a single point of failure. Even if the Inventory service and Shipping services are down, the users can still check their accounts using the account service

Microservices design patterns

The microservices architecture has a lot of readily available different design patterns that can be used for different use cases.

Image Source: https://microservices.io/i/PatternsRelatedToMicroservices.jpg

Microservices are independent, loosely coupled, and follow the distributed system architecture where each of the services does a single responsibility. There are going to be a lot of challenges in this type of architecture ranging from a communication failure, distributed transaction rollback, externalizing the configuration, centralized logging, etc.

These design challenges are addressed in the form of solutions to them called Microservices Design Patterns. There are a lot of design patterns for microservices as shown in the diagram below. If one can have exposure to all the important patterns, it will be very helpful for designing a microservices architecture.

The Microservices design patterns can be generally grouped into the following types

  1. Decomposition Patterns
  2. Integration Patterns
  3. Database Design Patterns
  4. Observability Design Patterns
  5. Cross-Cutting Design Patterns
Image Source: https://miro.readmedium.com/max/567/1*CKSVv4WkS8Okx572rX45HA.png

1. Decomposition patterns

The Decomposition Pattern is very useful if we need to break down a monolithic application into smaller microservices. These patterns provide suggestions on how to do the decomposition logically. There are different types of these patterns and the important ones to know the area.

a. Decompose by Business Capability

b. Decompose by Subdomain

c. Decompose by Strangler pattern

2. Integration Design Patterns

The Integration design patterns are used to handle the communication between different microservices and also how to obtain the response across services and send it to the client while maintaining high performance. The important Integration patterns are

a. API Gateway pattern

b. Aggregator pattern

c. Proxy pattern

d. Chained Microservice pattern

3. Database Design Patterns

The Database Design Patterns help us to design the database for the microservices architecture like using a single shared database or separate database for each microservices, having separate databases for read and write operations, distributed transaction management across microservices, and so on. These following database design patterns are very important as designing the database can make or break the application

a. Database Per Service Pattern

b. Shared Database per Service pattern

c. Command and Query Responsibility Segregation (CQRS) Pattern

d. Event Sourcing

e. Saga Pattern

4. Observability Patterns

Observability patterns are very critical to design the microservices for proper monitoring and telemetry i.e centralized logging, distributed tracing, performance metrics, Health check of the microservice instances, and so on. The important patterns are

a. Log Aggregation Pattern

b. Performance Metrics

c. Distributed Tracing

d. Health Check

5. Cross-Cutting Concern Design Patterns

The Cross Cutting patterns are used to deal with how the microservices discover each other, how to externalize the microservices configuration, how to handle service failure using a Circuit Breaker, and how to deploy the microservices. The important patterns are

a. External Configuration Pattern

b. Service Discovery Pattern

c. Circuit Breaker Pattern

d. Blue Green Deployment Pattern

Advantages of Microservices

  1. Microservices follow the single responsibility principle.
  2. Better compliance and data security.
  3. Self-contained and independently deployable
  4. Dynamic scaling and cheaper scaling cost when compared to Monolith
  5. Quicker time to market
  6. We can use multiple programming languages and frameworks for every microservice

7. More resilient applications and improved fault isolation.

8. Readmade availability of a wide range of design patterns

Drawbacks of Microservices

The Microservices architecture comes with its own drawbacks as follows

  1. Increased complexity of communication between the services
  2. Higher chances of communication failure
  3. Complicated rollback of a distributed transaction
  4. More resources and overhead
  5. Difficult to test and debug
  6. Maintaining multiple smaller services is complicated
  7. Complex deployment

Summary

In this article, we saw about Microservice Architecture and how it is different from a Monolithic application. Then we looked at what are Microservices Design Patterns and the different types. We also saw the advantages and drawbacks of Microservices architecture to conclude this article.

Hope this article was useful to you and thanks for reading it!!!

If you like to get more updates from me, 
please follow me on Medium and subscribe to the email alerts.

If you are considering buying a medium membership, 
please buy through my referral link

Please go through my related articles

Technology
Software Engineering
Software Development
Microservices
Programming
Recommended from ReadMedium