Managing Database Connections in a Microservice Architecture with Django

I am designing a microservice architecture using Django and I have encountered a major challenge in data management. I would appreciate it if you could share your experience and perspective. We have several separate services, each with its own database. For example:

Core service: Responsible for managing core models such as User and uses the db_core database. WebSocket service: Responsible for managing real-time communications and uses the db_websocket database. Main challenge: How can we best manage the data connection between these two services? This challenge has two aspects:

  1. Read Access: The WebSocket service needs to read information from the User model of the Core service to authenticate the user (when connecting) or display his information (for example, the user's name next to a chat message). What is the correct approach for this?
  2. Managing Cross-Database Relationships: This challenge is more complex. Suppose we have a ChatMessage model in the WebSocket service that requires a ForeignKey to the User model in the Core service. Since it is not possible to create a FOREIGN KEY constraint between two physical databases, what is the recommended pattern for implementing this logical relationship?
Вернуться на верх