Transactions across REST microservices?

前端 未结 11 1901

Let\'s say we have a User, Wallet REST microservices and an API gateway that glues things together. When Bob registers on our website, our API gateway needs to create a user

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 15:05

    In micro-services world the communication between services should be either through rest client or messaging queue. There can be two ways to handle the transactions across services depending on how are you communicating between the services. I will personally prefer message driven architecture so that a long transaction should be a non blocking operation for a user. Lets take you example to explain it :

    1. Create user BOB with event CREATE USER and push the message to a message bus.
    2. Wallet service subscribed to this event can create a wallet corresponding to the user.

    The one thing which you have to take care is to select a robust reliable message backbone which can persists the state in case of failure. You can use kafka or rabbitmq for messaging backbone. There will be a delay in execution because of eventual consistency but that can be easily updated through socket notification. A notifications service/task manager framework can be a service which update the state of the transactions through asynchronous mechanism like sockets and can help UI to update show the proper progress.

提交回复
热议问题