## Notify user in event driven architecture

We have set up an account service management: its responsibility is to let a user register on his account, confirm his email, etc …

We have also implemented a process layer which is responsible for notifying the user when their account is changed.

Notifications are carried out by a notification service which is decoupled from our account service and which informs the user on the basis of an event mechanism.
Here is an overview of the principle:

As a new requirement, our client wants us to send a reminder every 2 hours to the user now for any notification.
For example if the account is not yet confirmed, we will send the user an email notification asking them to confirm their account 2 hours later …
The team in charge of the UserNotification service, thinks that it is not their responsibility to manage this because they have a stateless process and do not know the status of the account for example.
They therefore request that the account management service trigger an "AccountStillNotConfirmed" event to request the notification every two hours:

The alternative is to make the user notification complete, or at the very least ask the account service for a list of "not yet confirm account" every two hours and send a notification if necessary.
The "AccountStillNotConfirmed" event seems strange to me.
I am looking for the cleanest way to solve this problem.

which architecture would be better for you and why?
Is there another way to meet the needs of our customers?

## unit tests – Entity Framework and Domain Driven Design Testability

I use a DDD approach for domain classes. Although I have a problem with my design, that I manage it now but that I have not had a good idea to address it.

My architecture is as follows:

– Heart

• Application(here i have a bunch of commands / queries which use domain entities and CQRS to handle use cases)
• Field

-Services

-Infrastructure

-Presentation

My problem is based on the following. I have a class called template that implements the ITemplate interface. This interface implements several methods and properties. As we can see above

`````` public interface ITemplate
{
public int Id { get; set; }
string Name { get; set; }

string Definition { get; set; }

ISource Source { get; set; }

ITemplateDefinition GetTemplateDefinitionObject();

void SetTemplateDefinition(string templateDefinitionString);
}
``````

Inside an order, placed on the Application folder, I have the following:

