I have a couple of web applications that write to their own databases. They also share a few entities, for example, the customer entity. My business case is such that the same field for the same record can be updated around the same time in both the applications. It brings in dual sources of truth. How can one ensure data consistency and integrity in such a scenario? What's the best integration architecture to work with here? Is optimistic concurrency achievable in such a distributed architecture with multiple databases? What are some architectural ideas/themes that one could explore here to ensure that we have some form of data consistency going on even if the consistency model needs to be eventual?

What complicates matters here a bit is that both of the web applications are SaaS applications who's read and write APIs to their databases are tightly coupled to their respective front end UIs. So, it is difficult to decouple the UI from the database and segregate the read and write pipelines to maybe read and write from a distributed commit log in a event sourcing based architecture.

Any help here would be deeply appreciated. Thanks in advance...


There are multiple ways to go about solving the issue of having distributed entities.

Avoiding it

You could make sure the customer entity only exist in one place and have the other parts of the system modify it. It could be done by having a microservice for the customer entity.


Instead of modifying the entity directly, you could trigger an event that is consumed in a central place. It will require more infrastructure but it will give you the benefit of having an ordering of the changes that can be observed.

A more in-depth walkthrough https://medium.com/better-programming/event-driven-architecture-as-a-strategy-dfb8370724c9

Saga pattern

It is probably overkill for you case, but it is a way to ensure consistency in a distributed system. https://microservices.io/patterns/data/saga.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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