<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: DevByJESUS</title>
    <description>The latest articles on DEV Community by DevByJESUS (@edgaremmanuel).</description>
    <link>https://dev.to/edgaremmanuel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F623369%2Fa0b3f910-c967-4b3e-80f7-ff1ead1ae1d4.png</url>
      <title>DEV Community: DevByJESUS</title>
      <link>https://dev.to/edgaremmanuel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/edgaremmanuel"/>
    <language>en</language>
    <item>
      <title>Implementing Domain Driven Design - Domain Events ( 2 ) - Publish and Subscribe</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Sat, 29 Aug 2026 12:33:05 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/implementing-domain-driven-design-domain-events-2-publish-and-subscribe-2lgo</link>
      <guid>https://dev.to/edgaremmanuel/implementing-domain-driven-design-domain-events-2-publish-and-subscribe-2lgo</guid>
      <description>&lt;p&gt;We continue talking about domain events, and we will focus of the way to process them from the domain to the outside world ( who is shy here ? 🙈 ) &lt;/p&gt;

&lt;h1&gt;
  
  
  A - The forbidden way ❌
&lt;/h1&gt;

&lt;p&gt;WE KNOW 👀 we are in DDD, so that simple rule is a must to know : &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Avoid exposing the domain model to any kind of middleware messaging infrastructure. Those kinds of components live only in the infrastructure.&lt;/strong&gt; And while the domain model might at times use such infrastructure indirectly, it would never explicitly couple to it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  B - The way to go PUBLISH - SUBSCRIBE ✅
&lt;/h1&gt;

&lt;p&gt;Because we want a decoupling between the domain and the processing of the domain events, the way to go is the &lt;strong&gt;observer design pattern&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;One of the simplest and most effective ways to publish Domain Events without coupling to components outside the domain model is to create a lightweight Observer [Gamma et al.]. For the sake of naming I use Publish- Subscribe, which is acknowledged by [Gamma et al.]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  B - 1 - Publisher 🔊
&lt;/h2&gt;

&lt;p&gt;The publisher of the events created inside the aggregate is a service that notifies all the subscribers and this service lives in a &lt;strong&gt;module(DDD)&lt;/strong&gt; !&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Perhaps the most common use of Domain Events is when an Aggregate creates an Event and publishes it. The publisher resides in a Module of the model, but it doesn’t model some aspect of the domain. Rather, it provides a simple service to Aggregates that need to notify subscribers of Events&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the figure below , we see clearly the role of the Publisher next to the aggregate :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fit5tfeaufz4a6wk0nl9s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fit5tfeaufz4a6wk0nl9s.png" alt="publisher flow with domain events" width="799" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Explanation&lt;/em&gt; : When &lt;strong&gt;publish()&lt;/strong&gt; is executed on &lt;strong&gt;DomainEventPublisher&lt;/strong&gt;, it iterates through all registered subscribers. Invoking subscribedToEventType() on each subscriber allows it to filter out all subscribers not subscribed to the specific Event type. Subscribers answering &lt;strong&gt;DomainEvent.class&lt;/strong&gt; to this filter query will receive all Events. All qualified subscribers are sent the published Event by way of their &lt;strong&gt;handleEvent()&lt;/strong&gt; method. After all subscribers have been either filtered or notified, the publisher completes.&lt;/p&gt;

&lt;h2&gt;
  
  
  B - 1 - Subscribers 🎧
&lt;/h2&gt;

&lt;p&gt;If you have seen correctly the pucture above , you should now understand that subscribers are registered inside &lt;strong&gt;application service&lt;/strong&gt; or VERY SPECIFIC CASES inside &lt;strong&gt;domain services&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What components register subscribers to Domain Events? Generally speaking, Application Services (14), and sometimes Domain Services, will. The subscriber may be any component that is running on the same thread as the Aggregate that publishes the Event, and that can subscribe prior to the Event being published. This means that the subscriber is registered in the method execution path that uses the domain model.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And here is an example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BacklogItemApplicationService&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
 &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;commitBacklogItem&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
   &lt;span class="nc"&gt;Tenant&lt;/span&gt; &lt;span class="n"&gt;aTenant&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
   &lt;span class="nc"&gt;BacklogItemId&lt;/span&gt; &lt;span class="n"&gt;aBacklogItemId&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
   &lt;span class="nc"&gt;SprintId&lt;/span&gt; &lt;span class="n"&gt;aSprintId&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;DomainEventSubscriber&lt;/span&gt; &lt;span class="n"&gt;subscriber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
      &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DomainEventSubscriber&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BacklogItemCommitted&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;@Override&lt;/span&gt;
        &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;handleEvent&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BacklogItemCommitted&lt;/span&gt; &lt;span class="n"&gt;aDomainEvent&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// handle event here ...&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="nd"&gt;@Override&lt;/span&gt;
        &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Class&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BacklogItemCommitted&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;subscribedToEventType&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;BacklogItemCommitted&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
     &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="nc"&gt;DomainEventPublisher&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;instance&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;subscribe&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subscriber&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
   &lt;span class="nc"&gt;BacklogItem&lt;/span&gt; &lt;span class="n"&gt;backlogItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
         &lt;span class="n"&gt;backlogItemRepository&lt;/span&gt;
         &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;backlogItemOfId&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;aTenant&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;aBacklogItemId&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
   &lt;span class="nc"&gt;Sprint&lt;/span&gt; &lt;span class="n"&gt;sprint&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sprintRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sprintOfId&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;aTenant&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;aSprintId&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
   &lt;span class="n"&gt;backlogItem&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;commitTo&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sprint&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The Application Service task coordinator then registers the subscriber with the DomainEventPublisher....What the subscriber does with the Event is not shown in this example. It could send an e-mail about the fact that a BacklogItemCommitted, if that made any sense. It might store the Event in an Event Store. It could forward the Event via a messaging infrastructure.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hope you enjoyed it, See yoouuu in the next one 😊&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwareengineering</category>
      <category>architecture</category>
      <category>ddd</category>
    </item>
    <item>
      <title>Implementing Domain Driven Design - Domain Events ( 1 ) - Definition and Modeling</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Sat, 29 Aug 2026 11:23:18 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/implementing-domain-driven-design-domain-events-1-definition-and-modeling-ggo</link>
      <guid>https://dev.to/edgaremmanuel/implementing-domain-driven-design-domain-events-1-definition-and-modeling-ggo</guid>
      <description>&lt;p&gt;I know it has been a long time, i was finishing some work, Can we talk about &amp;lt;&amp;lt; domain events &amp;gt;&amp;gt; today ? 😄&lt;/p&gt;

&lt;h1&gt;
  
  
  A - What, When, Why ? 🤔
&lt;/h1&gt;

&lt;h2&gt;
  
  
  A - 1 - What is a Domain Event ?
&lt;/h2&gt;

&lt;p&gt;There is no direct definition, we can say that they are the result of  listening to domain experts. And the final point is &lt;strong&gt;something happened and the domain experts want to know it.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A - 2 - When to use Domain Event ?
&lt;/h2&gt;

&lt;p&gt;We have to go for it &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How can we determine if something that happens in the domain is important to the domain experts? As we have discussions with them, we must listen carefully for clues. Consider a few key phrases to listen for when domain experts talk:&lt;br&gt;
• “When . . .”&lt;br&gt;
• “If that happens . . .”&lt;br&gt;
• “Inform me if . . .” and “Notify me if . . .”&lt;br&gt;
• “An occurrence of . . .”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A - 3 - Why use Domain Event ?
&lt;/h2&gt;

&lt;p&gt;Because if something happened in the domain, those who want to know it are not neccessarily in the domain, so we use domain event like a bridge to process the new to others.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This tends to happen when Events must be broadcast to external&lt;br&gt;
services, where the systems in your enterprise have been decoupled and occurrences throughout the domain must be communicated across Bounded Contexts (2). Events like this get published, and subscribers are notified. As such Events are handled by subscribers, they may have far-reaching impact on local and remote Bounded Contexts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  B - Modeling Domain Event ? 🦾
&lt;/h1&gt;

&lt;h2&gt;
  
  
  B - 1 - The Name of the Domain Event
