Search code examples
database.net-corearchitecturemicroservicessoa

Service Oriented Architecture: Foreign Key Across Different Databases


We are implementing Services Oriented Architecture (SOA). We have different service databases for each, Customer Management, Orders, Shipping, Refunds. What is strategies to maintain foreign key relationships across tables in different databases (since cross database foreign keys are not allowed in SQL Server)? Should foreign keys be substituted with business API rules?

This is not Microservices; where database information is replicated in each arena, but SOA. We did not want put everything in 1 database, since different backup maintenance hours, did not want deadlock/runaway query to bring down all services. Service Oriented Architecture does not dictate if we should have 1 database or multiple.


Solution

  • You can use a Guid(UUID) as the key of your entities, generated by the creator and then you can use that Guid across databased and tables to reference the entity in question.

    for example, when you create a new order, the ui will generate the order's Id, send a message to the component creating the order, the component will then publish an event using that orderId so that the other components can do related work to that order without accessing the database to get that id.

    Make sense?