0

Context

Hello, at my company we have been working with DDD for some time now. We have a monolith and some services. The bounded contexts in the monolith use HTTP calls to communicate between them or data replication/projections when it's needed. Now we have a case where we think we have two bounded contexts, but there are a significant amount of dependencies.

This part of the domain is based on CRM integration. We have an API to store Objects and Records (same behaviour as a CRM, but our implementation):

  • The aggregate Object is an arbitrary object in a CRM (with configurable fields, etc)
  • The aggregate Record is an instance of an Object.

It may seem I'm talking about OOP, but I'm not. This is the ubiquitous language in our CRM (and in others too, like Salesforce). For instance, Account would be an Object, and a specific account, would be a Record of the Object Account. Now, both Object and Record aggregates, are part of the RecordsBC bounded context. The RecordsBC contains the business logic of our own CRM-like implementation.

Due to the fact, that we are also an integration company, we also have a bounded context named CRMIntegrationBC, where our customers can choose to replicate their CRM data inside our application, keeping them synced. This is not mandatory, so one of our clients can be connected or not to a CRM.

As described, our business processes between these two bounded contexts are more or less like this:

enter image description here

So, for CRUD-related operations in the RecordsBC, if the company is integrated, we also need to replicate the data there, using the CRMIntegrationBC. We do this synchronously because we think introducing events for this is going to increase the complexity too much (we are not event-driven yet).

Question

So, I have some questions about how to model this:

Q1: Should RecordsBC and CRMIntegrationBC be separate bounded contexts?

From the beginning, I assumed they should be, because it seems the logic is quite different:

  • RecordsBC handles our own CRM business rules and features.
  • CRMIntegrationsBC handles CRM-integration things like how many users you can integrate, what objects, etc.

Nonetheless, given the high coupling between their use cases, I'm unsure about this fact.

Q2: If they indeed should be separate BC, how should communication take place?

Both of these modules live in our monolith, and we want to avoid direct import statements. For that reason, we thought that we would use a REST API to communicate with both contexts:

  • To create a Record, our web/mobile clients would call POST /api/records, which would trigger the application service of creating a record in RecordsBC, which would handle the communication with CRMIntegrationsBC. Something like:
class CreateRecordService:
    def run(self, user_id, record):
        self._do_some_validation()
        # HTTP call to the API of CRMIntegrationBC
        if self._user_is_crm_integrated(user_id):
             # HTTP call to the API of CRMIntegrationBC
             self._create_record_in_crm(user_id, record)
        self._create_record(user_id, record)

Notes

Our tech stack consists of a Django monolith and some other different services (mainly fast API, and some NodeJS servers). Our BCs are set as follows:

src/
   shared_kernel/ # things like aggregate IDs and such
   RecordsBC/
       application/
       domain/
       infrastructure/
   CRMIntegrationsBC/
       application/
       domain/
       infrastructure/
9
  • You seem to be using BC to mean "a sub set of my code base" rather than "the language dept A uses to talk about their processes". How are you implementing the BCs? is it just that when you send a message via HTTP you count that as a BC boundary?
    – Ewan
    Commented May 18 at 14:57
  • Mm, interesting. We are implementing BC as isolated parts of our business, that's why I think they are different BC. We offer a CRM-like app, without the need to have a CRM. Nonetheless, we also offer a CRM integration. For the technical setup of the BCs, see my latest update to the Notes section. Commented May 18 at 15:06
  • are they both web apps or does the user download them and run them locally?
    – Ewan
    Commented May 18 at 17:42
  • Both are part of our monolith right now, exposed through a REST API. The user only needs to interact with the RecordsBC api (and we using other back office front ent, setup the integration using both BCs) Commented May 18 at 17:47
  • 1
    Are you asking about DDD? I don't think you have a need for BCs, it sounds like you have one or two apps and they do separate things one BC or two makes no difference. Its not like you have dept 1 says CRM = one thing and dept two says CRM to mean something else
    – Ewan
    Commented May 18 at 19:19

1 Answer 1

1

Q1: Should RecordsBC and CRMIntegrationBC be separate bounded contexts?

I am not convinced that they represent different bounded contexts, but it it makes the architecture of your system easier, they can certainly be different modules that each listen to their own (internal) API.

Q2: If they indeed should be separate BC, how should communication take place?

Assuming you use HTTP communication between the two modules (or contexts if you decide so), the check if a user is connected to an external CRM should be done within the CRMIntegrationBC module. That keeps the logic nicely contained.

If you support multiple CRMs to integrate to, you could even arrange that a POST /CRMIntegrationBC/<user_id>/create is responded to with a 3xx redirection response giving the actual CRM type that the user is connected to. For a non-connected user, that external CRM type would be a dummy implementation that simply discards all incoming data and replies with 404 on all data requests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.