&lt;/h2&gt;

&lt;p&gt;I think we are clean coders 👀 and futhermore we are in domain driven design. So the name should be in the norm of the ubiquitous language. And i totally agree when in the book, it says :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If an Event is the result of executing a command operation on an Aggregate, the name is usually derived from the command that was executed. The command is the cause of the Event, and hence the Event’s name is rightly stated in terms of the command having occurred in the past.....When publishing Events from Aggregates, it is important that the Event name reflect the past nature of the occurrence. It is not occurring now. It occurred previously. The best name to choose is the one that reflects that fact&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  B - 2 - Properties of the Domain Event
&lt;/h2&gt;

&lt;p&gt;Firstly because it is an event : &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For one, we need a timestamp that indicates when the Event occurred.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And for the other properties it all depends on the talk : &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;the team determines what other properties are necessary to&lt;br&gt;
represent a meaningful occurrence of what happened. Consider including whatever would be necessary to trigger the Event again. This normally includes the identity of the Aggregate instance on which it took place, or any Aggregate instances involved. Using this guidance, we might create properties of any parameters that caused the Event, if discussion proves they are useful. It’s also possible that some resulting Aggregate state transition values could be helpful to subscribers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  B - 3 - Domain Event and Aggregate Characteristics
&lt;/h2&gt;

&lt;p&gt;Inside the aggregate as the result of the process, inside the aggregate we can create an event and of course it would contain some properties of the aggregate source: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Events are designed to be created by direct request from clients.&lt;br&gt;
This is done in response to some occurrence that is not the direct result of executing behavior on an instance of an Aggregate in the model. Possibly a user of the system initiates some action that is considered an Event in its own right. When that happens, the Event can be modeled as an Aggregate and retained in its own Repository. Since it represents some past occurrence, its Repository&lt;br&gt;
would not permit its removal. &lt;strong&gt;When Events are modeled in this way, like Aggregates they become part of the model’s structure. Thus, they are not just a record of some past occurrence, although they are that also. The Event is still designed as immutable, but it may be assigned a generated unique identity.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;N.B:&lt;/strong&gt; : &lt;em&gt;An unique identity because there will be times where we have to compare event and here an unique identity is required&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Soooooo 😊 in this article we have clearly define the what, when, and why of a domain events and how the modeling part works !&lt;/p&gt;

&lt;p&gt;See yoouuu in the next one 😊&lt;/p&gt;

</description>
      <category>programming</category>
      <category>architecture</category>
      <category>softwareengineering</category>
      <category>ddd</category>
    </item>
    <item>
      <title>Implementing Domain Driven Design - Services</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Tue, 15 Jul 2025 08:08:29 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/implementing-domain-driven-design-services-bbh</link>
      <guid>https://dev.to/edgaremmanuel/implementing-domain-driven-design-services-bbh</guid>
      <description>&lt;p&gt;We continue our series in the chapter 7 of IDDD which talks about &lt;em&gt;Services&lt;/em&gt; 😁&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. The problem&lt;/strong&gt; ⚠️
&lt;/h2&gt;

&lt;p&gt;In the blue book, it says :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;There are important domain operations that can't find a natural home in an ENTITY or VALUE OBJECT.&lt;/strong&gt; Some of these are intrinsically activities or actions, not things, but since our modeling paradigm is objects, we try to fit them into objects anyway. Now, the more common mistake is to give up too easily on fitting the behavior into an appropriate object, gradually slipping toward procedural programming. But when we force an operation into an object that doesn't fit the object's definition, the object loses its conceptual clarity and becomes hard to understand or refactor. Complex operations can easily swamp a simple object, obscuring its role. And because these operations often draw together many domain objects, coordinating them and putting them into action, the added responsibility will create dependencies on all those objects, tangling concepts that could be understood independently.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So here is the problem, we have some operations but they can not be put inside an Entity or a Value Objects , how to deal with those operations ?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;B. The Solution&lt;/strong&gt; 🤔
&lt;/h2&gt;

&lt;p&gt;The solution is to create some &lt;strong&gt;doers&lt;/strong&gt;, and the book says :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sometimes services masquerade as model objects, appearing as objects with no meaning beyond doing some operation. &lt;strong&gt;These "doers" end up with names ending in "Manager" and the like. They have no state of their own nor any meaning in the domain beyond the operation they host.&lt;/strong&gt; Still, at&lt;br&gt;
least this solution gives these distinct behaviors a home without messing up a real model object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;C. Service&lt;/strong&gt; 😌
&lt;/h2&gt;

&lt;p&gt;Before giving the definition of the book i want to emphasize the fact that this term is proper to DDD and is not equal to the way we put a suffix to some classes in our java or typescript projects for example, it is a conceptual thing :&lt;/p&gt;

&lt;p&gt;In the blue book :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A SERVICE is an operation offered as an interface that stands alone in the model, without encapsulating state, as ENTITIES and VALUE OBJECTS do. SERVICES are a common pattern in technical frameworks, but they can also apply in the domain layer.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the red book :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A Service in the domain is a stateless operation that fulfills a domain-specific task. Often the best indication that you should create a Service in the domain model is when the operation you need to perform feels out of place as a method on an Aggregate or a Value Object.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;D. Domain Service is not an Application Service&lt;/strong&gt; 🤨
&lt;/h2&gt;

&lt;p&gt;Because when we see the big picture of domain driven design the line between the application and the domain is thin, and so the concept of service is different between the two :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Don’t confuse a Domain Service with an Application Service. We&lt;br&gt;
don’t want to house business logic in an Application Service, but we do want business logic housed in a Domain Service. Briefly, to differentiate the two, an Application Service, being the natural client of the domain model, would normally be the client of a Domain Service.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;N.B&lt;/strong&gt; : For example in a banking application, &lt;em&gt;if the banking application can convert and export our transactions into a spreadsheet file for us to analyze, that export is an application SERVICE&lt;/em&gt;. There is no meaning of "file formats" in the domain of banking, and there are no business rules involved. &lt;strong&gt;On the other hand, a feature that can transfer funds from one account to another is a domain SERVICE because it embeds significant business rules&lt;/strong&gt; (crediting and debiting the appropriate accounts, for example) and because a "funds transfer" is a meaningful banking term.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;E. GOOD Domain Service&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There is three characteristics :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The operation relates to a domain concept that is not a natural part of an ENTITY or VALUE OBJECT.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The interface is defined in terms of other elements of the domain model.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The operation is stateless.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;N.B :&lt;/strong&gt; &lt;em&gt;Statelessness here means that any client can use any instance of a particular SERVICE without regard to the instance's individual history. The execution of a SERVICE will use information that is accessible globally, and may even change that global information (that is, it may have side effects). But the SERVICE does not hold state of its own that affects its own behavior, as most domain objects do.&lt;/em&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;F. Repartition of services&lt;/strong&gt; 💭
&lt;/h2&gt;

