How to Reference a User Entity from Another Microservice in ASP.NET Core?

In my microservices architecture using ASP.NET Core, I have two distinct microservices: Identity.API for user management and PersonalAccount.API for handling personal account-related functionalities. Each microservice operates with its own separate database. In PersonalAccount.API, I have a Project entity with a ManagerID field intended to reference a User entity from the Identity.API microservice.
Since Identity.API and PersonalAccount.API are separate projects and databases, there is no direct database-level foreign key constraint possible between them. This situation creates challenges in managing and validating the reference to a user across microservices. I’m seeking guidance on the best approach to handle such cross-service references, ensure data consistency, and maintain integrity between these microservices.

I attempted to use a foreign key approach between the ManagerID in the PersonalAccount.API and the User entity in the Identity.API. However, this approach is not feasible due to the microservices being in separate databases and not sharing a direct connection.
Instead, I considered having PersonalAccount.API make HTTP requests to Identity.API to validate the ManagerID. I expected that by implementing a service-to-service communication mechanism, I would be able to validate the ManagerID and ensure it references a valid User in Identity.API.
What actually resulted was a more complex implementation involving additional service calls and potential performance overhead. I am now looking for a more streamlined approach to manage this cross-microservice reference effectively.

New contributor

Medina Abasova is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

I can really recommend the whole microsoft learn course “.NET Microservices: Architecture for Containerized .NET Applications” at https://learn.microsoft.com/en-us/dotnet/architecture/microservices/ which is also available as a pdf download

More specifically, you asked about How to achieve consistency across multiple microservices and microsoft unmistakably says “No microservice should ever include tables/storage owned by another microservice in its own transactions, not even in direct queries”

That said I see two possible solutions:

  1. the synchronous pattern (that you already designed by making HTTP requests to Identity.API) guarantees consistency but has the overhead and may have performance implications
  2. the asynchronous way would be working with eventual consistency by using an event-based communication

Edit: You should also read Identify domain-model boundaries for each microservice on how to store and work with data owned by another microservice (bounded context)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật