Design Patterns
Implementing the principles mentioned on the previous page comes with various challenges. Let's discuss these problems and their solutions.
Decomposition Patterns
1. By Business Capability
Problem: Microservices are concerned with loosely coupling services by applying the single responsibility principle. However, breaking down an application into smaller pieces should be done logically. How do we decompose an application based on business capabilities?
Solution: One strategy is to decompose based on business capabilities. A business capability is something a business does to create value. The set of capabilities for a specific business depends on the type of business. For example, the capabilities of an insurance company usually include sales, marketing, underwriting, claims processing, billing, compliance, etc.
2. By Subdomain
Problem: Decomposing an application based on business capabilities might be a good start, but it won't be easy, and you might encounter "God Classes." These classes would be shared across multiple services. For instance, an Order class might be used in Order Management, Order Taking, Order Delivery, etc. How do we decompose these?
Solution: Domain-Driven Design (DDD) comes to the rescue to solve the "God Classes" problem. DDD uses the concepts of subdomains and bounded context to address this issue. To solve this, subdomains and bounded contexts should be defined by analyzing and understanding the business and organizational structure. Each microservice will then be developed around a bounded context.
Identifying subdomains is not an easy task. It requires a deep understanding of the business. Similar to business capabilities, subdomains are identified by analyzing the business and organizational structure, determining different areas of expertise.
3. Strangler Pattern
Problem: The design patterns discussed so far were for decomposing applications from scratch, but most of the work involves large, monolithic applications. Applying all the mentioned design patterns to them, live and in production, might be challenging.
Solution: The Strangler Pattern is a design pattern that involves gradually transforming the monolithic architecture into a microservices architecture by selecting and converting one functionality at a time. Monolithic services and microservices coexist for a while, and as microservices become stable over time, the services in the monolithic application are strangled and removed. During this transformation, new requirements arising from business needs are also addressed on the microservices architecture.