Core Concepts of Microservice Architecture and Its Relationship with Domain‑Driven Design
This article explains the fundamental differences between microservice architecture and traditional SOA, emphasizes the importance of proper service boundaries and DDD‑guided decomposition, and compares transaction‑script (anemic) and rich‑model approaches with code examples to illustrate how domain‑centric design improves microservice implementations.
Microservice architecture has become popular, and this article compares it with traditional SOA, highlighting both similarities (registry, transaction consistency, gateway, logging) and key differences such as service granularity and the importance of proper service boundaries.
It emphasizes that the essence of microservices lies in how services are split; overly coarse‑grained services or “pseudo‑microservices” that only separate business logic without separating data storage lead to coupling and performance issues.
Domain‑Driven Design (DDD) is presented as a practical method for service decomposition, using concepts such as Bounded Context to map business domains to independent services.
The article then contrasts the “transaction script” (anemic model) approach with the “rich model” (active‑record) approach. A Java class example and accompanying SQL pseudo‑code illustrate the anemic style, where business logic is expressed as raw SQL statements:
public class Stock { private String spuId; private String skuId; private int stockNum; private int orderStockNum; } count = select stocknum from stock where spuId=xx and skuid=xx; if (count > num) { update stock set stocknum=stocknum-num, orderstocknum=orderstocknum+num where skuId=xx and spuId=xx; } else { //库存不足,扣减失败 } insert stock_log set xx=xx, date= new Date();
In the rich model, business behavior is encapsulated within domain objects (e.g., an Inventory entity) and invoked through application services, reducing coupling and aligning with OOP principles, though it introduces concurrency challenges that can be mitigated with event‑driven architectures.
Overall, the piece argues that successful microservice adoption requires careful boundary definition, DDD‑guided decomposition, and a shift from procedural scripts to domain‑centric rich models.
Architect
Professional architect sharing high‑quality architecture insights. Topics include high‑availability, high‑performance, high‑stability architectures, big data, machine learning, Java, system and distributed architecture, AI, and practical large‑scale architecture case studies. Open to ideas‑driven architects who enjoy sharing and learning.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.