&lt;p&gt;In this picture you can see where each service belongs to :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxt6rq4nm75p2v6i9m1ct.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxt6rq4nm75p2v6i9m1ct.png" alt="services_partitioning" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion :&lt;/strong&gt; To conclude we can say , &lt;em&gt;SERVICE, the pattern is also valuable as a means of controlling granularity in the interfaces of the&lt;br&gt;
domain layer, as well as decoupling clients from the ENTITIES and VALUE OBJECTS. Medium-grained, stateless SERVICES can be easier to reuse in large systems because they encapsulate significant functionality behind a simple interface. Also, fine-grained objects can lead to inefficient messaging in a distributed system.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;See you next time 😁&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>architecture</category>
      <category>programming</category>
    </item>
    <item>
      <title>Implementing Domain Driven Design - Value Objects</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Wed, 09 Jul 2025 08:37:27 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/implementing-domain-driven-design-value-objects-2kjo</link>
      <guid>https://dev.to/edgaremmanuel/implementing-domain-driven-design-value-objects-2kjo</guid>
      <description>&lt;p&gt;We continue our series in the chapter 6 about &lt;em&gt;Value Objects&lt;/em&gt; 😁&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. Problem&lt;/strong&gt; 🤔
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Tracking the identity of ENTITIES is essential, but attaching identity to other objects can hurt system performance, add analytical work, and muddle the model by making all objects look the same. Software design is a constant battle with complexity. We must make distinctions so that special handling is applied only where necessary. However, if we think of this category of object as just the absence of identity, wehaven't added much to our toolbox or vocabulary. &lt;strong&gt;In fact, these objects have characteristics of their own and their own significance to the model. These are the objects that describe things&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;B. Definition&lt;/strong&gt; 🔑
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;An object that represents a descriptive aspect of the domain with no conceptual identity is called a VALUE OBJECT. &lt;strong&gt;VALUE OBJECTS are instantiated to represent elements of the design that we care about only for what they are, not who or which they are.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;C. Value Objects Characteristics&lt;/strong&gt; 📕
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1️⃣ &lt;em&gt;Measures, Quantifies, or Describes&lt;/em&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;When you have a true Value Object in your model, whether you realize it or not, it is not a thing in your domain. Instead, it is actually a concept that measures, quantifies, or otherwise describes a thing in the domain. A person has an age.&lt;strong&gt;The age is not really a thing but measures or quantifies the number of years the person (thing) has lived. A person has a name. The name is not a thing but describes what the person (thing) is called.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  2️⃣ &lt;em&gt;Immutable&lt;/em&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;An object that is a Value is unchangeable after it has been created. Instantiation of a value objects class alone does not guarantee that an object is immutable. After the object has been instantiated and initialized by means of construction, none of its methods, whether public or hidden, will from that time forward cause its state to change.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  3️⃣ &lt;em&gt;Conceptual Whole&lt;/em&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;You can see the full explanation of the &lt;a href="http://fit.c2.com/wiki.cgi?WholeValue" rel="noopener noreferrer"&gt;WholeValue&lt;/a&gt;. But the point is simply A Value Object may possess just one, a few, or a number of individual attributes,&lt;br&gt;
each of which is related to the others. &lt;strong&gt;Each attribute contributes an&lt;br&gt;
important part to a whole that collectively the attributes describe. Taken apart from the others, each of the attributes fails to provide a cohesive meaning. Only together do all the attributes form the complete intended measure or description.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  4️⃣ &lt;em&gt;Value Equality&lt;/em&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;When a Value Object instance is compared to another instance, a test of object equality is employed. Throughout the system there may be many, many Value instances that are equal, and yet not the same objects. &lt;strong&gt;Equality is determined by comparing the types of both objects and then their attributes. If both the types and their attributes are equal, the Values are considered equal.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  5️⃣ &lt;em&gt;Replaceability&lt;/em&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;In your model an immutable Value should be held as a reference by an Entity as long as its constant state describes the currently correct Whole Value. &lt;strong&gt;If that is no longer true, the entire Value is completely replaced with a new Value that does represent the currently correct whole.&lt;/strong&gt; Because two value objects are equals if all the attributes are same, so a value object can replace another if it has the same value for the attributes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  6️⃣ &lt;em&gt;Side-Effect-free Function&lt;/em&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A method of an object can be designed as a Side-Effect-Free Function [Evans]. A function is an operation of an object that produces output but without modifying its own state. Since no modification occurs when executing a specific operation, that operation is said to be side-effect free. The methods of an immutable Value Object must all be Side-Effect-Free Functions because they must not violate its immutability quality.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Conclusion&lt;/strong&gt; : Whether to treat a concept as a reference object or value object depends on your context. In many situations it's worth treating a postal address as a simple structure of text with value equality. But a more sophisticated mapping system might link postal addresses into a sophisticated hierarchic model where references make more sense. As with most modeling problems, different contexts lead to different solutions. It's often a good idea to replace common primitives, such as strings, with appropriate value objects. While I can represent a telephone number as a string, turning into a telephone number object makes variables and parameters more explicit (with type checking when the language supports it), a natural focus for validation, and avoiding inapplicable behaviors (such as doing arithmetic on integer id numbers).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;See you next time 😁&lt;/p&gt;

</description>
      <category>softwareengineering</category>
      <category>softwaredevelopment</category>
      <category>architecture</category>
      <category>programming</category>
    </item>
    <item>
      <title>Implementing Domain Driven Design - Entities</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Tue, 01 Jul 2025 09:45:33 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/implementing-domain-driven-design-entities-30h</link>
      <guid>https://dev.to/edgaremmanuel/implementing-domain-driven-design-entities-30h</guid>
      <description>&lt;p&gt;We continue our series in the chapter 5 about &lt;em&gt;Entities&lt;/em&gt; 😁&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. The problem&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here is the problem, our entities do not reflect the importance of &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Instead of designing domain concepts with rich behaviors, we might think primarily about the attributes (columns) and associations (foreign keys) of the data. Doing so reflects the data model into object counterparts, &lt;strong&gt;which leads to almost every concept in our “domain model” being coded as an Entity abounding with getter and setter methods.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;here is the problem, we have entities we only getters and setters and no domain logic!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;B. What is a true Entity&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;We design a domain concept as an Entity when we care about its individuality, when distinguishing it from all other objects in a system is a mandatory constraint. &lt;strong&gt;An Entity is a unique thing and is capable of being changed continuously over a long period of time. Changes may be so extensive that the object might seem much different from what it once was. Yet, it is the same object by identity.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;It is the unique identity and mutability characteristics that set Entities apart from Value Objects&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;C. When a CRUD is enough&lt;/strong&gt; 🙃
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;There are times when an Entity is not the appropriate modeling tool to&lt;br&gt;
reach for. Misappropriated use happens far more often than many are aware. Often a concept should be modeled as a Value. If this is a disagreeable notion, it might be that DDD doesn’t fit your business needs. It is quite possible that a CRUD-based system would be more fitting. &lt;strong&gt;When CRUD makes sense, languages and frameworks such as Groovy and Grails, Ruby on Rails, and the like make the most sense. If the choice is correct, it should save time and money.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;D. When DDD is necessary&lt;/strong&gt;😉
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;When complexity grows, we experience the limitation of poor tool selection. CRUD systems can’t produce a refined business model by only capturing data. &lt;strong&gt;If DDD is a justifiable investment in the business’s bottom line, we use Entities as intended.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And if we talk about the fact to track changes of an entity, that entity has to have a unique identifier , and Eric Evans says : &lt;/p&gt;

&lt;p&gt;&lt;em&gt;When an object is distinguished by its identity, rather than its attributes, make this primary to its definition in the model. Keep the class definition simple and focused on life cycle continuity and identity. Define a means of distinguishing each object regardless of its form or history. The model must define what it means to be the same thing&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;E. Unique Identity for an Entity&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;So that’s what we’ll do first. Having a range of available options for implementing identity is really important, as are those for ensuring that the uniqueness is preserved throughout time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will go through each of the method for ensuring unique identity for an entity &lt;/p&gt;

&lt;h3&gt;
  
  
  1️⃣ &lt;strong&gt;User provides identity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let's see in details : &lt;/p&gt;

&lt;p&gt;✅ &lt;em&gt;Advantage(s)&lt;/em&gt;: It appears to be a straightforward approach to have a user manually enter the details of unique identity. &lt;strong&gt;The user types a recognizable value or symbol into an input field or selects from a set of available characteristics, and the Entity is created.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❌ &lt;em&gt;Disadvantage(s)&lt;/em&gt;: One complication is relying on users to produce quality identities. The identity may be unique but incorrect. Most times identities must be immutable, so users shouldn’t change them. &lt;strong&gt;Can users be relied upon to produce both unique and correct, long-lasting identities?&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2️⃣ &lt;strong&gt;Application generates identity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In details &lt;/p&gt;

&lt;p&gt;✅ &lt;em&gt;Advantage(s)&lt;/em&gt;: There are highly reliable ways to autogenerate unique identities, although care must be taken when the application is clustered or otherwise distributed across multiple computing nodes. There are identity creation patterns that can, to a much greater degree of certainty, produce a completely unique identity. The universally unique identifier (UUID), or globally unique identifier (GUID).&lt;/p&gt;

&lt;p&gt;❌ &lt;em&gt;Disadvantage(s)&lt;/em&gt;: the identity is big and is not considered human-readable.&lt;/p&gt;

