Microservice architecture design pattern-(11) query

Two modes

  • API composition model
    • Call multiple services to obtain data and then combine it into what you want
    • accomplish
      • API composition is done by the front end
        • The front end directly calls multiple services to query information
        • The front end is too heavy
      • API composition is done by the gateway
      • API composition as a standalone service
    • benefit
      • Simple and intuitive
    • Disadvantages
      • add extra overhead
      • Reduced availability
        • Because multiple services need to be called, and the availability of each service is 99.5%, then if the data of 4 services is to be aggregated, the service availability of the combiner becomes 97.5% (0.995^5, it is also a service in itself)
        • If you want to improve availability, turn some services intonon-blockingYes
          • If a service is unavailable, just ignore it and return incomplete data. In this way, other useful information can be displayed on the user page without directly reporting an error.
            • Of course, when this service is unavailable, maintenance personnel can be notified through monitoring alarms.
      • Lack of transactional data consistency
        • During the execution of the transaction, some parts of the query have been updated, and some have not yet been updated.
  • CORS mode
    • Command query separation of duties
    • Use events to maintain read-only views copied from multiple databases for querying
    • benefit
      • Efficient
        • No need to consume memory and network like API combination
      • Different types of query implementations
        • For example, there is a service that uses a NoSQL database and cannot support queries very well. Then using CQRS to build a dedicated query database at this time can solve this problem very well.
          • Another example is parsing MySQL's json data into fields that query the database.
      • Event source query
        • The information stored in the event is placed in the json of event_data, which is not conducive to querying. Functional query event ID or aggregate ID. Use CQRS to construct one or more latest views, which can be queried very well
      • isolation
        • Isolate commands and queries
    • Disadvantages
      • complex architecture
      • Need to deal with delays caused by data replication
        • How to solve
          • Let the client record the latest event ID tag
          • Then bring it with you when querying. If the query view has not been updated and the ID cannot be found, an error will be reported.
          • Because the function ensures that the data is ultimately consistent.

Guess you like

Origin blog.csdn.net/u014704998/article/details/128997361