Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

0

引言:

在云计算的浪潮中,“无服务器”(Serverless)架构以其弹性伸缩、按需付费的特性,正迅速成为现代应用开发的主流选择。然而,随着“函数即服务”(FaaS)的普及,一种名为“Lambda 锤子”的思维模式正在悄然蔓延,导致过度依赖函数,反而增加了架构的复杂性和成本。本文将深入探讨无服务器架构的演变,揭示 FaaS 的潜在陷阱,并探讨如何培养“无函数”思维,以实现更高效、可持续的云应用开发。

主体:

无服务器的崛起:从托管服务到函数即服务

“无服务器”的概念并非横空出世,其根源可以追溯到云计算早期。亚马逊的 SQS 和 S3 等全托管服务,早在十多年前就已出现,它们消除了开发者对底层基础设施的担忧,让开发者可以专注于业务逻辑。2012年,“无服务器”一词开始流行,它代表了一种无需管理服务器的开发模式。然而,真正将无服务器推向高潮的是 2014 年 AWS Lambda 的发布。作为首个 FaaS 产品,Lambda 让开发者可以编写和运行代码,而无需关心服务器的配置和维护。随后,微软 Azure Functions 和谷歌 Cloud Functions 等产品相继问世,进一步推动了无服务器的普及。

FaaS 的副作用:Lambda 锤子与弹球架构

FaaS 的便捷性,使得开发团队可以快速实现业务逻辑,加速产品迭代。然而,这种便捷性也带来了一些负面影响。

  • Lambda 锤子思维: 就像“手里拿着锤子,看什么都像钉子”一样,开发者容易将所有问题都视为函数问题,过度依赖 FaaS。这种思维模式忽略了其他更适合特定场景的云服务,导致架构设计缺乏灵活性。
  • Lambda 弹球架构: 过度使用相互依赖的函数,以及 S3、SQS 等服务,会导致请求在系统中像弹球一样反弹,形成一个复杂、难以维护的分布式单体应用。这种架构不仅增加了系统的复杂性,也使得调试和故障排除变得困难。
  • 无意中增加的云成本: 虽然 FaaS 按需付费,但过度使用函数会显著增加云成本。函数的执行时间和内存分配是成本的关键因素。例如,一个执行时间从 10 毫秒增加到 10 秒的函数,其成本可能会增加数百倍。

培养“无函数”思维:优化成本与可持续性

为了避免 FaaS 的陷阱,我们需要培养一种“无函数”的思维方式,将函数视为一种代码负担,尽可能地减少它们的使用。

  • 评估用例: 在选择技术方案时,要仔细评估用例,并非所有场景都适合使用函数。对于服务编排等场景,全托管服务可能是更好的选择。
  • 利用全托管服务: 云提供商提供了各种全托管服务,如消息队列、数据库、存储服务等。这些服务可以帮助开发者构建更简洁、高效的架构,减少对函数的依赖。
  • 关注可持续性: 云的可持续性不仅是云提供商的责任,也是每个云用户的责任。通过合理使用云服务,减少不必要的计算资源消耗,我们可以为可持续发展做出贡献。

结论:

无服务器架构的未来,不仅仅是函数的堆砌,更在于对云服务的合理利用。从“函数”到“无形”,我们需要培养一种“无函数”的思维方式,将函数视为一种代码负担,尽可能地减少它们的使用。通过评估用例,利用全托管服务,关注可持续性,我们可以构建更高效、更经济、更可持续的云应用。

参考文献:

  • Brisals, S. (2025, January 10). Becoming Functionless: How to cultivate a serverless mindset to write less code!. InfoQ.
  • Thoughtworks. (n.d.). Lambda Pinball Architecture. Thoughtworks Technology Radar.
  • Amazon Web Services. (n.d.). Well-Architected Framework. AWS Documentation.

(注:以上参考文献格式为 APA 格式,可根据需要调整为其他格式)


>>> Read more <<<

Views: 0

0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注