Microservices: how to handle foreign key relationships

前端 未结 4 2094
温柔的废话
温柔的废话 2021-01-29 20:14

Microservices architecture suggest that each service should handle it\'s own data. Hence any service (Service A) dependent on data owned by other service (service B) should acce

4条回答
  •  星月不相逢
    2021-01-29 20:55

    When distributing your code to achieve reduced coupling, you want to avoid resource sharing, and data is a resource you want to to avoid sharing.

    Another point is that only one component in your system owns the data (for state changing operations), other components can READ but NOT WRITE, they can have copies of the data or you can share a view model they can use to get the latest state of an object.

    Introducing referential integrity will reintroduce coupling, instead you want to use something like Guids for your primary keys, they will be created by the creator of the object, the rest is all about managing eventual consistency.

    Take a look at Udi Dahan's talk in NDC Oslo for a more details

    Hope this helps

提交回复
热议问题