API 异步 & 同步的决策树

2018-08-03  本文已影响27人  魔镜的技术心经

定义

Synchronous: A business transaction done in a single HTTP request/response exchange, which means that the HTTP response provides all data and associated resources resulting from the transaction

Asynchronous: A business transaction done over multiple HTTP request/response exchanges, which means that the initial HTTP response does not provide all data and associated resources resulting from the transaction, such data and resources can be obtained in subsequent interactions.

问题域

HTTP是一个同步协议:

一些情况下,这种同步-blocking的通信方式,并不适合,比如以下的场景:

方法域

异步模式:

  1. Web hook
    web hook.png

2.Asynchronous Notification

async-notification.png

什么时候使用异步呢?

  1. 根据HTTP操作来判断
  1. 根据响应时间来判断

辅助决策树

Sync & Async decision tree .png

异步参考资料

[1]I cannot have my users wait on the API on finish
[2]http://jsonapi.org/recommendations/#asynchronous-processing

上一篇下一篇

猜你喜欢

热点阅读