当前位置:网站首页>无状态与有状态的区别
无状态与有状态的区别
2022-07-31 22:22:00 【热爱编程的小宇】
无状态与有状态
- 有状态服务
有状态服务,即服务端记录每次会话的客户端信息,从而识别客户端身份,根据用户身份进行相应的处理。
- 无状态服务
明白了有状态服务,无状态服务就好理解了,无状态服务在实际比较常见的实现是采用基于令牌的方式,即:
- 服务端不保存任何客户端会话信息;
- 客户端的每次请求必须携带令牌,其中包含了认证者、签名相关信息(用户名、角色、权限等);
传统的session认证方式存在的问题
HTTP
本身是无状态的,短连接,因此便有了我们传统的 Cookie-Session 模式,这在单体架构中广泛使用。用户完成登录后,与用户的会话信息被保存在服务端的Session
中,然后服务端响应一个SessionID
给前端,前端将这个SessionID
存储在Cookie
中,后续请求携带Cookie
信息继续发起请求,后端再查询其对应的会话信息,完成请求响应。
这种方式会带来一些问题:
- 性能:每建立一个会话,服务端就需要存储这个会话信息,增加了服务端存储、查询的压力,占用了宝贵的存储、计算资源;
- 扩展性:服务端保存用户状态,难以进行水平扩展,微服务环境下需要在各服务器上进行状态的复制、同步(Session同步、Session共享)等处理后才能进行扩展;
- CSRF攻击:因为该方式是基于 cookie 来进行用户识别的,如果 cookie 被截获,用户以及服务器就会受到跨站请求伪造的攻击;
- 跨平台:在移动应用上 session 和 cookie 很难行通,你无法与移动终端共享服务器创建的 session 和 cookie。
解决办法:
边栏推荐
- 信息学奥赛一本通 1941:【07NOIP普及组】Hanoi双塔问题 | 洛谷 P1096 [NOIP2007 普及组] Hanoi 双塔问题
- Basic Grammar Introduction of Carbon Tutorial (Tutorial)
- 【ACM】2022.7.31训练赛
- GateWay implements load balancing
- 「SDOI2016」征途 题解
- 老牌音乐播放器 WinAmp 发布 5.9 RC1 版:迁移到 VS 2019 完全重建,兼容 Win11
- Audio alignment using cross-correlation
- JS basic exercises
- 财务盈利、偿债能力指标
- The article you worked so hard to write may not be your original
猜你喜欢
ReentrantLock原理(未完待续)
架构实战营模块 8 作业
How to identify fake reptiles?
Memblaze发布首款基于长存颗粒的企业级SSD,背后有何新价值?
[Code Hoof Set Novice Village 600 Questions] Leading to the combination of formulas and programs
Getting Started with Tkinter
Pytest first experience
MATLAB program design and application 2.4 Common internal functions of MATLAB
A high-quality WordPress download site template theme developed abroad
[NLP] What is the memory of the model!
随机推荐
Thymeleaf是什么?该如何使用。
focus on!Haitai Fangyuan joins the "Personal Information Protection Self-discipline Convention"
"SDOI2016" Journey Problem Solution
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"
基于STM32 环形队列来实现串口接收数据
uni-app中的renderjs使用
Flex layout in detail
Redis Overview: Talk to the interviewer all night long about Redis caching, persistence, elimination mechanism, sentinel, and the underlying principles of clusters!...
Basic Grammar Introduction of Carbon Tutorial (Tutorial)
Payment module implementation
Shell script quick start to actual combat -02
MySQL数据库‘反斜杠\’ ,‘单引号‘’,‘双引号“’,‘null’无法存储
Unity - LineRenderer show a line
STM32 full series development firmware installation guide under Arduino framework
cas and spin locks (is lightweight locks spin locks)
Implementation of a sequence table
Book of the Month (202207): The Definitive Guide to Swift Programming
【论文精读】iNeRF
LeetCode 第 304 场周赛
Architecture Battalion Module 8 Homework