&lt;h3&gt;
  
  
  3️⃣ &lt;strong&gt;Persistence Mechanism Generates Identity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;✅ &lt;em&gt;Advantage(s)&lt;/em&gt;: &lt;strong&gt;Delegating the generation of unique identity to a persistence mechanism has some unique advantages. If we call on the database for a sequence or incrementing value, it will always be unique.&lt;/strong&gt; Depending on the range needed, the database can generate a unique 2-byte, 4-byte, or 8-byte value. In Java, a 2-byte short integer would allow for up to 32,767 unique identities; a 4-byte normal integer would afford 2,147,483,647 unique values; and an 8-byte long integer would provide up to 9,223,372,036,854,775,807 distinct identities. Even zero-filled text representations of these ranges are narrow, at five, ten, and 19 characters respectively.&lt;/p&gt;

&lt;p&gt;❌ &lt;em&gt;Disadvantage(s)&lt;/em&gt;: &lt;strong&gt;One possible downside is performance. It can take significantly longer to go to the database to get each value than to generate identities in the application.&lt;/strong&gt; Much depends on database load and application demand. &lt;em&gt;One way around this is to cache sequence/increment values in the application, such as in a Repository.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4️⃣ &lt;strong&gt;Another Bounded Context assigns Identity&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;✅ &lt;em&gt;Advantage(s)&lt;/em&gt; : &lt;strong&gt;When another Bounded Context assigns identity, we need to integrate to find, match, and assign each identity.&lt;/strong&gt; DDD integrations are explained in Context Maps and Integrating Bounded Contexts. Making an exact match is the most desirable. Users need to provide one or more attributes, such as an account number, username, e-mail address, or other unique symbol, to pinpoint the intended result.&lt;/p&gt;

&lt;p&gt;❌ &lt;em&gt;Disadvantage(s)&lt;/em&gt;: &lt;strong&gt;This has synchronization implications.&lt;/strong&gt; What happens if externally referenced objects transition in ways that affect local Entities? How will we know that the associated object changed?&lt;/p&gt;

&lt;p&gt;💡 &lt;em&gt;solution(s)&lt;/em&gt;: This problem can be solved using an Event-Driven Architecture with Domain Events. Our local Bounded Context&lt;br&gt;
subscribes to Domain Events published by external systems. When a relevant notification is received, our local system transitions its own Aggregate Entities to reflect the state of those in external systems.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Conclusion : An Entity is an object that &lt;strong&gt;has a unique identity&lt;/strong&gt; that runs through time and different states. &lt;strong&gt;Is mutable&lt;/strong&gt; — its attributes may change, but it remains the same entity. &lt;strong&gt;Is distinguished by its ID&lt;/strong&gt; rather than its attributes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;See you next time 😁&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>ddd</category>
    </item>
    <item>
      <title>Patterns of Enterprise Application Architecture - Data Source Patterns (3)</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Mon, 30 Jun 2025 08:12:55 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/patterns-of-enterprise-application-architecture-data-source-patterns-3-27k9</link>
      <guid>https://dev.to/edgaremmanuel/patterns-of-enterprise-application-architecture-data-source-patterns-3-27k9</guid>
      <description>&lt;p&gt;Today we end that chapter , with the &lt;strong&gt;Data Mapper&lt;/strong&gt; pattern &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. The problem&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Objects and relational databases have different mechanisms for structuring data. Many parts of an object, such as collections and inheritance, aren’t present in relational databases. When you build an object model with a lot of business logic it’s valuable to use these mechanisms to better organize the data and the behavior that goes with it. Doing so leads to variant schemas; that is, the object schema and the relational schema don’t match up. You still need to transfer data between the two schemas, and this data transfer becomes a complexity in its own right. If the in-memory objects know about the relational database structure, changes in one tend to ripple to the other.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;How to make the object schema and the relational schema work together in a cohesive way ?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;B. The Solution&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F44v82rdhz4ykgt3c96w3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F44v82rdhz4ykgt3c96w3.png" alt="data_mapper_schema" width="800" height="291"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Data Mapper is a layer of software that separates the in-memory objects from the database. Its responsibility is to transfer data between the two and also to isolate them from each other. With Data Mapper the in-memory objects needn’t know even that there’s a database present; they need no SQL interface code, and certainly no knowledge of the database schema.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;C. How it works ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The way it works, we have to deal with two important steps :&lt;/p&gt;

&lt;p&gt;1 - &lt;strong&gt;Finder&lt;/strong&gt; : The step of finding is an important step, it goes from the presentation layer to the domain layer, and the domain object after going from object to objects , makes the request to the mapper layer.&lt;/p&gt;

&lt;p&gt;2 - &lt;strong&gt;Mapping Data to Domain Fields&lt;/strong&gt; : Once the mapper has retrieved the response from the database , we have to find a way to map the column from the database to the domain fields. The first solution is to have  &lt;strong&gt;Rich Constructor&lt;/strong&gt; it’s nice to have a well-formed object from the start. This also means that, if you have an immutable field, you can enforce it by not providing any method to change its value. The second is to use a &lt;strong&gt;no args constructor&lt;/strong&gt; the point here is to create an empty object and then populate it with the mandatory data.&lt;/p&gt;

&lt;p&gt;Here we have a figure to show the sequential order :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotyceapj99voxdvzoeey.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotyceapj99voxdvzoeey.png" alt="data_mapper_flow" width="799" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;D. When to use it ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To say it simply :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The primary occasion for using Data Mapper is when you want the database schema and the object model to evolve independently. &lt;strong&gt;The most common case for this is with a Domain Model. Data Mapper’s primary benefit is that when working on the domain model you can ignore the database, both in design and in the build and testing process.&lt;/strong&gt; The domain objects have no idea what the database structure is, because all the correspondence is done by the mappers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And how can i test that : &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;So the test for using these patterns is the complexity of the business logic. More complicated logic leads you to Domain Model and therefore to Data Mapper.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; &lt;em&gt;Here we do not have the coupling between the domain and the datasource, the data mapper for me is a good layer for low coupling&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Patterns of Enterprise Application Architecture - Data Source Patterns (2)</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Mon, 23 Jun 2025 08:19:18 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/patterns-of-enterprise-application-architecture-data-source-patterns-2-3f4n</link>
      <guid>https://dev.to/edgaremmanuel/patterns-of-enterprise-application-architecture-data-source-patterns-2-3f4n</guid>
      <description>&lt;p&gt;Today we will dive in the &lt;em&gt;Active Record data source patterns&lt;/em&gt; for enterprise applications&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. Active Record&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffb6dqjopxi5um4fdqfkq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffb6dqjopxi5um4fdqfkq.png" alt="active_record" width="709" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;A.1 Definition&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;An object carries both data and behavior. Much of this data is persistent and needs to be stored in a database. Active Record uses the most obvious approach, putting data access logic in the domain object. This way all people know how to read and write their data to and from the database.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;A.2 How it works ?&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Each Active Record is responsible for saving and loading to the database and also for anyndomain logic that acts on the data. This may be all the domain logic in the application, or you may find that some domain logic is held in Transaction Scripts with common and data-oriented code in the Active Record.&lt;strong&gt;The data structure of the Active Record should exactly match that of the database: one field in the class for each column in the table.&lt;/strong&gt; Type the fields the way the SQL interface gives you the data—don’t do any conversion at this stage.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;A.3 Composition of an Active Record Class&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The Active Record class typically has methods that do the following:&lt;/p&gt;

&lt;p&gt;• Construct an instance of the Active Record from a SQL result set row&lt;/p&gt;

&lt;p&gt;• Construct a new instance for later insertion into the table&lt;/p&gt;

&lt;p&gt;• Static finder methods to wrap commonly used SQL queries and return&lt;br&gt;
Active Record objects&lt;/p&gt;

&lt;p&gt;• Update the database and insert into it the data in the Active Record&lt;/p&gt;

&lt;p&gt;• Get and set the fields&lt;/p&gt;

