{"id":288,"date":"2022-02-21T15:59:01","date_gmt":"2022-02-21T15:59:01","guid":{"rendered":"https:\/\/liangqi.org\/?p=288"},"modified":"2022-02-21T16:28:26","modified_gmt":"2022-02-21T16:28:26","slug":"domain-driven-design","status":"publish","type":"post","link":"https:\/\/liangqi.org\/?p=288","title":{"rendered":"Domain Driven Design"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.geeksforgeeks.org\/domain-driven-design-ddd\/\">https:\/\/www.geeksforgeeks.org\/domain-driven-design-ddd\/<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-domain\">What is Domain?<\/h2>\n\n\n\n<p>The word <code>domain<\/code> used in context of software development refers to <code>business<\/code>. domain logic == business logic. <\/p>\n\n\n\n<p>When we are developing software our focus should not be primarily on technology, rather it should be primarily on <code>business<\/code> (<code>domain<\/code>).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"component\">Component<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"entity\">Entity<\/h3>\n\n\n\n<p>The instance of entity has a global identity and keeps same identify throughout lifespan. Identity never changes. It generally persisted as a row in DB and consists of value objects. <\/p>\n\n\n\n<p>Can we say one entity is one business object?<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"value-object\">Value Object<\/h3>\n\n\n\n<p>Value Object has no identify. User is an entity and address is a value object. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"services\">Services<\/h3>\n\n\n\n<p>Service is a stateless class. Services is neither related to an entity nor vlaue objects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"aggregates\">Aggregates<\/h3>\n\n\n\n<p>An aggregates is a collection of entities and values which come under a single transaction boundary (??) Aggregates has a root entity called aggregate roots. The root entity governs lifetimes of other entities in aggregates.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"528\" height=\"640\" src=\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/02\/image-10.png\" alt=\"\" class=\"wp-image-289\" srcset=\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/02\/image-10.png 528w, https:\/\/liangqi.org\/wp-content\/uploads\/2022\/02\/image-10-248x300.png 248w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/figure>\n\n\n\n<p>User and Order are root entity. when they got deleted no use for other entities.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"factories-and-repositories\">Factories and Repositories<\/h3>\n\n\n\n<p>We should always create repository per aggregate root but not for all entities. For example we have UserRepo but not AddressRepo.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rules-micro-service-patterns-chapter-5\">Rules (Micro Service Patterns, Chapter 5)<\/h2>\n\n\n\n<p>Rule # 1 Reference only the aggregate root<\/p>\n\n\n\n<p>Rule # 2 Inter Aggregate reference must use Primary Keys<\/p>\n\n\n\n<p>Rule # 3 One transaction creates or update one aggregate. Like we can put User and Order in one DB transaction but we should not do that. This is really good for microservice architecture. Different aggregates may use different storage like  NoSQL for User and MySQL for Order.<\/p>\n\n\n\n<p>The Z company doesn&#8217;t flow the Rule # 3, everything is in one transaction which makes it very hard to decompose.<\/p>\n\n\n\n<p>The aggregate boundaries are not set in stones.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/www.geeksforgeeks.org\/domain-driven-design-ddd\/ What is Domain? The word domain used in context of software development refers to business. domain logic == business logic. When we are developing software our focus should not be primarily on technology, rather it should be primarily on business (domain). Component Entity The instance of entity has a global identity and keeps same identify throughout lifespan. Identity never changes. It generally persisted as a row in DB and consists of value objects. Can we say one entity is one business object? Value Object Value Object has no identify. User is an entity and address is a value object. Services Service is a stateless class. Services is neither related to an entity nor vlaue objects. Aggregates An aggregates is a collection of entities and values which come under a single transaction boundary (??) Aggregates has a root entity called aggregate roots. The root entity governs lifetimes of other entities in aggregates. User and Order are root entity. when they got deleted no use for other entities. Factories and Repositories We should always create repository per aggregate root but not for all entities. For example we have UserRepo but not AddressRepo. Rules (Micro Service Patterns, Chapter 5) Rule # 1 Reference only the aggregate root Rule # 2 Inter Aggregate reference must use Primary Keys Rule # 3 One transaction creates or update one aggregate. Like we can put User and Order in one DB transaction but we should not do that. This is really good for microservice architecture. Different aggregates may use different storage like NoSQL for User and MySQL for Order. The Z company doesn&#8217;t flow the Rule # 3, everything is in one transaction which makes it very hard to decompose. The aggregate boundaries are not set in stones.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,16],"tags":[],"class_list":["post-288","post","type-post","status-publish","format-standard","hentry","category-design","category-16"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Domain Driven Design - Liangqi\u2018s Technical Journey<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/liangqi.org\/?p=288\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Domain Driven Design - Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"og:description\" content=\"https:\/\/www.geeksforgeeks.org\/domain-driven-design-ddd\/ What is Domain? The word domain used in context of software development refers to business. domain logic == business logic. When we are developing software our focus should not be primarily on technology, rather it should be primarily on business (domain). Component Entity The instance of entity has a global identity and keeps same identify throughout lifespan. Identity never changes. It generally persisted as a row in DB and consists of value objects. Can we say one entity is one business object? Value Object Value Object has no identify. User is an entity and address is a value object. Services Service is a stateless class. Services is neither related to an entity nor vlaue objects. Aggregates An aggregates is a collection of entities and values which come under a single transaction boundary (??) Aggregates has a root entity called aggregate roots. The root entity governs lifetimes of other entities in aggregates. User and Order are root entity. when they got deleted no use for other entities. Factories and Repositories We should always create repository per aggregate root but not for all entities. For example we have UserRepo but not AddressRepo. Rules (Micro Service Patterns, Chapter 5) Rule # 1 Reference only the aggregate root Rule # 2 Inter Aggregate reference must use Primary Keys Rule # 3 One transaction creates or update one aggregate. Like we can put User and Order in one DB transaction but we should not do that. This is really good for microservice architecture. Different aggregates may use different storage like NoSQL for User and MySQL for Order. The Z company doesn&#8217;t flow the Rule # 3, everything is in one transaction which makes it very hard to decompose. The aggregate boundaries are not set in stones.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/liangqi.org\/?p=288\" \/>\n<meta property=\"og:site_name\" content=\"Liangqi\u2018s Technical Journey\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-21T15:59:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-21T16:28:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/02\/image-10.png\" \/>\n<meta name=\"author\" content=\"liangqi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"liangqi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/liangqi.org\/?p=288#article\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/?p=288\"},\"author\":{\"name\":\"liangqi\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"headline\":\"Domain Driven Design\",\"datePublished\":\"2022-02-21T15:59:01+00:00\",\"dateModified\":\"2022-02-21T16:28:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/liangqi.org\/?p=288\"},\"wordCount\":285,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"articleSection\":[\"Design\",\"\u6280\u672f\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/liangqi.org\/?p=288#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/liangqi.org\/?p=288\",\"url\":\"https:\/\/liangqi.org\/?p=288\",\"name\":\"Domain Driven Design - Liangqi\u2018s Technical Journey\",\"isPartOf\":{\"@id\":\"https:\/\/liangqi.org\/#website\"},\"datePublished\":\"2022-02-21T15:59:01+00:00\",\"dateModified\":\"2022-02-21T16:28:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/liangqi.org\/?p=288#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/liangqi.org\/?p=288\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/liangqi.org\/?p=288#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/liangqi.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Domain Driven Design\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/liangqi.org\/#website\",\"url\":\"https:\/\/liangqi.org\/\",\"name\":\"Liangqi\u2018s Technical Journey\",\"description\":\"Chasing Excellence; Enjoy life.\",\"publisher\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/liangqi.org\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3\",\"name\":\"liangqi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"contentUrl\":\"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg\",\"width\":2560,\"height\":1920,\"caption\":\"liangqi\"},\"logo\":{\"@id\":\"https:\/\/liangqi.org\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/liangqi.org\"],\"url\":\"https:\/\/liangqi.org\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Domain Driven Design - Liangqi\u2018s Technical Journey","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/liangqi.org\/?p=288","og_locale":"en_US","og_type":"article","og_title":"Domain Driven Design - Liangqi\u2018s Technical Journey","og_description":"https:\/\/www.geeksforgeeks.org\/domain-driven-design-ddd\/ What is Domain? The word domain used in context of software development refers to business. domain logic == business logic. When we are developing software our focus should not be primarily on technology, rather it should be primarily on business (domain). Component Entity The instance of entity has a global identity and keeps same identify throughout lifespan. Identity never changes. It generally persisted as a row in DB and consists of value objects. Can we say one entity is one business object? Value Object Value Object has no identify. User is an entity and address is a value object. Services Service is a stateless class. Services is neither related to an entity nor vlaue objects. Aggregates An aggregates is a collection of entities and values which come under a single transaction boundary (??) Aggregates has a root entity called aggregate roots. The root entity governs lifetimes of other entities in aggregates. User and Order are root entity. when they got deleted no use for other entities. Factories and Repositories We should always create repository per aggregate root but not for all entities. For example we have UserRepo but not AddressRepo. Rules (Micro Service Patterns, Chapter 5) Rule # 1 Reference only the aggregate root Rule # 2 Inter Aggregate reference must use Primary Keys Rule # 3 One transaction creates or update one aggregate. Like we can put User and Order in one DB transaction but we should not do that. This is really good for microservice architecture. Different aggregates may use different storage like NoSQL for User and MySQL for Order. The Z company doesn&#8217;t flow the Rule # 3, everything is in one transaction which makes it very hard to decompose. The aggregate boundaries are not set in stones.","og_url":"https:\/\/liangqi.org\/?p=288","og_site_name":"Liangqi\u2018s Technical Journey","article_published_time":"2022-02-21T15:59:01+00:00","article_modified_time":"2022-02-21T16:28:26+00:00","og_image":[{"url":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/02\/image-10.png"}],"author":"liangqi","twitter_card":"summary_large_image","twitter_misc":{"Written by":"liangqi","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/liangqi.org\/?p=288#article","isPartOf":{"@id":"https:\/\/liangqi.org\/?p=288"},"author":{"name":"liangqi","@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"headline":"Domain Driven Design","datePublished":"2022-02-21T15:59:01+00:00","dateModified":"2022-02-21T16:28:26+00:00","mainEntityOfPage":{"@id":"https:\/\/liangqi.org\/?p=288"},"wordCount":285,"commentCount":0,"publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"articleSection":["Design","\u6280\u672f"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/liangqi.org\/?p=288#respond"]}]},{"@type":"WebPage","@id":"https:\/\/liangqi.org\/?p=288","url":"https:\/\/liangqi.org\/?p=288","name":"Domain Driven Design - Liangqi\u2018s Technical Journey","isPartOf":{"@id":"https:\/\/liangqi.org\/#website"},"datePublished":"2022-02-21T15:59:01+00:00","dateModified":"2022-02-21T16:28:26+00:00","breadcrumb":{"@id":"https:\/\/liangqi.org\/?p=288#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/liangqi.org\/?p=288"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/liangqi.org\/?p=288#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/liangqi.org\/"},{"@type":"ListItem","position":2,"name":"Domain Driven Design"}]},{"@type":"WebSite","@id":"https:\/\/liangqi.org\/#website","url":"https:\/\/liangqi.org\/","name":"Liangqi\u2018s Technical Journey","description":"Chasing Excellence; Enjoy life.","publisher":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/liangqi.org\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/liangqi.org\/#\/schema\/person\/105c89d9b783fda67b62e3ce113d6cd3","name":"liangqi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/","url":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","contentUrl":"https:\/\/liangqi.org\/wp-content\/uploads\/2022\/01\/P1100089-3-scaled.jpg","width":2560,"height":1920,"caption":"liangqi"},"logo":{"@id":"https:\/\/liangqi.org\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/liangqi.org"],"url":"https:\/\/liangqi.org\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288"}],"version-history":[{"count":4,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions"}],"predecessor-version":[{"id":295,"href":"https:\/\/liangqi.org\/index.php?rest_route=\/wp\/v2\/posts\/288\/revisions\/295"}],"wp:attachment":[{"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/liangqi.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}