If you want failover to work well, use it often
If you want failover to work well, use it often
Get new notes and articles by email. 通过电子邮件获取新的笔记和文章。
There is an old saying about backups: “Your backups are only as good as the last time you restored them.” 关于备份有一句老话:“备份的可靠性取决于你上一次恢复它的时候。”
The same applies to failover. 故障转移也适用同样的道理。
If you don’t use it frequently enough, it might not work when you need it to. 如果你不经常使用它,那么在真正需要的时候,它可能无法正常工作。
Let’s imagine you’ve got a warm standby environment. 设想你有一个热备环境。
The application is running, the infrastructure is provisioned, and health checks are passing. 应用程序正在运行,基础设施已配置完毕,健康检查也已通过。
Everything looks ready for traffic, right? 一切看起来都已准备好接收流量,对吧?
When you start an environment, the application establishes connections to dependencies like databases and caches. 当你启动一个环境时,应用程序会与数据库和缓存等依赖项建立连接。
Everything works fine at startup, but what happens when that environment sits idle for months? 启动时一切正常,但如果该环境闲置数月会发生什么呢?
If you use persistent database connections without appropriate idle timeouts or maximum connection lifetimes, those connections could become stale without your application realizing it. 如果你使用持久数据库连接而没有设置适当的空闲超时或最大连接生命周期,这些连接可能会在应用程序未察觉的情况下失效。
When a system is idle, dependencies can change, firewall rules can be modified, and credentials can expire without you knowing. 当系统处于空闲状态时,依赖项可能会发生变化,防火墙规则可能会被修改,凭据也可能在你不知情的情况下过期。
Health checks might show the system is working fine, but unless they exercise the same dependencies, network paths, and credentials as real traffic, they might miss important problems. 健康检查可能显示系统运行正常,但除非它们使用了与真实流量相同的依赖项、网络路径和凭据,否则可能会遗漏重要问题。
So when you finally move production traffic to that environment, you might discover problems that have been sitting there for a long time, undetected. 因此,当你最终将生产流量迁移到该环境时,可能会发现那些长期存在且未被察觉的问题。
It’s never a great feeling finding these problems during an outage. 在故障期间发现这些问题绝不是一种好的体验。
The easy answer might be to run active-active. 简单的答案可能是采用双活(active-active)模式。
Yes, having both environments process traffic avoids most of the scenarios I mentioned in passive environments. 是的,让两个环境同时处理流量可以避免我在被动环境中提到的多数情况。
But distributing your traffic across 2 or more environments doesn’t instantly solve all challenges. 但将流量分配到两个或更多环境并不能立即解决所有挑战。
During normal operations, your traffic is distributed across multiple environments, and everything seems great. 在正常运行期间,流量分布在多个环境中,一切看起来都很棒。
But what happens when traffic grows? 但当流量增长时会发生什么?
Maybe each environment handles its share just fine, but when you fail over, the remaining environment suddenly needs to handle significantly more traffic. 也许每个环境都能很好地处理各自的份额,但当你进行故障转移时,剩余的环境突然需要处理大幅增加的流量。
Can it actually handle that volume? 它真的能承受那种负载吗?
You might have planned for this capacity, but having a plan and having it execute in production are two different things. 你可能已经规划了这种容量,但拥有计划和在生产环境中执行计划是两码事。
I usually see this with teams running three or more environments. 我通常在运行三个或更多环境的团队中看到这种情况。
Their normal failover takes them down to two, but sometimes they unexpectedly need to run on just one. 他们正常的故障转移会将环境缩减为两个,但有时他们会意外地需要仅在一个环境上运行。
And that remaining environment might not be capable of handling the full volume. 而那个剩余的环境可能无法处理全部流量。
These challenges become easier to identify and address when you incorporate failover into normal operations. 当你将故障转移纳入日常运营时,这些挑战就更容易识别和解决。
One effective way to do this is to use failover when you make changes. 实现这一点的一个有效方法是在进行变更时使用故障转移。
Software is constantly changing; you’ve always got a new release coming down the pipeline. 软件在不断变化;你总会有新的版本通过流水线发布。
Why not leverage that as an opportunity to exercise your failover capabilities? 为什么不利用这个机会来演练你的故障转移能力呢?
If your architecture supports it, use your failover mechanism to move traffic away from an environment, deploy and validate your changes, and then move traffic back. 如果你的架构支持,可以使用故障转移机制将流量从某个环境中移出,部署并验证你的变更,然后再将流量移回。
You just exercised a planned failover. 你刚刚完成了一次计划内的故障转移。
Did it work? 它成功了吗?
You’ll know pretty quickly whether it did. 你很快就会知道结果。
The more frequently you release, the more familiar your operations team becomes with the process. 你发布得越频繁,你的运维团队对该流程就越熟悉。
The more frequently they use it, the more incentive they have to automate it. 他们使用得越频繁,就越有动力去实现自动化。
After all, nobody wants to execute the same complicated procedure every week manually. 毕竟,没有人愿意每周手动执行同样复杂的程序。
Over time, failover becomes a nothing-burger: automated, well-understood, and something your teams become very comfortable with. 随着时间的推移,故障转移将变得微不足道:自动化、易于理解,并且成为团队非常得心应手的事情。
That is very different from a process used only during emergencies or every X months as an “exercise.” 这与仅在紧急情况下或每隔几个月作为“演习”使用的流程截然不同。
Regularly using your failover process doesn’t just familiarize people with the process; it also requires you to think about your architecture in a different light. 定期使用故障转移流程不仅能让人们熟悉该流程,还要求你以不同的视角审视你的架构。
If you’re going to fail over frequently, then you need to ask yourself: 如果你打算频繁进行故障转移,那么你需要问自己:
When failover is part of your standard operating model, you have to solve these problems or consciously accept the trade-offs. 当故障转移成为你标准运营模式的一部分时,你必须解决这些问题或有意识地接受权衡。
This strengthens your platform not just for every change, but also during emergencies. 这不仅能加强你的平台以应对每一次变更,也能在紧急情况下提供保障。
One caveat: using failover during planned changes validates your ability to move traffic, but it doesn’t necessarily validate what happens during an unexpected failure. 需要注意的一点是:在计划变更期间使用故障转移可以验证你迁移流量的能力,但这并不一定能验证在意外故障发生时会发生什么。
If your system relies on automated failure detection and recovery, you still need to test those mechanisms separately. 如果你的系统依赖于自动故障检测和恢复,你仍然需要单独测试这些机制。
A planned traffic shift and an unexpected failure aren’t the same thing. 计划内的流量切换和意外故障并不是一回事。
And if you can incorporate automated failure detection and recovery into your regular testing, even better. 如果你能将自动故障检测和恢复纳入日常测试,那就更好了。
Even if you can’t exercise every failure scenario during normal operations, regularly using your failover mechanisms gives you opportunities to discover problems while you’re still in control. 即使你无法在正常运营期间演练每一种故障场景,定期使用故障转移机制也能让你有机会在一切尽在掌握时发现问题。
If something doesn’t work, you can often move traffic back and figure out what went wrong. 如果某些环节无法正常工作,你通常可以将流量切回并找出问题所在。
Finding out your failover has flaws during an emergency is the worst time. 在紧急情况下才发现故障转移存在缺陷是最糟糕的时刻。
There is no fail back and figure it out. 那时将没有机会切回并进行排查。