&lt;p&gt;• Implement some pieces of business logic&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;A.4 When to use it ?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The author of the book says :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Active Record is a good choice for domain logic that isn’t too complex, such as creates, reads, updates, and deletes.&lt;/strong&gt; Derivations and validations based on a single record work well in this structure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Active Record is a good pattern to consider if you’re using Transaction Script&lt;/strong&gt; and are beginning to feel the pain of code duplication and the difficulty in updating scripts and tables that Transaction Script (110) often brings. In this case you can gradually start creating Active Records and then slowly refactor behavior into them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  A.5 What's in the Real World
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;In the real world we have ActiveRecord (Ruby on Rails), Eloquent (Laravel / PHP), some implementations of JPA (Java Persistence API), Django ORM (Python)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When you use those ORM you'll face Active Record pattern because in each the class contains the domain information and can do the operations directly againts the database &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt; : &lt;em&gt;The problem is the coupling between the domain and the database, and that's why the next time , we will talk about &lt;strong&gt;Data mapper&lt;/strong&gt;&lt;/em&gt; 😉&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>programming</category>
      <category>development</category>
    </item>
    <item>
      <title>Patterns of Enterprise Application Architecture - Data Source Patterns (1)</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Thu, 19 Jun 2025 08:42:39 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/patterns-of-enterprise-application-architecture-data-source-patterns-1-135d</link>
      <guid>https://dev.to/edgaremmanuel/patterns-of-enterprise-application-architecture-data-source-patterns-1-135d</guid>
      <description>&lt;p&gt;Today we will dive in some of the &lt;em&gt;data source patterns&lt;/em&gt; for enterprise applications&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. Table Data Gateway&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb18yrq315smcxm6lnm5c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb18yrq315smcxm6lnm5c.png" alt="table_data_gateway" width="787" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Table Data Gateway holds all the SQL for accessing a single table or view: selects, inserts, updates, and deletes. Other code calls its methods for all interaction with the database.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  A.1 How it works ?
&lt;/h3&gt;

&lt;h4&gt;
  
  
  A.1.1 Insertion Part
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;A Table Data Gateway has a simple interface, usually consisting of several find methods to get data from the database and update, insert, and delete methods. Each method maps the input parameters into a SQL call and executes the SQL against a database connection.The Table Data Gateway is usually stateless, as its role is to push data back and forth.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  A.1.2 Retrieving Part
&lt;/h4&gt;

&lt;p&gt;Here we have a problem with that patterm because, it will return &lt;strong&gt;multiple items&lt;/strong&gt; even for a simple &lt;em&gt;findById(id)&lt;/em&gt; method !&lt;br&gt;
We have alternatives for that :&lt;/p&gt;

&lt;p&gt;-&lt;em&gt;Map&lt;/em&gt;: A map works, but it forces data to be copied out of the record set that comes from the database into the map. But the problem with a Map is that it can not be used everywhere !&lt;/p&gt;

&lt;p&gt;-&lt;em&gt;DTO&lt;/em&gt;: However a DTO can, yes we have to create another object but a DTO can be used or processed but much more environments&lt;/p&gt;

&lt;h3&gt;
  
  
  A.2 When to use it ?
&lt;/h3&gt;

&lt;p&gt;According to the author :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I find that Table Data Gateway is probably the simplest database interface pattern to use, as it maps so nicely onto a database table or record type. It also makes a natural point to encapsulate the precise access logic of the data source.  Table Data Gateway works particularly well with &lt;a href="https://martinfowler.com/eaaCatalog/tableModule.html" rel="noopener noreferrer"&gt;Table Module&lt;/a&gt;, where it produces a record set data structure for it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;B. Row Data Gateway&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If it is not white, it's dark 😂&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7k4hw4oaazrg6r4rltx5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7k4hw4oaazrg6r4rltx5.png" alt="row_data_gateway" width="799" height="592"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Row Data Gateway gives you objects that look exactly like the record in your record structure but can be accessed with the regular mechanisms of your programming language. All details of data source access are hidden behind this interface.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  B.1 How it works ?
&lt;/h3&gt;

&lt;h4&gt;
  
  
  B.1.1 Behind the hood
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;A Row Data Gateway acts as an object that exactly mimics a single record, such as one database row. In it each column in the database becomes one field. The Row Data Gateway will usually do any type conversion from the data source types to the in-memory types, but this conversion is pretty simple. This pattern holds the data about a row so that a client can then access the Row Data Gateway directly&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But we have the problem of how to generate a &lt;em&gt;Row data gateway&lt;/em&gt; ?&lt;/p&gt;

&lt;h4&gt;
  
  
  B.1.2 Creating a Row Data Gateway
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;With a Row Data Gateway you’re faced with the questions of where to put&lt;br&gt;
the find operations that generate this pattern. You can use static find methods, but they preclude polymorphism should you want to substitute different finder methods for different data sources. In this case it often makes sense to have separate finder objects so that each table in a relational database will have one finder class and one gateway class for the results&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2wq7zu0nidtzbmq0k4d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2wq7zu0nidtzbmq0k4d.png" alt="row_data_gateway" width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Like you see in the image below, we create a &lt;strong&gt;Finder&lt;/strong&gt; that will generate for us &lt;strong&gt;Row data gateway&lt;/strong&gt; for the &lt;em&gt;Person&lt;/em&gt; model &lt;/p&gt;

&lt;h3&gt;
  
  
  B.2 When to use it ?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;I use Row Data Gateway most often when I’m using a &lt;a href="https://martinfowler.com/eaaCatalog/transactionScript.html" rel="noopener noreferrer"&gt;Transaction Script&lt;/a&gt; . In this case it nicely factors out the database access code and allows it to be reused easily by different Transaction Scripts. A Row Data Gateway&lt;br&gt;
should contain only database access logic and no domain logic.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Conclusion : The choice of Row Data Gateway often takes two steps: first whether to use a gateway at all and second whether to use Row Data Gateway or Table Data Gateway.&lt;/em&gt; 😉&lt;/p&gt;

</description>
      <category>programming</category>
      <category>softwareengineering</category>
      <category>softwaredevelopment</category>
      <category>development</category>
    </item>
    <item>
      <title>Implementing Domain Driven Design - Event Driven Architecture</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Fri, 13 Jun 2025 09:07:42 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/implementing-domain-driven-design-event-driven-architecture-348o</link>
      <guid>https://dev.to/edgaremmanuel/implementing-domain-driven-design-event-driven-architecture-348o</guid>
      <description>&lt;p&gt;We continue our series in the chapter 4 about Architecture 😁&lt;br&gt;
Today we will talk about &lt;strong&gt;Event Driven Architecture ( EDA )&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. Definition&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In a simple way :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Event-driven architecture (EDA) is a software architecture promoting the production, detection, consumption of, and reaction to events.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;B. What kind of events ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Of course in a system with can handle many types of events, but perhaps we are in DDD, the main focus will be on &lt;strong&gt;Domain Events&lt;/strong&gt; , and in the book :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There may be a number of different kinds of events that enter and exit a hexagon. We are interested specifically in Domain Events. The application may also subscribe to system, enterprise, or other types of events as well. Perhaps those deal with system health and monitoring, logging, dynamic provisioning, and the like. Yet, it is the Domain Events that convey the happenings requiring our modeling attention.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;N.B: The flow of events will go from one output port to an input port.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fep9zjztueornftzqlw5t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fep9zjztueornftzqlw5t.png" alt="flow of events" width="799" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Domain Events published by one such system through the output Port would be delivered to subscribers represented in the others through their input Port. The various Domain Events received have a specific meaning in each receiving&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;C. Pipes and Filters&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In EDA there is the concepts of &lt;em&gt;Pipes&lt;/em&gt; and &lt;em&gt;Filters&lt;/em&gt; , it is important to grasp some characteristics of them , but the main point can be truly understood in the definition &lt;/p&gt;

&lt;h3&gt;
  
  
  C.1. Filters
&lt;/h3&gt;

&lt;p&gt;A Filter has many characteristics , like the book says :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Filters may process messages without actually filtering. Futhermore Filters receive messages on an inbound Pipe and send messages on an outbound Pipe. Finally Filters connect to inbound and outbound Pipes through a Port. Ports make Hexagonal (Ports and Adapters) a fitting overarching style.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The table below for me explains some &lt;em&gt;key&lt;/em&gt; characteristics of filter : &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8o10tuhr0zt3swwddxc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8o10tuhr0zt3swwddxc.png" alt="filter characteristics" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  C.2. Pipes
&lt;/h3&gt;

