Microservice Patterns - 3.4 Interprocess communication in a microservice architecture - Using asynchronous messaging to improve availability


Reference

  • synchronous communication with other services as part of request handling reduces application availability
  • As a result, you should design your services to use asynchronous messaging whenever possible

Synchronous communication reduces availability
  • Problem of "Use REST for inter-service communication" is "it's synchronous protocol"
  • Synchronous protocol => Reduce availability
  • If you want to maximize availability, you must minimize the amount of synchronous communication.

Eliminating synchronous interaction
ways to reduce the amount of synchronous communication with other services while handling synchronous requests
  • defining services that only have asynchronous APIs (but  public APIs are commonly RESTful)

USE ASYNCHRONOUS INTERACTION STYLES

REPLICATE DATA
  • If a service has a synchronous API, one way to improve availability is to replicate data
  • A service maintains a replica of the data that it needs when processing requests.
  • It keeps the replica up-to-date by subscribing to events published by the services that own the data
  • Drawback
    • it can sometimes require the replication of large amounts of data, which is inefficient.
    • it doesn’t solve the problem of how a service updates data owned by other services

FINISH PROCESSING AFTER RETURNING A RESPONSE
handle a request as follows: 
  1. Validate the request using only the data available locally.
  2. Update its database, including inserting messages into the OUTBOX table.
  3. Return a response to its client.
it asynchronously sends messages to other services

Drawback:
  • makes the client more complex


沒有留言:

張貼留言

別名演算法 Alias Method

 題目 每個伺服器支援不同的 TPM (transaction per minute) 當 request 來的時候, 系統需要馬上根據 TPM 的能力隨機找到一個適合的 server. 雖然稱為 "隨機", 但還是需要有 TPM 作為權重. 解法 別名演算法...