Stateless vs StateFul server

  • 區別

    A stateless system can be seen as a box [black? ;)] where at any point in time the value of the output(s) depends only on the value of the input(s) [after a certain processing time]
    A stateful system instead can be seen as a box where at any point in time the value of the output(s) depends on the value of the input(s) and of an internal state,so basicaly a stateful system is like a state machine with "memory" as the same set of input(s) value can generate different output(s) depending on the previous input(s) received by the system.

  • Example:file system

    Stateful: server maintains information about client operations such as open mode, file offset, etc
    Stateless: client should send self-containing request to server

  • Example:web server
  1. COOKIE
    其實一般的cookie已經屬于是stateful了,但是很多web server借助類似于redis這些來實現全局session,所以可以簡單認為這種web server是stateless的,因為request可以到任何一臺機器;
  2. Transaction
    A stateless service is a service that does not store any data on the application
    server. It reads or writes data to the database, returns a value (or not), and after
    that, any information on the task itself is forgotten.
    A stateful service is used to perform transactions, that is a series of tasks that depend on the result of preceding tasks. The easiest example is sending an order at a web store, where you gather your products in a shopping cart, and when you check out, you enter your account data on one page, store it, then enter your billing address, store it, then confirm your order and conclude the transaction. Each step depends on the successful outcome of the preceding step, and data needs to be preserved until the last one of these steps is completed or the transaction is canceled, in which case there has to be a rollback to restore your account balance to the way it was before you checked out.
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容