&lt;p&gt;It is a channel where the event goes after the processing in the filter &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Pipe is actually a message channel&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;N.B: Understand, however, that a messaging Pipes and Filters approach is not exactly like the command-line version, and it is not intended to be. For example, an EDA Filter doesn’t need to actually filter anything. A Filter in an EDA may be used to perform some processing while leaving the message data intact.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1h65dwveakfclglzg7nk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1h65dwveakfclglzg7nk.png" alt="pipeline of events" width="800" height="772"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here for example &lt;strong&gt;PhoneNumberFinder&lt;/strong&gt; or &lt;strong&gt;MatchedPhoneNumberCounter&lt;/strong&gt; are Filters !&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;D. How does it fit in DDD?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I thought also it was so simple but it so well said in the book :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In an actual DDD scenario, Domain Events reflect names meaningful to the business. Step 1 could publish a Domain Event based on the behavioral outcome of an Aggregate in one Bounded Context. Steps 2 through 4 could occur in one or more different Bounded Contexts that receive the initial Event and then publish one of the subsequent ones. Those three steps could create or modify Aggregates in their respective Contexts. It does depend on the domain, but those are common outcomes of handling Domain Events in a Pipes and Filters Architecture. &lt;strong&gt;Domain Events&lt;/strong&gt; They explicitly model business process activity occurrences that are useful for domain-wide subscribers to know about, and they pack unique identity and as many knowledge-conveying properties as necessary to clearly get their point across. Yet this synchronous, step-by-step style can be extended to accomplish more than one thing at the same time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;E. Sagas&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Of course because we are in the domain of computer we can have events that processes shortly and &lt;strong&gt;long running processes&lt;/strong&gt; because they can be completed after some days and those ones are called &lt;strong&gt;Sagas&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The synthetic Pipes and Filters example can be extended to demonstrate another Event-Driven, distributed, parallel processing pattern, namely, Long-Running Processes. A Long-Running Process is sometimes called a Saga&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;E.1. Handling more than one event&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A filter can handle more than one event, for example if a Filter handle two events from two processes, one can be a short running and the other a long running . Because the execution is in parallel now the main issue is to tell to the filter or to inform him that the long running one has finished his work &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98wdv461os7uwvkjgbjl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F98wdv461os7uwvkjgbjl.png" alt="long running processes" width="800" height="430"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Extending the previous example, we could create parallel pipelines by adding just one new Filter, &lt;strong&gt;TotalPhoneNumbersCounter&lt;/strong&gt;, as an additional subscriber to AllPhoneNumbersListed. &lt;strong&gt;It receives the Event AllPhoneNumbersListed virtually in parallel with the PhoneNumberFinder.&lt;/strong&gt; The new Filter has a very simple goal, counting all existing contacts. This time, however, PhoneNumberExecutive both starts the Long-Running Process and tracks it through completion.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And the point for the filter is : &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Now it is the responsibility of PhoneNumberExecutive to subscribe to two Events, both MatchedPhoneNumbersCounted and AllPhoneNumbersCounted. &lt;strong&gt;The parallel processing is not considered completed until both of these Domain Events are received.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;F. How to know the end of the long running process ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;There is a problem with this Long-Running Process, however. The&lt;br&gt;
&lt;em&gt;PhoneNumberExecutive&lt;/em&gt; currently has no way of knowing that it has received the two completion Domain Events associated with the specific, corresponding parallel processes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can combine two ways to give a solution to the problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;F.1. Unique ID&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The first step in the solution to this troublesome situation is to assign a unique Process identity that is carried by each of the associated Domain Events. This could be the same identity assigned to the originating Domain Event that causes the Long-Running Process to begin (for example, AllPhoneNumbersListed). We could use a universally unique identifier (UUID) allocated specifically to the Process.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;F.2. Tracker&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Create a Tracker that tracks each of the associated events of course with the verification of the ID of the associated events &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;In an actual domain each instance of a Process executive creates a new Aggregate-like state object for tracking its eventual completion. The state object is created when the Process begins, associating the same unique identity that each related Domain Event must carry. It may also be useful for it to hold a timestamp of when the Process began (the reasons are discussed later in the chapter). As each pipeline in the parallel processing completes, the executive receives a corresponding completion Event. &lt;strong&gt;The executive retrieves the state tracking&lt;br&gt;
instance by matching the unique Process identity carried by the received Event and sets a property that represents the step just completed&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5t962y6bsn0trn6wm57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5t962y6bsn0trn6wm57.png" alt="tracker" width="799" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Not to be overlooked is that the Long-Running Process executive can publish one, two, or more Events to initiate the parallel processing. There may also be not only two, but three or more subscribers to any initiating Event or Events. In other words, a Long-Running Process may lead to many separate business process activities executing simultaneously.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;G. Event Sourcing&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;G.1. The Problem&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;With an increased desire for even more change tracking, the business demands more metadata. It begins to care also about the individual operations that were executed over time. Maybe it even wants to understand how long certain operations took to execute. Those desires lead to the need to maintain an audit log or journal of the finer-grained use case metrics. But an audit log or journal has its limitations. It can convey some information about what has happened in the system, perhaps even allowing for some debugging. But it doesn’t allow us to examine the state of individual domain objects before and after specific kinds of changes. What if we could stretch more out of change tracking?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;G.2. Why we need it ?&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;As developers we have all experienced finer-grained change tracking in one form or another. The most common example is with the use of a source code repository, such as CVS, Subversion, Git, or Mercurial. What all of these variations of source revision management systems have in common is that they all know how to track changes that occur on a source file. &lt;em&gt;The change tracking provided by this genre of tool enables us to go all the way back in time, to view a source code artifact from its very first revision, and then to proceed revision by revision, all the way to the very latest. When committing all source files to revision control, it can track changes of the whole development life cycle.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  G.3 Solution
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Now, if we think about applying this concept to a single Entity, then to an Aggregate, then to every Aggregate in the model, we can understand the power of change tracking objects and the value it can produce in our systems. With that in mind, we want to develop a means to know what occurred in the model to cause the creation of any given Aggregate instance, and also what has happened to that given Aggregate instance throughout time, operation by operation. Given the history of everything that’s happened, we could even support temporal models. &lt;strong&gt;This level of change tracking is at the heart of a pattern named Event Sourcing.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi9roh97m91tdoqp2daqj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi9roh97m91tdoqp2daqj.png" alt="event sourcing" width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt; : &lt;em&gt;For me that architecture is for a very low coupling between bounded contexts and to make everyone independent, because the only thing that link a Bounded context to another is the Domain Event&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;See you next time 😁 if you want to add some insights feel free to comment !&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>eventdriven</category>
    </item>
    <item>
      <title>Patterns of Enterprise Application Architecture - Distribution Strategies</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Wed, 11 Jun 2025 08:56:51 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/patterns-of-enterprise-application-architecture-distribution-strategies-1ok8</link>
      <guid>https://dev.to/edgaremmanuel/patterns-of-enterprise-application-architecture-distribution-strategies-1ok8</guid>
      <description>&lt;p&gt;We continue in the chapter &lt;em&gt;Distribution Strategies&lt;/em&gt; 😉&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. The Problem&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The author says :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;However, distribution of objects, or indeed of anything else, has a lot more pitfalls than many people realize [Waldo et al.], especially when they’re under the influence of vendors’ cozy brochures. This chapter is about some of these hard lessons&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The point is : &lt;strong&gt;How can we make distribution of objects efficient in our system ?&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;B. The Bad&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The most popular way is to take each Object and put them in a seperate node for &lt;em&gt;performance&lt;/em&gt; , like in the image below :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqo79k5srtp3d2q2ipclb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqo79k5srtp3d2q2ipclb.png" alt="bad distribution" width="799" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But the author says : &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Transparency is valuable, but while many things can be made transparent in distributed objects, performance isn’t usually one of them. Although our prototypical architect was distributing objects the way he was for performance reasons, in fact his design will usually cripple performance, make the system much harder to build and deploy, or, usually, do both.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;N.B: Why putting everything in a single node is  bad ?&lt;/strong&gt; :
