Microservice database and relationships between them

0

I'm working on an application on Python using the Flask framework. It is oriented to microservices and each one has its own database. I am currently in the process of creating the models of one of the microservices using Flask-SQLAlchemy.

The issue is that, as is obvious, in the database of this microservice (responsible for managing incidents) there is a point of connection with another (responsible for managing applications) which is a table that relates both. However, I do not know how to design this relationship because the applications are outside the scope of the incident microservice.

Some colleagues have suggested to me that the ORM has a notion of all the databases, that it models all the entities and relationships and that the microservices can access the relationships that only concern them. However, I think that, in the long term, it is not a good idea given that, in the case that there is a microservice team, everyone would have a notion of all the databases when really they should only be interested in their microservice.

Others have recommended me to simulate the relationship by creating another model like the ones that appear later. In my view that is not correct since it is a relationship and not a model. It is true that solves the problem but not in the right way.

Some code to see the problem:

from base_class_sql import BaseModel
from app.models.emergency_alch_sql import Emergency
from main import db

class Incident(BaseModel, db.Model):

    __tablename__ = 't_incident'

    incident_id = db.Column(db.String(20), primary_key=True)
    incident_parent_id = db.Column(db.String(20))
    emergency_id = db.Column(db.ForeignKey(u't_emergency.emergency_id'), nullable=False, index=True)
    summary_incident = db.Column(db.String(200))

    # relaciones con otros modelos
    emergency = db.relationship('Emergency')

# t_inc_app es la tabla que relaciona las incidencias con las aplicaciones
inc_apps = db.Table('t_inc_app',
    db.Column('incident_id', db.String, db.ForeignKey('Incident.incident_id'), primary_key=True),
    db.Column('app_id', db.String, primary_key=True),   # columna extraida del microservicio de aplicaciones
    BaseModel.created_audit_date,
    BaseModel.updated_audit_date,
    BaseModel.user_audit_id
)

In this case, the entity Emergency can be related without problems to the entity Incident given that both exist in the same database. However, inc_apps can not be related by the function db.relationship() since inc_apps is an instance of the class db.Table and not% db.Model .

I understand that this problem is quite common working with microservice databases only that it is not I know how to create the relationship M to N when really the app_id does not matter from the point of view of the microservice of incidences.

    
asked by cpinamtz 02.01.2019 в 12:41
source

0 answers