为什么状态是软件设计中最难的部分
ByteByteGo 文章解释状态为何是软件设计中最难的问题,并梳理开发者管理状态的多重策略。
中文处理结果
状态是系统保留的、以某种方式影响其功能的信息。例如,网站可能记录已登录的用户。文档编辑器记住当前文本。后台工作进程记录已完成和待处理的任务。数据库按需长期保存写入其中的记录。
任何有用的软件通常都需要管理状态,以实现其预期功能。难点在于:当请求重叠、服务器增加、机器故障、软件变更被部署时,仍要保持状态正确。
常见的建议往往是“让应用无状态”。但这一建议需要解释。它通常指让特定的应用服务器易于替换,同时把重要状态放在别处。它并不意味着完全没有状态。理解这样的架构,需要考察状态为何存在、谁拥有它,以及当它不可用时会发生什么。
在本文中,我们将探讨为什么状态是软件开发中最难的部分,以及开发者可以用来管理它的多种策略。
什么是状态?
阅读更多
原始正文摘录
Why State is the Hardest Thing in Software Design
State is the information a system retains that affects its functionality in some way. For example, a website might keep track of users who have logged in. A document editor remembers the current text. A background worker logs which tasks it has completed and which ones are pending. A database stores the records written to it for as long as needed.
Any useful software usually needs to manage state to carry out its intended functionality. The difficulty is keeping the state correct even as requests overlap, servers are added, machines fail, and software changes are deployed.
Often, the common advice is to “make the application stateless”. But this advice needs explanation. It usually means making particular application servers easy to replace while putting their important state elsewhere. It doesn’t signify a complete absence of state. Understanding such a setup requires looking at why state exists, who owns it, and what happens when it becomes unavailable.
In this article, we will look at why state is the hardest thing in software development and the multiple strategies that developers can use to manage it.
What Is State?
Read more