&lt;/h3&gt;

&lt;p&gt;Simply because &lt;em&gt;local call and remote call&lt;/em&gt; on the point of performance &lt;strong&gt;are not same&lt;/strong&gt; :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The primary reason that the distribution by class model doesn’t work has to do with a fundamental fact of computers. A procedure call within a process is very, very fast. A procedure call between two separate processes is orders of magnitude slower. Make that a process running on another machine and you can add another order of magnitude or two, depending on the network topography involved.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;C. The Good&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The way is to be proficient with our multiple processors environment and the author says :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Hence, we get to my **First Law of Distributed Object Design: Don’t distribute your objects!&lt;/strong&gt; How, then, do you effectively use multiple processors? In most cases the way to go is clustering. Put all the classes into a single process and then run multiple copies of that process on the various nodes. That way each process uses local calls to get the job done and thus does things faster.**&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0enpa18swz4dmqa9s2s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl0enpa18swz4dmqa9s2s.png" alt="good distribution" width="800" height="540"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;D. Be Pragmatic with Clustering&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Because there will always be case where distribution is inevitable for objects and the author to say &lt;em&gt;The rub is that there are limits to that approach—that is, places where you need to separate the processes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Some examples :&lt;/p&gt;

&lt;p&gt;&lt;em&gt;1. Separation is between the traditional clients and servers of&lt;br&gt;
business software&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2. Separation between server-based application software (the application server) and the database&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Colleen Roe’s memorable phrase, is to be &lt;strong&gt;“parsimonious&lt;br&gt;
with object distribution.”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;E. Minimizing the coupling in distribution&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;As you design your system you need to limit your distribution boundaries as much as possible, but where you have them you need to take them into account. We can do it with some solutions :&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;E.1. Remote Facade&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The coarse-grained objects don’t really do anything but&lt;br&gt;
delegate so they act as a facade for the fine-grained objects. This facade is there only for distribution purposes—hence the name Remote Facade (388). Using a Remote Facade (388) helps minimize the difficulties that the coarsegrained interface introduces. This way only the objects that really need a remote service get the coarse-grained method, and it’s obvious to the developers. &lt;a href="https://martinfowler.com/eaaCatalog/remoteFacade.html" rel="noopener noreferrer"&gt;Remote Facade&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fly55620els3x1dcmsjul.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fly55620els3x1dcmsjul.png" alt="remote facade" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;E.2. Data Transfer Object&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;You usually can’t send the domain object itself, because it’s&lt;br&gt;
tied in a Web of fine-grained local inter-object references. So you take all the data that the client needs and bundle it in a particular object for the transfer—hence the term Data Transfer Object (401). (Many people in the enterprise Java community use the term value object for this, but this causes a clash with other meanings of the term Value Object (486)). The Data Transfer Object (401) appears on both sides of the wire, so it’s important that it not reference anything that isn’t shared over the wire. This boils down to the fact that a Data Transfer Object (401) usually only references other Data Transfer Objects (401) and fundamental objects such as strings. &lt;a href="https://martinfowler.com/eaaCatalog/dataTransferObject.html" rel="noopener noreferrer"&gt;DTO&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F19o8mygb7gq4hw1ktbcn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F19o8mygb7gq4hw1ktbcn.png" alt="dto schema" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally what we can say that these are the patterns to be efficient with distribution of objects ! &lt;/p&gt;

&lt;p&gt;End of that chapter , See you ❤️&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
      <category>programming</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Implementing Domain Driven Design - CQRS</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Tue, 10 Jun 2025 09:11:07 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/implementing-domain-driven-design-cqrs-4jjb</link>
      <guid>https://dev.to/edgaremmanuel/implementing-domain-driven-design-cqrs-4jjb</guid>
      <description>&lt;p&gt;We continue our series in the chapter 4 about Architecture 😁&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. What's the problem ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How can we retrieve all the data users need to view and do it correctly and especially when the domain is complex ?&lt;/strong&gt; we can do it with repositories in combination with DTOs but it will not be optimal &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;B. The Solution&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;The answer lies in the &lt;strong&gt;oddly named architecture pattern CQRS ( Command Query Responsibility Segregation )&lt;/strong&gt;. It is the result of pushing a stringent object (or component) design principle, command-query separation (CQS), up to an architecture pattern.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;C. The Definition&lt;/strong&gt;
&lt;/h2&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;C.1. Basic&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Bertrand Meyer, asserts the following:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Every method should be either a command that performs an action, or a query that returns data to the caller, but not both. In other words, asking a question should not change the answer. More formally, methods should return a value only if they are referentially transparent and hence possess no side effects.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;C.2. Technical&lt;/strong&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;1. If a method modifies the state of the object, it is a command, and its method must not return a value. In Java and C# the method must be declared void.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2. If a method returns some value, it is a query, and it must not directly or indirectly cause the modification of the state of the object. In Java and C# the method must be declared with the type of the value it returns.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;D. how is it applied ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There is two steps, designing the &lt;strong&gt;Command Model&lt;/strong&gt; and after tuning the &lt;strong&gt;Query Model&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;D.1. Command Model&lt;/strong&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;Now think of segregating all of the pure query responsibilities traditionally found in a model from all responsibilities that execute pure commands on the same model. Aggregates would have no query methods (getters), only command methods. Repositories would be stripped down to an add() or save() method (supporting both creation and updating saves) and only a single query method, such as fromId(). The single query method takes the unique identity of an Aggregate and returns it. A Repository could not be used to find an Aggregate by any other means, such as by filtering on some additional properties. With all of that removed from the traditional model, we designate it a &lt;strong&gt;command model&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;D.2. Query Model&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;To fully understand the design of the &lt;em&gt;Query Model&lt;/em&gt; we have to do a deep dive in the details of the &lt;em&gt;CQRS Pattern&lt;/em&gt; for each of the components of the figure below :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6vglshnnmqhhzinsjiz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu6vglshnnmqhhzinsjiz.png" alt=" " width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;D.2.A Client and Query Processor&lt;/strong&gt;
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;p&gt;The client (at the far left in the diagram) may be a Web browser or a custom desktop user interface. It uses a set of query processors running on a server. The diagram doesn’t show architecturally significant divisions between tiers on the server(s). Whatever tiers exist, the query processor represents a simple component that only knows how to execute basic queries on a database, such as a SQL store.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;D.2.B Query Model (or Read Model)&lt;/strong&gt;
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;p&gt;The query model is a denormalized data model. It is not meant to deliver domain behavior, only data for display (and possibly reporting). If this data model is a SQL database, each table would hold the data for a single kind of client view (display). The table can have many columns, even a superset of those needed by any given user interface display view. Table views can be created from tables, each of which is used as a logical subset of the whole&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;D.2.C Command Processors&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;A command submission is received by a Command Handler/processor, which can have a few different styles. We consider those styles here, along with some advantages and disadvantages.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We can use a &lt;em&gt;&lt;strong&gt;categorized style&lt;/strong&gt;&lt;/em&gt; with several Command Handlers in one Application Service. This style creates an Application Service interface and implementation for a category of commands. Each Application Service could have multiple methods, one method declared for each type of command with parameters that fits the category. The primary advantage here is simplicity. This kind of handler is well understood, easy to create, and easy to maintain.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can create a &lt;em&gt;&lt;strong&gt;dedicated style&lt;/strong&gt;&lt;/em&gt; handler. Each one would be a single class with one method. The method contract facilitates a specific command with parameters. This has clear advantages: There is a single responsibility per handler/processor; each handler may be redeployed independently of others; handler types can be scaled out to manage high volumes of certain kinds of commands.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;D.2.D Command Model (or Write Model)&lt;/strong&gt;
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;p&gt;Executes Behavior As each command method on the command model is executed, it completes by publishing an Event. This is the linchpin for updating the query model with the most recent changes to the command model. If using Event Sourcing, the Events are also necessary for persisting the state of the Aggregate that has just been modified. However, it is not a necessity to use Event Sourcing with CQRS. Unless Event logging is a requirement specified by the business, the command model can be persisted using an object- relational mapper (ORM) to a relational database or some other approach. &lt;strong&gt;Either way, a Domain Event must still be published to ensure that the query model is updated.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;D.2.E Event Subscriber Updates the Query Model&lt;/strong&gt;
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;p&gt;A special subscriber registers to receive all Domain Events published by the command model. The subscriber uses each Domain Event to update the query model to reflect the most recent changes to the command model. This implies that each Event must be rich enough to supply all the data necessary to produce the correct state in the query model.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;N.B :&lt;/strong&gt; &lt;em&gt;Should the updates be performed synchronously or asynchronously? It depends on the normal load on the system, and possibly also on where the query model database is stored. Data consistency constraints and performance requirements will influence the decision.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;E. Eventual Consistency&lt;/strong&gt;
&lt;/h2&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;E.1. Trade-off&lt;/strong&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;To update synchronously, the query model and command model would normally share the same database (or schema), and we would update the two models in the same transaction. That keeps both models completely consistent. Yet, this will require more processing time for the multiple table updates, which may not meet the service-level agreement (SLA). If the system is normally under heavy load and the query model update process is lengthy, use asynchronous updates instead. This may lead to challenges of eventual consistency, where the user interface will not immediately reflect the most recent changes in the command model. The lag time is unpredictable, but it is a trade-off that may be necessary to meet other SLAs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;E.2. A way to give a solution&lt;/strong&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;One technique suggested by [Dahan, CQRS] always explicitly displays on the user interface the date and time of the data from the query model that a user is currently viewing. To do so, each record in the query model needs to maintain the date and time of the latest update. This is a trivial step, generally supported by a database trigger. &lt;strong&gt;With the date and time of the latest update, the user interface can now inform the user how old the data is. If the user determines that the data is too stale to use, he or she can at that time request fresher data&lt;/strong&gt;. Admittedly this approach is lauded by some as an effective pattern and heavily criticized by others as a hack or artifice. Certainly these opposing viewpoints indicate the need to perform user acceptance tests before this approach is employed in our own systems.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Conclusion :&lt;/strong&gt; As with every pattern, CQRS introduces a number of competing forces. We must exercise a great deal of care and choose wisely.&lt;/p&gt;