``````public async Task Handle(UpdateTemplateCommand request, CancellationToken cancellationToken)
{
var templateDto = request.Template;

var sourceForTemplate = await SourceRepository.SingleAsync(x => x.Id == templateDto.SourceId);

if (sourceForTemplate == null)
{
throw new NotFoundException(nameof(Domain.Entities.Source), request.Template.SourceId);
}

var templateToUpdate = await TemplateRepository.SingleAsync(x => x.Id == templateDto.Id);

if (templateToUpdate == null)
{
throw new NotFoundException(nameof(Domain.Entities.Template), request.Template.Id);
}

if (!string.IsNullOrEmpty(templateDto.Definition))
{
try
{
**templateToUpdate.SetTemplateDefinition(templateDto.Definition);**
}
catch (Exception e)
{
throw e;
}

}
``````

TemplateRepository.UpdateRFEntity ((Domain.Entities.Template) templateToUpdate);

The line with the surrounding ** is my problem.

When Unit tests this, I cannot simulate it because the repository returns a concrete implementation and not an interface, which, in my opinion, is the right way, because when it comes to an ORM like EF, with the ability to track entities and other mechanisms, we shouldn't let go of that by mapping responses to an interface.

Does anyone have any idea how to make it cleaner so you can make fun of class calls without needing to make the members virtual, because i already have an interface, and without having to transpose all responses to the interface?

## domain driven design – Where to place the value object code shared by multiple aggregation roots?

I have 2 aggregate root:
One is the `Lessor` user, and the other is the `Lessee` user.

``````class Lessor extends AggregateRoot {}

class Lessee extends AggregateRoot {}
``````

Each of these aggregated roots has a `email` , it is a valuable item.

``````class Email extends ValueObject { }
``````
``````class Lessor extends AggregateRoot {
private email: Email
}

class Lessee extends AggregateRoot {
private email: Email
}
``````

I do not share an instance of `Email`, I share the code of `Email`.

### Can i put the `Email` code in the `SharedKernel` folder?

• I didn't want to duplicate the `Email` code by placing it in the`Domain` folders of each aggregated root.
• And don't even put the `Email` code in one of the aggregated roots and import it into the other.

## Are the increments of a stochastic process driven by fractional Brownian motion independent?

I am studying the following equation in the context of population dynamics
$$tag1 dX_t = mu X_t dt + sigma X_t dB ^ H_t$$
or $$B ^ H$$ is the fractional Brownian motion (fBm) of the Hurst parameter $$H in (0,1)$$, i.e. a continuous Gaussian process starting at zero, with $$B ^ H_t sim mathcal N (0, t ^ {2H})$$ and with covariance $$mathbb E (B ^ H_t B ^ H_s) = frac12 (| t | ^ {2H} + | s | ^ {2H} – | t-s | ^ {2H})$$.

According to the value of $$H$$

• if $$H = 1/2$$ then $$B ^ H$$ is the classic Brownian motion
• if $$H <1/2$$ then increments of $$B ^ H$$ are negatively correlated
• if $$H> 1/2$$ then increments of $$B ^ H$$ are positively correlated

Additionally, the increment process $$B ^ H_ {t + 1} -B ^ H_ {t}$$ is called fractional Gaussian noise (fGn) and has a covariance $$gamma (k) = frac12 (| k-1 | ^ {2H} -2 | k | ^ {2H} + | k + 1 | ^ {2H})$$.

To run numerical simulations, we must first find estimators for the parameters $$mu$$ and $$sigma$$.

Let $$f, g$$ to be two functions of $$X_t$$ and of $$theta$$, vector of unknown parameters. Consider
$$tag2 dX_t = f (X_t, theta) dt + g (X_t, theta) dB ^ H_t$$
the first and second moments of the increments of $$X$$ are given by
$$mathbb E (dX | X, t) = f (X_t, theta) dt$$
$$mathbb E ((dX) ^ 2 | X, t) = g ^ 2 (X_t, theta) (dt) ^ {2H}.$$

Partitioning $$(0, T)$$ as $$0 = t_0 s.t. $$Delta t = t_ {i + 1} -t_i = T / N$$, of the $$(2)$$ can be approximated by the Euler-Maruyama method as
$$tag3 X_0 = x_0, quad X_ {n + 1} = X_n + f (X_n, theta) Delta t + g (X_n, theta) Delta B ^ H_n$$
or $$Delta B ^ H_n = B ^ H_ {t_ {n + 1}} – B ^ H_ {t_n}$$ (in the mentioned article, $$Delta B ^ H_n$$ is not explicitly defined, but I guess the definition is the one I wrote here) is the fGn and $$0 le n le N-1$$.

The probability density function of $$(X_ {n + 1}, t_ {n + 1})$$ from $$(X_n, t_n)$$ is then
$$tag4 color {red} {p_X} = frac {1} { sqrt {2 pi g ^ 2 (X_n, theta) ( Delta t) ^ {2H}}} exp Bigg (- frac { (X_ {n + 1} -X_n-f (X_n, theta) Delta t) ^ 2} {2g ^ 2 (X_n, theta) ( Delta t) ^ {2H}} Bigg)$$
and the joint density gives the likelihood function $$mathcal L$$, whose maximizers are the parameter estimates $$mu$$ and $$sigma$$.

For the initial sde $$(1)$$ we have $$f (X_t, theta) = mu X_t$$ and $$g (X_t, theta) = sigma X_t$$, Therefore
$$tag5 color {red} { mathcal L ( mu, sigma) = prod_ {n = 0} ^ {N-1}} frac {1} { sqrt {2 pi sigma ^ 2X ^ 2_n ( Delta t) ^ {2H}}} exp Bigg (- frac {(X_ {n + 1} -X_n- mu X_n Delta t) ^ 2} {2 sigma ^ 2X ^ 2_n ( Delta t) ^ {2H}} Bigg)$$

The first question is related to the first $$color {red} { text {red}}$$ term: is the formula $$(4)$$ for the process increments pdf $$X$$, Defined by $$(3)$$, correct?

The second question is related to the second $$color {red} { text {red}}$$ term: is the formula $$(5)$$ for the joint density (likelihood function) of the process increments $$X$$, Defined by $$(3)$$, correct?

Regarding the second question, my doubt is that since the fBm increments are not independent, perhaps also the process increments $$X$$, Defined by $$(3)$$, piloted by the fBm are not independent. If that were the case, then we could not write the joint density of the increments of $$X$$ as the product of individual densities. How to prove if the increments of $$X$$ are independent or not?

## domain driven design – Is the repository model part of the concept of ports and adapters

By reading the blue book on page 152, we can find this:

(A repository) provides methods for adding and removing objects, which
encapsulate the actual insertion or deletion of data in the data store.
Provide methods that select objects based on certain criteria and return
fully instantiated objects or collections of objects whose attribute
the values ​​meet the criteria, thus encapsulating the actual storage and
query technology.

One of the advantages of the introduction of benchmarks is that:

They allow you to easily replace a dummy implementation, for use in
trial

Clear as rock water! I can use an interface to define the repository; implement it with many classes (i.e. an actual database, rather than a memory value for testing); inject one implementation or another using the DI engine.

On the other hand:

Hexagonal architecture (alias ports and adapters) divides a system into several
interchangeable loose coupling components, such as application
kernel, database, user interface, test scripts and interfaces
with other systems.

To me, this sounds like extending the concepts of the repository not just to a database. Do I have a notification port? Next, I will implement two adapters, one for RabbitMQ, another for Amazon SNS or a subject in memory.

Put me like this: a repository can be thought of as an adapter for the database port.

Am I missing something?

## Error handling in an event driven system

The context

I have two components A and B, which communicate through events.

B components are responsible for long-running background processes and listen to the following event:

startProcess (uniqueID)

Component A sends startProcess events.

The problem

I need the IDs sent by component A to be unique, because elsewhere component B breaks.

Possible solutions

When Component B receives an ID that has already been assigned to another background job, does not accept it and therefore rejects the launch of a new background process .

The problem here is that component A does not experience rejection, unlike an Http request response design, where the error is communicated via the response.

Question

Is there a better way to handle this, apart from component B which silently refuses to start a new process? A final solution would be to forget about the events and make this request / response. But in general, how do event systems handle this type of scenario?

Latest

What I'm doing right now is that component A is responsible for sending unique identifiers. Is this the solution I'm looking for?

## Domain Driven Design – Multiple Agreegate Root Updates for Immediate Consistency in DDD

I have an aggregated root named "Project". It has some basic attributes like name, duration, documents.

I have another aggregated root named "Task". It also has some basic attributes like name, duration, documents and more.

We have a scenario where a user can add more than 200 Tasks at project.

Creating a task list as one of the attributes of Project seems unlikely due to memory consumption.

However, we have another scenario where when the user adds a task and provides a duration, we must find the minimum date and maximum date in the task list and assign that duration to project

We can not use consistency here because we want the updates to be reflected immediately.

I thought about the approach below

`````` public class TaskService {
{
Project project = this.projectRepo.getProject(command.projectId);

projectRepo.save(project);
}
}
``````

Another approach

``````public class TaskService {
{
Project project = this.projectRepo.getProject(command.projectId);

projectRepo.save(project);
}
}

{
Date startDate;
Date endDate;

public void assignDuration(Duration duration, Project project)
{
this.startDate = duration.startDate;
this.endDate = duration.endDate;

if(this.startDate < project.startDate)
project.changeStartDate(this.startDate);

if(this.endDate > project.endDate)
project.changeEndDate(this.endDate);

}
``````

The reasons why the task list is not another Project attribute is memory and it is possible that more than one person can add tasks to the same project.

## domain driven design – Identifying delimited context in task management

I'm currently trying DDD with a sample application "Task Management System". This is not linked to a specific domain as such, it will be a generic application that can be used in any domain.

• The task can have a duration and be assigned to different roles or users.
• Each subtask can be assigned to one or more roles or users.
• The task can be sent for approval to another user or role.

Based on the knowledge above, I thought I had three related contexts.

b] Approval process – support domain

c] Roles, Users, Permissions – User Domain

