当前位置:网站首页>无状态与有状态的区别
无状态与有状态的区别
2022-07-31 22:22:00 【热爱编程的小宇】
无状态与有状态
- 有状态服务
有状态服务,即服务端记录每次会话的客户端信息,从而识别客户端身份,根据用户身份进行相应的处理。
- 无状态服务
明白了有状态服务,无状态服务就好理解了,无状态服务在实际比较常见的实现是采用基于令牌的方式,即:
- 服务端不保存任何客户端会话信息;
- 客户端的每次请求必须携带令牌,其中包含了认证者、签名相关信息(用户名、角色、权限等);
传统的session认证方式存在的问题
HTTP
本身是无状态的,短连接,因此便有了我们传统的 Cookie-Session 模式,这在单体架构中广泛使用。用户完成登录后,与用户的会话信息被保存在服务端的Session
中,然后服务端响应一个SessionID
给前端,前端将这个SessionID
存储在Cookie
中,后续请求携带Cookie
信息继续发起请求,后端再查询其对应的会话信息,完成请求响应。
这种方式会带来一些问题:
- 性能:每建立一个会话,服务端就需要存储这个会话信息,增加了服务端存储、查询的压力,占用了宝贵的存储、计算资源;
- 扩展性:服务端保存用户状态,难以进行水平扩展,微服务环境下需要在各服务器上进行状态的复制、同步(Session同步、Session共享)等处理后才能进行扩展;
- CSRF攻击:因为该方式是基于 cookie 来进行用户识别的,如果 cookie 被截获,用户以及服务器就会受到跨站请求伪造的攻击;
- 跨平台:在移动应用上 session 和 cookie 很难行通,你无法与移动终端共享服务器创建的 session 和 cookie。
解决办法:
边栏推荐
- 一款国外开发的高质量WordPress下载站模板主题
- UVM RAL model and built-in seq
- 架构实战营模块 8 作业
- Payment module implementation
- "The core concept of" image classification and target detection in the positive and negative samples and understanding architecture
- [NLP] What is the memory of the model!
- find prime numbers up to n
- A shortcut to search for specific character content in idea
- sqlite3简单操作
- Fixed-length usage of nanopb string type based on RT1052 Aworks (27)
猜你喜欢
[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
Daily practice——Randomly generate an integer between 1-100 and see how many times you can guess.Requirements: The number of guesses cannot exceed 7 times, and after each guess, it will prompt "bigger"
ThreadLocal
Realize serial port receiving data based on STM32 ring queue
PCB stackup design
Financial profitability and solvency indicators
The article you worked so hard to write may not be your original
[Intensive reading of the paper] iNeRF
Payment module implementation
Flex layout in detail
随机推荐
关注!海泰方圆加入《个人信息保护自律公约》
网易云信圈组上线实时互动频道,「破冰」弱关系社交
Document management and tools in the development process
Efficient Concurrency: A Detailed Explanation of Synchornized's Lock Optimization
[Intensive reading of the paper] iNeRF
[Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
iNeuOS industrial Internet operating system, equipment operation and maintenance business and "low-code" form development tools
Basic configuration of OSPFv3
What's wrong with the sql syntax in my sql
#yyds干货盘点# 面试必刷TOP101:链表中环的入口结点
Embedded development has no passion, is it normal?
利用反射实现一个管理对象信息的简单框架
BOW/DOM (top)
Payment module implementation
Realization of character makeup
The whole network is on the verge of triggering, and the all-round assistant for content distribution from media people - Rongmeibao
Fixed-length usage of nanopb string type based on RT1052 Aworks (27)
One thing to say, is outsourcing company worth it?
Chapter VII
Socket回顾与I/0模型