&lt;p&gt;See you next time 😁 by the grace of JESUS, This year i will try to be more consistent !&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>programming</category>
      <category>softwareengineering</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>Implementing Domain Driven Design - Day 7</title>
      <dc:creator>DevByJESUS</dc:creator>
      <pubDate>Fri, 17 Jan 2025 11:03:16 +0000</pubDate>
      <link>https://dev.to/edgaremmanuel/implementing-domain-driven-design-day-7-3927</link>
      <guid>https://dev.to/edgaremmanuel/implementing-domain-driven-design-day-7-3927</guid>
      <description>&lt;p&gt;We continue our series in the chapter 4 about &lt;em&gt;Architecture&lt;/em&gt; 😁&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;A. SOA ( Service Oriented Architecture )&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A.1 - The principles of Services&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjsd5hobgr48z7oqd0nu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjsd5hobgr48z7oqd0nu.png" alt="services_principles" width="800" height="696"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A.2 - What are the Services&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The technical services could be &lt;strong&gt;RESTful resources&lt;/strong&gt;, &lt;strong&gt;SOAP interfaces&lt;/strong&gt;, or &lt;strong&gt;message types&lt;/strong&gt;. The business service emphasizes business strategy, a way to bring business and technology together. However, defining a single business service does not equate to defining a single Subdomain (2) or Bounded Context. No doubt as we perform both problem space and solution space assessments, we will find that a business service comprises a number of each.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A.3 - SOA with Hexagonal Architecture&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;With the service boundary at the far left and the domain model at the heart. The basic architecture is presented in Figure 4.5, where consumers reach services using REST, SOAP, and messaging. Note that one Hexagonal-based system supports multiple technical service endpoints. This has a bearing on how DDD is used within an SOA.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg3ecnejzhh2ksg9bdvhg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg3ecnejzhh2ksg9bdvhg.png" alt="soa_and_hexagonal" width="800" height="696"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Credits:IDDD of Vernon&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;B. Representational State Transfer—REST&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;B.1 - Definition&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Web protocols can be used in many different ways. Some of them match the goals of the original designers; some of them don’t. One often-used analogy highlights this using the RDBMS world familiar to many. You can use an RDBMS in line with its architectural concepts—that is, define tables with columns, foreign key relationships, views, constraints, and so on—or you can create a single table with two columns,one called “key,” one called “value,” and simply store serialized objects in the value column. Of course, you’d still be using an RDBMS, but many of its benefits will not be available to you (meaningful queries, joins, sorting and grouping, and so forth). In a very similar fashion, the Web protocols can be used in line with the original ideas that made them what they are—with an architecture that conforms to the REST architectural style—or be used in a way that fails to follow it. And similar to our RDBMS example, we ignore the underlying architectural style to our peril.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;B.2 - Key Aspects of a RESTful HTTP Server&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;B.2.1 - Resources&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;resources are a key concept. How so? As a&lt;br&gt;
system designer, you decide what are the meaningful “things” that you want to expose as accessible from the outside, and you assign each a distinct identity. In general, each resource has one URI, and more importantly, each URI should point to one resource—the “things” you expose to the outside need to be individually addressable. For example, you might decide that each customer, each product, each product listing, each search result, and maybe each change to the product catalog should be resources in their own right. Resources have representations, renditions of their state, in one or more formats. It’s through representations—an XML or JSON document, an HTML form’s post data, or some binary format—that clients interact with resources.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;B.2.2 - Stateless Communication&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The next key aspect is the idea of stateless communication, using self-descriptive messages. Such is an HTTP request that carries all the information the server needs to handle it. Of course, the server can (and usually will) use its own persistent state to help, but it’s important that the client and server don’t rely on individual requests to set up an implicit context (a session). This enables access to each resource independently of other requests, an aspect that helps in achieving massive scalability. If you view resources as objects—and it’s not at all unreasonable to do so it’s valid to ask what kind of interface they should have. &lt;strong&gt;The answer is another very important aspect that differentiates REST from any other architectural style for distributed systems. The set of methods that you can invoke is fixed. Every object supports the same interface. In RESTful HTTP, the methods are the HTTP verbs—most importantly, GET, PUT, POST, DELETE—that can be applied to resources.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;B.2.3 - Hyper-media as the Engine of Application State (HATEOAS)&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Finally, a RESTful server enables a client to discover a path through the application’s possible state transitions by means of hypermedia. This is called Hyper-media as the Engine of Application State (HATEOAS) in Fielding’s dissertation. &lt;strong&gt;Put more simply, the individual resources don’t stand on their own. They are connected, linked to each other. This should not come as a surprise. After all, this is where the Web got its name. For the server, this means that it will embed links in its answers, enabling the client to interact with connected resources.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;B.3 - Key aspects of a RESTFull HTTP Client&lt;/strong&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;A RESTful HTTP client moves from one resource to the next either by following links contained in resource representations or by being redirected to resources as a result of sending data for processing to the server. Server and client cooperate to influence the client’s distribution behavior dynamically. As a URI contains all information necessary for dereferencing an address—including host name and port—a client following the hypermedia principle might end up talking to a resource hosted by a different application, a different host, or even a different company.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;C. Why REST ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;a system designed conforming to REST principles fulfills the&lt;br&gt;
promise of loose coupling. In general, it’s very easy to add new resources and links to them in existing resource representations. It’s also easy to add support for new formats where needed, leading to a much less brittle set of system connections. A REST-based system is much easier to understand, as it’s split into&lt;br&gt;
smaller chunks—the resources—each of which exposes a separately testable, debuggable, and usable entry point. The design of HTTP and the maturity of the tooling with support for features such as URI rewriting and caching make RESTful HTTP a great choice for architectures that need to be both loosely coupled and highly scalable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Owh by the way good year 2025 😊!&lt;br&gt;
See you next time 😁&lt;/p&gt;

</description>
      <category>programming</category>
      <category>architecture</category>
      <category>softwaredevelopment</category>
      <category>softwareengineering</category>
    </item>
  </channel>
</rss>
