
This is something every backend developer should know (Concurrency)
每个后端开发者都应该了解的知识(并发控制)
21 分钟阅读AI
【后端进阶】并发(Concurrency)深度解析:每一位后端开发者必须跨越的门槛 在高并发 AI 请求的今天,并发模型决定了系统的天花板。本内容详细拆解了 Go、Node.js 与 Rust 在处理并发时的底层逻辑差异,解释了架构师该如何通过非阻塞 IO 与协程设计来压榨系统性能极限。 🎙️ 主讲人介绍 资深后端架构师:拥有多年大规模分布式系统实战经验,专注于后端性能优化与并发理论研究。 核心议题:协程与线程的底层逻辑、锁机制的性能代价、异步 IO 的陷阱、AI 应用高并发优化。 关键词:后端开发、并发编程、系统性能、高可用架构
章节 1:后端并发的核心概念与理论基础
📝 本节摘要:
本节首先强调了掌握并发(Concurrency)对于进阶高级后端开发者的重要性。作者将并发定义为“两个进程或事务争夺同一资源”,指出在符合 ACID 标准的数据库中,这主要涉及“隔离性(Isolation)”的处理。
>
通过一个具体的银行账户案例(事务A和B同时操作同一ID),视频引出了两种处理冲突的核心路径:让后续事务等待(悲观策略)或允许其继续修改(乐观策略)。最后,作者澄清了一个关键误区:并发策略的选择不是针对整个应用程序(如 Netflix vs Facebook)或数据库类型(如 Postgres vs MongoDB),而是取决于具体的业务动作(如“更新个人资料”适合乐观并发,而“银行充值”适合悲观并发)。
[原文] [Speaker]: if you're a back-end developer concurrency is one of those things that will make you stand out from other senior developers And it's quite a tricky topic but as always I'm going to make it super easy for you
[译文] [Speaker]: 如果你是一名后端开发人员,并发性(Concurrency)是那些能让你从其他高级开发人员中脱颖而出的技能之一。这虽然是一个相当棘手的话题,但像往常一样,我会让它对你来说变得超级简单。
[原文] [Speaker]: So the plan for today is the following First we're going to try to understand what it is We're going to look at two approaches pessimistic and optimistic concurrency There are trade-offs and as always the best practices
[译文] [Speaker]: 所以今天的计划如下:首先我们将尝试理解它是什么。我们将研究两种方法:悲观并发(Pessimistic Concurrency)和乐观并发(Optimistic Concurrency)。这其中存在权衡,当然还有最佳实践。
[原文] [Speaker]: And before we dive deep into the code as always I want to make sure that we're on the same page when it comes to the theory So we're going to start with a bit of a theory first
[译文] [Speaker]: 在深入代码之前,像往常一样,我想确保我们在理论层面达成共识。所以我们要先从一点理论开始。
[原文] [Speaker]: So concurrency can be seen not only in databases although our video is primarily about concurrency in databases but it's basically about two processes or in our case transactions competing for one resource
[译文] [Speaker]: 并发不仅存在于数据库中(尽管我们的视频主要关于数据库中的并发),但它基本上是关于两个进程——或者在我们的例子中是事务(Transactions)——争夺同一个资源。
[原文] [Speaker]: So in asset compliant databases concurrency is basically taking care of isolation
[译文] [Speaker]: 所以在符合 ACID(原子性、一致性、隔离性、持久性)标准的数据库中,并发基本上是在处理隔离性(Isolation)。
[原文] [Speaker]: So what do I mean let's say we have one table called accounts and obviously we have we have many accounts
[译文] [Speaker]: 那么我是什么意思呢?假设我们要有一个名为 accounts(账户)的表,显然我们有很多账户。
[原文] [Speaker]: So if transaction A is trying to access one of those accounts let's say account ID 1 and it wants to update it while transaction E is doing some work on this ID
[译文] [Speaker]: 如果事务 A 试图访问这些账户中的一个,比如账户 ID 1,并且它想在该 ID 上进行更新,而此时事务 E 正在对这个 ID 进行某些工作。
[原文] [Speaker]: The transaction B has to wait until transaction A is finished so that it can also do it This is one of the ways to deal with concurrency or transaction B can actually go ahead and modify while transaction A is still running
[译文] [Speaker]: 事务 B 必须等待直到事务 A 完成,这样它才能执行操作。这是处理并发的一种方式,或者事务 B 实际上可以在事务 A 仍在运行时继续进行修改。
[原文] [Speaker]: Now which way is better this is the question and this is why we have two different types of concurrency And your job is to choose the one that fits your scenario the best
[译文] [Speaker]: 现在哪种方式更好?这就是问题所在,这也是为什么我们有两种不同类型的并发。而你的工作是选择最适合你场景的那一种。
[原文] [Speaker]: Now when we talk about concurrency it's not like we're talking about a specific app Let's say Netflix is pessimistically concurrent and Facebook is optimistically concurrent
[译文] [Speaker]: 当我们谈论并发时,并不是说我们在谈论某个特定的应用程序。比如(不能说)Netflix 是悲观并发的,而 Facebook 是乐观并发的。
[原文] [Speaker]: No we're also not saying that Postgress is pessimistic and MongoDB is optimistic No we're really talking about specific actions within your application
[译文] [Speaker]: 不,我们也不是说 Postgres 是悲观的而 MongoDB 是乐观的。不,我们真正谈论的是应用程序中的具体操作(Specific Actions)。
[原文] [Speaker]: For example updating your user profile can be optimistically concurrent Updating your bank account or topping up your account can be pessimistic And we're going to talk about this in a minute
[译文] [Speaker]: 例如,更新你的用户资料可以是乐观并发的。更新你的银行账户或给账户充值可以是悲观的。我们将在一分钟后讨论这个问题。
- 章节 2:悲观并发(Pessimistic Concurrency)——原理与代码实现
- 章节 3:悲观并发的实战评估——场景、优缺与最佳实践
- 章节 4:技术插曲——自动化端到端测试工具
- 章节 5:乐观并发(Optimistic Concurrency)——版本控制机制
- 章节 6:乐观并发的工程落地——代码示例与策略总结
正在加载后续章节…







