DDD Lite: simplified version of DDD Domain Driven Design microservice

Time:2021-4-21

DDD Lite

Everyone should have heard of the name of DDD domain driver design, but few of the actual projects are completely implemented in DDD. Because DDD concepts are complex, such as domain, sub domain, core sub domain, general sub domain, entity, value object, domain service, application service, domain event, context and so on, people are directly confused. When corresponding to the actual business model, it is difficult for developers to reach an agreement.

Because DDD was originally designed as a solution for complex software, but most of our applications are not so complex. It’s a bit self defeating for a simple application to use such a complex set of concepts. In the era of microservice, the design principle is to divide the context according to the domain, which greatly reduces the complexity of single application. Microservice needs a simple architecture.

Here I propose a lightweight DDD architectureDDD LiteTo make it better fit the micro service.

Hierarchical architecture is widely used in MVC, and DDD also has four tier architecture, five tier architecture, hexagon architecture and other genres. DDD Lite adopts a relatively simple four tier architecture, from top to bottom as follows:

  • Interface
  • Service
  • Model
  • Infrastructure

layered

Interface

Interface layer.

HTTP, RPC and other interfaces are provided for external users. The logic of parameter verification, encoding and decoding are processed in this layer, and the business status code and external data structure are defined in this layer.

Service

Service layer.

Main business logic layer, calling model layer repository interface to realize domain business logic and transaction assembly. A service corresponds to a domain, which refers to the classification of similar business logic. Generally, a micro service has only one or two services, which should not be too many.

Model

Data model layer.

Define the data structure and the repository interface corresponding to the data model, but do not include the specific implementation. Multiple related models constitute the domain. The domain is simplified here, and no longer entangled in the fine-grained concepts such as sub domain, entity and value object. The repository interface is defined around the model, which is free of business logic and can be called by the service layer to facilitate the composition of transactions in the service layer.

Repository pattern

Let’s talk about the repository design pattern separately, which is the top priority of designing a good data model.

Repository mode abstracts the operation of data structure into interface, separates business logic from data access, and adds an abstraction layer.

With the repository interface, dependency becomes abstract from concrete, decouples from DB and other basic layer dependencies, and facilitates the implementation of TDD (Test Driven Development).

Repository interface should be fine-grained, universal enough to reduce business attributes and facilitate reuse.

Infrastructure

Infrastructure layer.

Realize the model layer repository interface, dock dB, MQ and other data persistence, or RPC remote call back-end services.

At the same time, it can also provide a repository fake implementation for service layer unit testing.

summary

There are many methodologies in DDD, most of which have been seen or practiced in project engineering. But the preconditions required by DDD are too ideal, such as what field experts, common language and so on. In the environment of migrant workers’ agile development, constantly changing demands, and 996 acceleration, the preconditions are too illusory to be implemented. Therefore, we do not need to copy everything. We should adjust measures to local conditions, extract the essence and discard the essence, and extract the suitable application framework. DDD Lite simplifies the DDD design mode, which is the author’s summary and Reflection on the theory of DDD combined with practical engineering experience.

DDD Lite architecture is only for personal understanding. If you have any opinions, please exchange them.

Full project code:win5do/go-microservice-demo (github.com)

Reference

DDD hierarchical architecture:https://www.yyang.io/2015/12/31/DDD-and-Layered-Architecture/

DDD Lite architecture proposed by foreign leaders:https://threedots.tech/post/ddd-lite-in-go-introduction/

Domestic tycoons fully follow the go demo designed by DDD, which is slightly cumbersomehttps://github.com/agiledragon/ddd-sample-in-golang

Recommended Today

Download canvas as an image

Download canvas as an image The idea is to convert canvas into Base64 link and download it by simulating the download attribute of a tag // https://stackoverflow.com/questions/18480474/how-to-save-an-image-from-canvas function download(canvas, filename) { var lnk = document.createElement(‘a’), e lnk.download = filename lnk.href = canvas.toDataURL(‘image/png;base64’) if(document.createEvent) { e = document.createEvent(‘MouseEvents’) e.initMouseEvent(‘click’, true, true, window, 0, 0, 0, 0, […]