Roles, users of the generic domain will have a different meaning in the field of tasks.
For example, a user in the User domain will be called as the creator / approver / assignee in the task domain. In the same way, the roles of the User domain will be called as the agent / manager role.

The data relating to the list of users, the roles will be assigned by an external system and the authentication will also be performed by an external system. The list of users and roles will be used for creating, assigning, and approving tasks.

Need clarity on the following points

• Have I clearly identified the delimited contexts?
• Am I right in separating users, roles in different contexts even if they are very important for creating tasks?
• Should the approval process be in a different context? I am confused on this part because it is actually very important and part of the task management.

## Software Engineering – Engine for a Football Manager type game (data driven, menu click)

A friend and I had started developing a football coach two years ago, but we finally messed it up because we ended up in a mess with the development of UI and the backup / loading.
The basic game loop of simulating games and moving days until the day of the match was already over. We also had an operational messaging system (for receiving messages that may require triggering decisions / events).
In our lack of knowledge, we tried to build the game in GameMaker2. This saved all the items (a team has 23 players, a league has 20 teams, there are several leagues) a nightmare. In addition, the development of the user interface (scroll bars, for example) took an incredible amount of our time and yet everything seemed relatively bland. In short: GameMaker2 did not seem to fit the type of game we wanted to build.
There must be a better engine / system to develop a manager-type game. Most of the game is in the menus, there is no critical time interaction passes.
Since we defined the project, I started to hold a legitimate position in software development and I acquired skills that I had not acquired before, such as knowledge of the basics of data and a great experience of Python.

It makes me look at the game again. Now, I see it as having a "data backend" and a point-and-click interface, with game design elements, such as hard decisions, events, and games. goals as the driving force in the middle.
We want attractive menus, in which players can set the training schedule, get ready for the day, chat with the players / leaders / whoever it is. The other necessity is the management of all data objects, which will be numerous. A league can easily hold 400 players, all of whom must have statistics, etc. I see a relational database for this, but maybe there is something smarter about game development?

## So my question is:

What's a proper engine / game development stack to develop real-time, data-loaded, click-menu type manager games like a football manager?