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.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容