首页 › 技术专题 › 高可用

高可用架构与弹性扩容

99.9% 不是营销话术,是每小时 4 分半的预算。这篇讲可用性怎么算、单点怎么拆、扩容什么时候触发、故障来了怎么降级——都是可以照抄的设计决策。

Home › Tech › High Availability

High-availability architecture and elastic scaling

99.9% is not a marketing line — it is a budget of four and a half minutes per hour. Availability arithmetic, removing single points, scaling triggers and degradation plans, all copyable.

「高可用」三个字经常被当成报价单上的加价项。这篇把它变成算术题和设计决策清单——算完您会发现,高可用的钱花在哪、能买回什么,其实都能算清楚。

可用性是算出来的

可用性年停机预算意味着什么
99%约 3.7 天单机部署,挂了就停
99.9%约 8.8 小时需要冗余和自动切换
99.99%约 53 分钟每个环节都要双活,成本陡增

注意每多一个 9,成本不是线性涨,是接近翻倍。对多数包网平台,99.9% 是务实的甜点位——99.99% 的钱,往往更该花在别处。

先拆单点,再谈扩容

拆单点的优先级排序,按「挂了影响多大」排:

  1. 数据库。主从复制加自动切换是底线。切换时间目标 30 秒内,切换逻辑必须演练过——没演练过的自动切换,比手动切换更危险。
  2. 接入层。负载均衡双节点 keepalived,这个是成熟方案,照抄即可。
  3. 缓存。缓存挂了数据库能不能扛住?扛不住就要做缓存预热和熔断降级,而不是简单重启。
  4. 任务队列。队列堆积时的消费策略、优先级排序,提前想好比事后救火便宜一百倍。

无状态:扩容的前提

弹性扩容的前提是应用无状态——会话不存本机(放 Redis 或用 token),文件不存本机(放对象存储)。做到这两条,加机器就是改一个数字的事;做不到,扩容就是迁移工程。改造通常需要两到三周,这笔投入在流量上涨前完成,回报率最高。

扩容触发:看指标,不看日历

  • CPU:持续 5 分钟高于 60% 触发评估,70% 触发扩容
  • 响应时间:P95 超过基线 50% 即告警——比 CPU 更早发现问题
  • 队列深度:消费延迟持续增长是容量问题的先行指标
  • 扩容节奏:先倍增再观察,加 20% 这种小步调整既慢又容易误判

降级预案同样重要:流量洪峰时先保什么(登录、核心浏览)、砍什么(报表、非核心功能),提前写死在预案里。现场决策的降级,十次有八次砍错。

多语言多时区对架构的牵连

多语言平台的报表、缓存失效策略、定时任务调度都受时区影响:定时任务统一 UTC 触发、按运营方时区展示;缓存的过期时间要考虑「跨时区的凌晨低峰」不复存在的问题。这些细节在多语言实务里有展开。

容量规划的一个经验值

预留 40% 余量:峰值流量来的时候,余量就是反应时间。2026 年市场侧对高可用的关注度明显上升,背景见上半年市场盘点。架构和接口层的重试熔断怎么配合,看API对接指南;安全侧的密钥容灾,看安全专题

一次教科书式的扩容失败

见过一个反面教材:流量涨了三倍,运维按预案加机器,应用层确实扩上去了,数据库连接池先爆了——每台新机器都带着自己的连接数上限,机器越多,数据库被打得越狠。扩容动作本身引发了故障。教训是容量规划必须全链路做:应用、数据库、缓存、队列一起算,只算一层的扩容方案,就是把压力赶到下一层。这个案例后来成了我们建议「容量演练」的理由——在预发环境模拟三倍流量,比在生产环境第一次见到三倍流量便宜太多。

"High availability" too often appears as a line item that justifies a price. This page turns it into arithmetic and a list of design decisions — and once you run the numbers, you can see exactly where the money goes and what it buys back.

Availability is arithmetic

AvailabilityAnnual downtime budgetWhat it implies
99%~3.7 daysSingle machine; when it dies, you stop
99.9%~8.8 hoursRedundancy and automatic failover required
99.99%~53 minutesActive-active everywhere; cost roughly doubles

Note that each additional nine roughly doubles the cost rather than adding linearly. For most platform operators, 99.9% is the pragmatic sweet spot — the money for 99.99% is usually better spent elsewhere.

Remove single points before you scale

Prioritize by blast radius:

  1. Database. Primary-replica replication with automatic failover is the floor. Target a switch inside 30 seconds — and only trust a failover path you have rehearsed. An unrehearsed automatic failover is more dangerous than a manual one.
  2. Edge. Two load balancers with keepalived. A solved problem; copy the pattern.
  3. Cache. If the cache dies, can the database absorb the load? If not, you need cache warm-up and circuit breaking, not just a restart.
  4. Job queues. Consumption policy and priority ordering under backlog — deciding this in advance is a hundred times cheaper than firefighting it later.

Stateless: the precondition for scaling

Elastic scaling assumes stateless application servers — sessions off the box (into Redis, or token-based) and files off the box (into object storage). With those two in place, adding capacity is a number in a config. Without them, scaling is a migration project. The redesign typically takes two to three weeks, and its return is highest when completed before traffic grows, not after.

Scaling triggers: watch metrics, not the calendar

  • CPU: sustained 5 minutes above 60% triggers review; 70% triggers scaling
  • Latency: alert when P95 exceeds baseline by 50% — this catches problems earlier than CPU does
  • Queue depth: steadily growing consumption lag is a leading indicator of capacity trouble
  • Cadence: double first, then observe; 20% nudges are both slow and easy to misread

Degradation plans matter just as much: during a traffic spike, decide in advance what you protect (login, core browsing) and what you cut (reports, non-core features). Degradation decided on the spot cuts the wrong thing eight times out of ten.

How multilingual and multi-zone builds pull on architecture

Reporting, cache invalidation and scheduled jobs all feel time zones: jobs fire in UTC and display in the operator's zone, and cache expiry can no longer lean on a "3 a.m. lull" that does not exist across regions. These details are expanded in the multilingual practice.

One capacity-planning rule of thumb

Keep 40% headroom: when peak traffic arrives, headroom is your reaction time. Market attention to high availability rose noticeably in 2026 — the background is in the first-half review. How the architecture layer coordinates with interface-level retries and circuit breaking is covered in the API guide; key-management failover on the security side is in the security topic.

A textbook scaling failure

We once watched a cautionary tale play out: traffic tripled, operations added machines per the playbook, and the application layer scaled just fine — right up until the database connection pool blew. Every new machine arrived with its own connection ceiling, so more machines meant a harder-hit database. The scaling action itself caused the outage. The lesson: capacity planning must be end-to-end. Application, database, cache and queue are one system; a plan that sizes only one layer just relocates the pressure to the next. That case is why we now recommend capacity drills — simulating triple load in staging is dramatically cheaper than meeting triple load for the first time in production.

容量规划心里没数?

把流量特征说说,我们帮您算冗余和触发线。

立即联系我们

No feel for capacity planning yet?

Describe the traffic profile and we will work out the redundancy and trigger lines.

Contact us