How to implement "foreign key" using Micro Services architecture? Django

1

I am trying to build a system using the micro services architecture, I came across the problem about dependency, in the case how to implement chave estrangeira using this architecture? I'm using Django

Example

The class pedido that will be a service is bound to a client, which will also be service, how to implement this in microservic architecture since both are physically decoupled?

I would normally declare it like this

class Pedido:
    cliente = models.ForeignKey(Cliente)   

and would access a client for an order like this:

p = Pedido.objects.filter().first()
p.cliente.nome

Using the miroservic architecture I could not declare this way since the Cliente class would not exist in the Pedido service

    
asked by anonymous 25.04.2016 / 22:57

1 answer

3

Do not take this issue too hard to uncover because you run the risk of doing it in the wrong place. Try to bring the idea of micro service to the real world and see what happens. Imagine the following situation:

  • You enter a restaurant and sit at a TABLE;
  • The waiter comes and takes the ORDER and notes the number of the MESA;
  • The waiter takes the REQUEST to the kitchen that prepares the REQUEST and touches the bell when the ready;
  • The waiter serves the dish on the table;
  • You consume the ORDER and ask the waiter for the ACCOUNT;
  • The waiter goes to tea the box, asks the ACCOUNT and hands you;
  • You go to the box , pay the ACCOUNT and it goes away.
  • Please note that in this case the micro services are represented by waiter , kitchen and box .

    The waiter does not know anything about making food, the kitchen does not know anything about serving and the box only knows what it has to charge, meaning they are DISABLED and work independently.

    But see that they all have the vision of the customer (represented by MESA) and the REQUEST. Here it is very clear that you should not separate these entities and what happens in this type of architecture is the REDUNDANCE of the data because each service must have a copy of the REQUEST with the number of the MESA.

    So, although independent and asynchronous microservices have to store the same information and to ensure this has to have a form of efficient communication (sockets is a good example).

    If you read the Martin Fowler article you will see which he recommends starting monolithic himself and creating micro services only when needed. Doing so at the beginning is a waste of time.

        
    06.06.2016 / 15:27