I'm playing around with DDD, and in particular in cases that involve remote service calls. I'm building a system where the user records are actually backed by Cognito, so I've got to work with the Cognito IdentityProvider SDK instead of a local database.
In terms of just loading and saving data, that's pretty easy. I've just got a Repository concept that is itself backed by the IdentityProvider SDK, so from the outside it works the same as if it was a local database.
Where I'm getting conflicted is how best to architect the other parts of the system. For example, changing the users password.
The flow for this is:
- Load the user details.
- This involves a call to the
AdminGetUser
action on the IdentityProvider SDK.
- This involves a call to the
- Check if the user has MFA enabled.
- If so, verify the provided MFA token in the API request.
- This is a call to the
AdminRespondToAuthChallenge
action on the IdentityProvider SDK.
- Actually change the password.
- This is a call to the
ChangePassword
action on the IdentityProvider SDK.
- This is a call to the
It seems that there are at least three ways that this can be structured:
- The User Entity itself is able to make remote calls.
- The Application Service makes remote calls.
- There are Domain Services that make remote calls, and the Application Service uses these.
I've asked elsewhere about #1 and have been recommended that the User Entity shouldn't be doing anything itself that directly impacts other systems.
#3 feels slightly cleaner - it means that there are domain concepts within the application for these things, and the making of remote calls is hidden behind those. However, it feels like this is just a lot of extra layers to achieve this. In particular, it ends up something like this:
So we have three different components that each have the SDK Client in them, all three of which are then in the same Application Service.
Is this the recommended way? Is there a better recommended way to structure this? Am I just massively over-thinking things? :)
Cheers