← Kỹ sư mạng← Network Engineer
Kỹ sư mạngNetwork Engineer19 Th7, 2026Jul 19, 202628 phút đọc24 min read

Dự phòng & High AvailabilityRedundancy & High Availability

Thuộc bộ kiến thức Network Engineer Roadmap.

Tổng quan

Mạng nào rồi cũng có lúc hỏng. Một bộ nguồn chết, một module quang tối đèn, một thay đổi cấu hình gõ nhầm làm hỏng bảng định tuyến, một switch tự reboot vì lỗi firmware lúc 3 giờ sáng. Khác biệt giữa một mạng chỉ giật nhẹ và một mạng sập hẳn nằm ở redundancy (dự phòng) — có sẵn đường đi thứ hai, thiết bị thứ hai, hoặc data center thứ hai sẵn sàng gánh tải — kết hợp với failover nhanh và tự động để thiết bị dự phòng tiếp quản trước khi người dùng (hoặc SLA) kịp nhận ra.

High Availability (HA) là kỷ luật thiết kế hệ thống để tiếp tục phục vụ dù có component hỏng. Nó không phải một tính năng bật lên là xong; nó là một thuộc tính hình thành từ các quyết định ở mọi tầng:

Mục tiêu chung là loại bỏ single point of failure (SPOF). SPOF là bất kỳ thành phần nào mà khi nó hỏng thì cả dịch vụ sập theo. Nếu hai firewall dự phòng của bạn cùng cắm vào một switch, thì switch đó là SPOF. Nếu hai switch dùng chung một ổ điện, ổ điện đó là SPOF. Thiết kế HA về bản chất là việc tìm kiếm và loại bỏ SPOF một cách có hệ thống.

Note này bao gồm: toán học của availability, các First Hop Redundancy Protocol (HSRP, VRRP, GLBP), các khái niệm failover (active-passive vs active-active, heartbeat, split-brain, preemption), load balancing chuyên sâu (L4 vs L7, thuật toán, health check, session persistence, SSL termination), link/path redundancy, và cách lắp ghép chúng thành topology có sức chống chịu. Các note liên quan:

Kiến thức nền tảng

Vì sao HA quan trọng: SPOF, chi phí downtime và blast radius

Downtime rất đắt và bất đối xứng. Vài giây mất gói khi failover sạch sẽ thì gần như vô hình; nhưng một sự cố 30 phút trong giờ làm việc có thể mất doanh thu, vi phạm SLA và kích hoạt phạt hợp đồng. Các động lực nghiệp vụ cho HA:

Công việc kỹ thuật là thu nhỏ blast radius (bán kính ảnh hưởng) của mỗi sự cố để không một component nào hỏng có thể kéo sập tất cả.

”Các số 9”: toán học của availability

Availability là tỷ lệ thời gian hệ thống hoạt động, thường biểu diễn bằng phần trăm và nói vui là số lượng “số 9”:

Availability = Uptime / (Uptime + Downtime)
             = MTBF / (MTBF + MTTR)
Availability”Số 9”Downtime / nămDowntime / thángDowntime / ngày
90%one nine36.5 ngày72 giờ2.4 giờ
99%two nines3.65 ngày7.2 giờ14.4 phút
99.9%three nines8.77 giờ43.8 phút1.44 phút
99.95%three rưỡi4.38 giờ21.9 phút43.2 giây
99.99%four nines52.6 phút4.38 phút8.6 giây
99.999%five nines5.26 phút26.3 giây0.86 giây
99.9999%six nines31.5 giây2.63 giây0.086 giây

Hai nhận định quan trọng:

  1. Các số 9 nhân với nhau khi mắc nối tiếp (series). Nếu một request phải đi qua firewall (99.99%), load balancer (99.99%) và app server (99.9%), thì availability đầu-cuối là 0.9999 × 0.9999 × 0.999 ≈ 99.88%tệ hơn bất kỳ component đơn lẻ nào. Chuỗi phụ thuộc kéo availability xuống.
  2. Redundancy mắc song song (parallel) nhân xác suất hỏng. Hai component độc lập, mỗi cái 99% availability (1% hỏng), đặt song song chỉ hỏng cùng lúc với xác suất 0.01 × 0.01 = 0.0001 → availability tổng hợp 99.99%. Đây là lý do redundancy mạnh đến vậy — nhưng chỉ khi các component hỏng độc lập (không chung nguồn, không chung sợi quang, không chung một bug bị kích hoạt bởi cùng input).

MTBF và MTTR

Availability = MTBF / (MTBF + MTTR), giảm một nửa MTTR cải thiện availability y hệt như tăng gấp đôi MTBF — và thường rẻ hơn nhiều. Failover nhanh, tự động là khoản đầu tư HA có ROI cao nhất. Một cú failover FHRP dưới một giây biến việc reboot thiết bị từ một sự cố thành một chuyện không đáng kể.

RTO và RPO (bối cảnh DR)

HA (giữ cho chạy) đi kèm với Disaster Recovery (DR) (khôi phục sau tổn thất lớn). Hai metric của DR đóng khung yêu cầu:

Cơ chế HA (FHRP, load balancer, clustering) nhắm tới RTO gần bằng 0 cho lỗi component. Cơ chế DR (backup, replication, standby site) nhắm tới RTO/RPO có giới hạn cho lỗi thảm khốc. Một thiết kế hoàn chỉnh dùng cả hai: HA cho trường hợp thường gặp (một thiết bị chết), DR cho trường hợp hiếm (mất cả một site).

Khái niệm chính

First Hop Redundancy Protocol (FHRP)

Host được cấu hình một default gateway IP duy nhất. Nếu gateway đó (router/L3 switch) chết, mọi host trong subnet mất kết nối ra ngoài subnet — một SPOF kinh điển. First Hop Redundancy Protocol giải quyết bằng cách cho hai hoặc nhiều router chia sẻ một virtual IP (VIP)virtual MAC đóng vai gateway. Host trỏ vào VIP; các router bầu ra một active forwarder; nếu nó hỏng, một standby tiếp quản VIP/MAC mà không cần cấu hình lại host.

Điều kỳ diệu là virtual MAC di chuyển theo vai trò. Vì host có ánh xạ VIP→virtual-MAC trong ARP cache, và router active mới bắt đầu trả lời cho chính virtual MAC đó, nên các entry ARP của host vẫn hợp lệ — traffic chỉ đơn giản chảy sang một thiết bị vật lý khác. Failover trong suốt đối với end station.

HSRP (Hot Standby Router Protocol) — Cisco độc quyền

! Cisco HSRP — hai router, VIP 10.1.1.1, group 10
! Router A (primary)
interface Vlan10
 ip address 10.1.1.2 255.255.255.0
 standby version 2
 standby 10 ip 10.1.1.1
 standby 10 priority 110
 standby 10 preempt
 standby 10 timers msec 250 msec 750      ! hello 250ms / hold 750ms
 standby 10 track GigabitEthernet0/1 20   ! -20 priority nếu uplink down
!
! Router B (secondary) — cùng VIP, priority thấp hơn
interface Vlan10
 ip address 10.1.1.3 255.255.255.0
 standby version 2
 standby 10 ip 10.1.1.1
 standby 10 priority 100
 standby 10 preempt

VRRP (Virtual Router Redundancy Protocol) — chuẩn mở, RFC 5798

! VRRP (chạy đa hãng; cú pháp Cisco), VIP 10.1.1.1, VRID 10
interface Vlan10
 ip address 10.1.1.2 255.255.255.0
 vrrp 10 ip 10.1.1.1
 vrrp 10 priority 110
 vrrp 10 timers advertise 1
 vrrp 10 preempt          ! bật mặc định; ghi ra cho rõ

GLBP (Gateway Load Balancing Protocol) — Cisco, active-active load sharing

! GLBP — active-active, một VIP 10.1.1.1, group 10
! Router A
interface Vlan10
 ip address 10.1.1.2 255.255.255.0
 glbp 10 ip 10.1.1.1
 glbp 10 priority 110
 glbp 10 preempt
 glbp 10 load-balancing weighted
 glbp 10 weighting 100
! Router B
interface Vlan10
 ip address 10.1.1.3 255.255.255.0
 glbp 10 ip 10.1.1.1
 glbp 10 priority 100
 glbp 10 preempt
 glbp 10 load-balancing weighted
 glbp 10 weighting 80

Bảng so sánh FHRP

Đặc điểmHSRPVRRPGLBP
ChuẩnCisco độc quyền (RFC 2281)Mở (RFC 5798)Cisco độc quyền
Vai tròActive / Standby / ListenMaster / BackupAVG / AVF
Bầu chọnPriority (100), cao thắngPriority (100), cao thắng; owner = 255AVG theo priority; forwarder chia tải
Virtual MAC0000.0C07.ACxx (v1)0000.5E00.01xxtối đa 4 vMAC (0007.B4xx…)
Hello / hold mặc định3 s / 10 s1 s adv / ~3 s down3 s / 10 s
Preemption mặc địnhTắt (phải bật)BậtTắt (phải bật)
Multicast / proto224.0.0.2 / 102, UDP 1985224.0.0.18, IP proto 112224.0.0.102, UDP 3222
Load sharingNhiều group (MHSRP)Nhiều group (VRID)Gốc (một VIP, active-active)
Interface/object tracking
Dùng khiToàn CiscoMulti-vendor / chuẩn mởCisco, muốn chia tải gateway theo flow

Mẹo: Cả ba đều hỗ trợ object/interface tracking để router mất link hướng lên (upstream) tự hạ priority và nhường vai, tránh tình huống “black hole” nơi gateway active còn sống ở phía LAN nhưng không có đường ra ngoài.

Các khái niệm failover

Active-passive vs active-active

Active-PassiveActive-Active
Xử lý trafficMột node phục vụ; node kia đứng chờ standbyTất cả node phục vụ đồng thời
Dùng tài nguyên~50% (standby ngồi không)Gần 100% (tất cả làm việc)
Hành vi failoverStandby lên khi có lỗi (giật nhẹ)Node còn sống hấp thụ tải ngay lập tức
Hoạch định năng lựcStandby phải bằng primaryCần headroom N+1 (mỗi node ≤ (N-1)/N tải)
Độ phức tạpĐơn giản hơn; không xung đột stateKhó hơn; cần shared/replicated state, session sync
Ví dụCặp HSRP/VRRP, cặp firewall HAGLBP, pool server sau LB, ECMP, anycast

Một lưu ý quan trọng của active-active: nếu hai node mỗi node chạy 70% và một cái chết, node còn lại cần 140% — sẽ quá tải. Hãy hoạch định năng lực active-active sao cho một node bất kỳ có thể hấp thụ được tải failover.

Heartbeat

Các peer dự phòng trao đổi thông điệp heartbeat định kỳ (hello của FHRP, keepalive của cụm LB, link HA của firewall) để biết đối phương còn sống. Mất N heartbeat liên tiếp thì kết luận peer đã chết và kích hoạt failover. Việc tinh chỉnh là đánh đổi:

Dùng BFD (Bidirectional Forwarding Detection) để phát hiện liveness nhanh, chi phí thấp mà nhiều FHRP và routing protocol có thể móc vào để hội tụ dưới giây mà không cần timer protocol quá quyết liệt.

Split-brain

Split-brain là kiểu lỗi nguy hiểm khi link heartbeat/giao tiếp giữa các peer đứt nhưng cả hai peer thật ra vẫn sống. Mỗi bên kết luận bên kia đã chết và cả hai đều lên active — hai master cùng trả lời cho một VIP, hoặc hai firewall cùng giữ active state, gây MAC flap, trùng IP, hỏng shared state và asymmetric routing. Cách giảm thiểu:

Preemption

Preemption quy định điều gì xảy ra khi một thiết bị priority cao hơn phục hồi:

Best practice: bật preemption kèm delay (preempt delay minimum) để router vừa reboot hội tụ xong bảng định tuyến và forwarding plane trước khi giành vai active — nếu không nó lên active trong khi vẫn còn black-hole traffic.

Load balancing (chuyên sâu)

Một load balancer (LB) trình ra cho client một virtual IP (VIP) duy nhất và phân phối các connection/request tới một pool server backend (“real server”). Nó mang lại quy mô (thêm server sau một địa chỉ), tính sẵn sàng (tự loại server hỏng qua health check), và sự linh hoạt (rolling deploy, SSL offload, routing).

L4 vs L7 load balancing

Layer 4 (Transport)Layer 7 (Application)
Hoạt động trênIP + TCP/UDP portHTTP(S), header, URL, cookie, gRPC
Cơ sở quyết định5-tuple (src/dst IP, port, proto)Nội dung: path, host, method, cookie, header
Tầm nhìnKhông thấy payloadKiểm tra toàn bộ request
Tính năngNhanh, đơn giản, không phụ thuộc protocolContent routing, rewrite header, WAF, caching, nén
Hiệu năngThroughput rất cao, latency thấpTốn CPU hơn (parse/terminate)
PersistenceDựa trên source IPDựa trên cookie/session (chính xác)
TLSPass-through (hoặc cơ bản)Termination, re-encryption, SNI routing
Ví dụLVS/IPVS, AWS NLB, F5 (L4 VS)NGINX, HAProxy (http mode), Envoy, AWS ALB

Chọn L4 khi cần tốc độ thô và protocol không phải HTTP; chọn L7 khi cần route theo URL/host, làm TLS termination, rewrite header, hay áp policy hiểu ứng dụng.

Các thuật toán load balancing

Thuật toánCách hoạt độngKhi nào dùngLưu ý
Round-robinXoay vòng qua các server theo thứ tựServer đồng nhất, request ngắn đều nhauBỏ qua tải thực; request dài làm lệch
Weighted round-robinRound-robin có thiên vị theo weight từng serverServer không đồng nhất (CPU/RAM khác)Weight tĩnh không thích ứng tải thời gian thực
Least connectionsGửi tới server có ít connection active nhấtConnection dài / độ dài biến thiên (DB, WebSocket)Cần theo dõi số connection
Weighted least connectionsLeast-connections có nhân theo capacity weightServer sức chứa khác nhau, connection dàiCần giữ thêm chút state
Least response timeÍt connection active nhất + latency thấp nhấtDịch vụ nhạy latencyCần probe response-time
IP hash / source hashHash IP client → server xác địnhStickiness rẻ, không cần cookieLệch nếu client nằm sau ít NAT/proxy
Consistent hashingHash key lên một vòng; remap tối thiểu khi thay đổiCache, backend shard, sticky ở quy mô lớnPhức tạp hơn; cần virtual node để cân bằng
Random (+ two choices)Chọn ngẫu nhiên (hoặc tốt hơn trong hai lần ngẫu nhiên)Đơn giản, hiệu quả bất ngờ ở quy mô lớn”Power of two choices” cần thấy được tải

Quy tắc chung: bắt đầu với round-robin (hoặc least-connections nếu thời lượng request rất biến thiên), thêm weight cho phần cứng không đều, và chỉ dùng tới hashing/consistent hashing khi cần stickiness hoặc cache affinity.

Health check

Health check là thứ biến LB thành công cụ availability chứ không chỉ là bộ phân phối. LB liên tục probe từng backend và loại các cái không khỏe khỏi vòng xoay:

Session persistence (sticky session)

Một số ứng dụng giữ state theo từng user trong bộ nhớ server, nên các request của user phải quay lại đúng backend đó. Các phương pháp persistence:

Best practice: ưu tiên backend stateless (lưu session vào store dùng chung như Redis hoặc token đã ký) để load balance thoải mái và không mất session khi failover. Sticky session là cái nạng làm hỏng phân phối đều và làm phức tạp rolling deploy.

SSL/TLS termination

Hardware vs software vs cloud load balancer

LoạiVí dụƯuNhược
Hardware applianceF5 BIG-IP, Citrix ADC (NetScaler), A10Throughput rất cao, ASIC SSL offload, tính năng chín muồiĐắt, năng lực là một hộp phải scale/thay, khóa nhà cung cấp
SoftwareHAProxy, NGINX, Envoy, LVS/IPVS, TraefikRẻ/miễn phí, linh hoạt, chạy mọi nơi, hợp IaCBạn tự lo scale/HA/patch; hiệu năng phụ thuộc host
Cloud managedAWS ALB/NLB, GCP Cloud Load Balancing, Azure LBCo giãn, HA sẵn có, multi-AZ, trả theo dùngÍt kiểm soát, chi phí theo request, tính năng riêng nhà cung cấp
# HAProxy — L7, round-robin với health check, cookie stickiness, TLS termination
global
    maxconn 20000

defaults
    mode http
    timeout connect 5s
    timeout client  30s
    timeout server  30s
    option httpchk GET /healthz

frontend web_in
    bind :80
    bind :443 ssl crt /etc/haproxy/certs/site.pem   # TLS termination
    redirect scheme https if !{ ssl_fc }
    default_backend web_pool

backend web_pool
    balance roundrobin
    cookie SRV insert indirect nocache               # sticky session
    server web1 10.0.1.11:8080 check inter 2s fall 3 rise 2 cookie s1 weight 100
    server web2 10.0.1.12:8080 check inter 2s fall 3 rise 2 cookie s2 weight 100
    server web3 10.0.1.13:8080 check inter 2s fall 3 rise 2 cookie s3 weight 50
# NGINX — upstream least-connections với các tùy chọn liên quan health
upstream app {
    least_conn;
    server 10.0.1.11:8080 max_fails=3 fail_timeout=10s;
    server 10.0.1.12:8080 max_fails=3 fail_timeout=10s;
    server 10.0.1.13:8080 backup;      # chỉ dùng khi các server khác down
}
server {
    listen 443 ssl;
    ssl_certificate     /etc/nginx/site.crt;
    ssl_certificate_key /etc/nginx/site.key;
    location / {
        proxy_pass http://app;
        proxy_next_upstream error timeout http_502 http_503;
    }
}

FHRP bảo vệ gateway; còn các đường đi giữa các thiết bị cần redundancy riêng của chúng.

Gộp nhiều link vật lý giữa hai thiết bị thành một link logic (IEEE 802.3ad / LACP; Cisco EtherChannel; Linux bonding). Lợi ích: băng thông tổng cao hơnredundancy ở mức link — nếu một member hỏng, traffic phân phối lại qua các member còn sống mà không cần STP hội tụ lại. Traffic được hash trên các member (theo MAC/IP/port), nên một flow đơn không vượt quá tốc độ một member. Xem ./08-switching.md.

! Cisco LACP EtherChannel
interface range GigabitEthernet0/1 - 2
 channel-group 1 mode active        ! LACP
interface Port-channel1
 switchport mode trunk

Hai uplink từ một access switch tới hai distribution switch tạo thành loop vật lý. STP/RSTP chặn đường dự phòng để chống broadcast storm, rồi mở lại trong vài giây nếu đường chính hỏng (RSTP hội tụ nhanh hơn STP cổ điển nhiều). Thiết kế hiện đại ưa dùng MLAG / vPC / stacking để cả hai uplink cùng active (không có port bị STP chặn) mà vẫn không loop — uplink active-active thay vì active-passive. Chi tiết trong ./08-switching.md.

ECMP (Equal-Cost Multi-Path)

Ở Layer 3, khi bảng định tuyến có nhiều đường cùng cost tới một đích, router cài tất cả và hash các flow trên chúng — vừa load sharing active-active vừa redundancy ở tầng routing. Nếu một next-hop hỏng, phần của nó phân phối lại qua các đường còn lại ở lần cập nhật routing kế tiếp (hoặc ngay lập tức với BFD). ECMP là nền của fabric spine-leaf trong data center và của anycast. Flow được hash theo 5-tuple nên một flow ở lại một đường (tránh reorder gói).

So sánh các tầng redundancy

Cơ chếTầngRedundancy choActive-active?
STP/RSTPL2Link switch dự phòng (không loop)Không (chặn backup)
MLAG / vPC / stackL2Uplink dual-homed
LACP / EtherChannelL2Các member link trong một bundle
HSRP / VRRPL3Default gatewayKhông (standby ngồi không)
GLBPL3Default gateway
ECMPL3Đường routed
Load balancerL4/L7Pool server
AnycastL3Endpoint địa lý/dịch vụ

Thiết kế topology dự phòng

HA được xếp lớp — mỗi tầng loại bỏ SPOF ở mức của nó:

  1. Component redundancy — hai bộ nguồn (trên PDU/feed riêng biệt), dual supervisor/route processor, dual NIC bond, quạt hot-swap.
  2. Device redundancy — cặp switch/router/firewall/LB, gắn với nhau bằng FHRP (gateway), HA clustering (firewall/LB) và MLAG (switch).
  3. Link/path redundancy — dual uplink (MLAG/ECMP), bundle LACP, và các tuyến sợi quang khác nhau về mặt vật lý để một nhát máy xúc không cắt đứt cả hai.
  4. Site/geographic redundancy — nhân bản dịch vụ qua nhiều data center / cloud region/AZ. Điều hướng traffic bằng GSLB / DNS-based load balancing, anycast, hoặc global LB của nhà cung cấp. Đây là nơi RTO/RPO và DR gặp HA.

Mẫu doanh nghiệp kinh điển — collapsed-core / hai tầng: cặp distribution/core switch (MLAG), mỗi access switch dual-home vào cả hai, FHRP (hoặc SVI trên cặp MLAG) cho gateway VIP, cặp firewall trong HA pair, cặp router tới hai ISP chạy BGP để dự phòng internet.

Quy tắc chung:

Best Practices

Tài liệu tham khảo

Part of the Network Engineer Roadmap knowledge base.

Overview

Every network eventually breaks. A power supply dies, an optic goes dark, a config change fat-fingers a routing table, a switch reboots for a firmware bug at 3 a.m. The difference between a network that hiccups and a network that goes down is redundancy — having a second path, a second device, or a second data center ready to carry the load — combined with fast, automatic failover so that the spare takes over before users (or SLAs) notice.

High Availability (HA) is the discipline of engineering systems to keep serving despite component failures. It is not a single feature you switch on; it is a property that emerges from decisions at every layer:

The unifying goal is the elimination of single points of failure (SPOFs). A SPOF is any element whose failure takes down the whole service. If your two redundant firewalls both plug into one switch, that switch is a SPOF. If your two switches share one power strip, that strip is a SPOF. HA design is largely the systematic hunt for and removal of SPOFs.

This note covers the math of availability, First Hop Redundancy Protocols (HSRP, VRRP, GLBP), failover concepts (active-passive vs active-active, heartbeat, split-brain, preemption), load balancing in depth (L4 vs L7, algorithms, health checks, session persistence, SSL termination), link and path redundancy, and how to assemble these into resilient topologies. Related notes:

Fundamentals

Why HA matters: SPOFs, cost of downtime, and blast radius

Downtime is expensive and asymmetric. A few seconds of packet loss during a clean failover is invisible; a 30-minute outage during business hours can cost revenue, breach an SLA, and trigger contractual penalties. The business drivers for HA are:

The engineering job is to shrink the blast radius of any single failure so that no one component failing can take everything down.

The “nines”: availability math

Availability is the fraction of time a system is operational, usually expressed as a percentage and colloquially as a number of “nines”:

Availability = Uptime / (Uptime + Downtime)
             = MTBF / (MTBF + MTTR)
Availability”Nines”Downtime / yearDowntime / monthDowntime / day
90%one nine36.5 days72 hours2.4 hours
99%two nines3.65 days7.2 hours14.4 min
99.9%three nines8.77 hours43.8 min1.44 min
99.95%three and a half4.38 hours21.9 min43.2 s
99.99%four nines52.6 min4.38 min8.6 s
99.999%five nines5.26 min26.3 s0.86 s
99.9999%six nines31.5 s2.63 s0.086 s

Two crucial insights:

  1. Nines are multiplicative in series. If a request must traverse a firewall (99.99%), a load balancer (99.99%), and an app server (99.9%), the end-to-end availability is 0.9999 × 0.9999 × 0.999 ≈ 99.88%worse than any single component. Chains of dependencies drag availability down.
  2. Redundancy in parallel multiplies the failure probability. Two independent components each with 99% availability (1% failure) placed in parallel fail together only 0.01 × 0.01 = 0.0001 of the time → combined availability 99.99%. This is why redundancy is so powerful — but only if the components fail independently (no shared power, no shared fiber, no shared bug triggered by the same input).

MTBF and MTTR

Because Availability = MTBF / (MTBF + MTTR), halving MTTR improves availability just as much as doubling MTBF — and is usually far cheaper. Fast, automatic failover is the highest-ROI HA investment. A sub-second FHRP failover turns a device reboot from an outage into a non-event.

RTO and RPO (the DR context)

HA (keeping running) is adjacent to Disaster Recovery (DR) (recovering after a major loss). Two DR metrics frame the requirements:

HA mechanisms (FHRP, load balancers, clustering) target near-zero RTO for component failures. DR mechanisms (backups, replication, standby sites) target bounded RTO/RPO for catastrophic failures. A complete design uses both: HA for the common case (a device dies), DR for the rare case (a site is lost).

Key Concepts

First Hop Redundancy Protocols (FHRP)

Hosts are configured with a single default gateway IP. If that gateway (router/L3 switch) dies, every host on the subnet loses off-subnet connectivity — a classic SPOF. First Hop Redundancy Protocols solve this by letting two or more routers share a virtual IP (VIP) and virtual MAC that acts as the gateway. Hosts point at the VIP; the routers elect an active forwarder; if it fails, a standby takes over the VIP/MAC with no reconfiguration on the hosts.

The magic is that the virtual MAC moves with the role. Because hosts have the VIP→virtual-MAC mapping in their ARP cache, and the new active router starts answering for that same virtual MAC, the hosts’ ARP entries stay valid — traffic just starts flowing to a different physical box. Failover is transparent to end stations.

HSRP (Hot Standby Router Protocol) — Cisco proprietary

! Cisco HSRP — two routers, VIP 10.1.1.1, group 10
! Router A (primary)
interface Vlan10
 ip address 10.1.1.2 255.255.255.0
 standby version 2
 standby 10 ip 10.1.1.1
 standby 10 priority 110
 standby 10 preempt
 standby 10 timers msec 250 msec 750      ! hello 250ms / hold 750ms
 standby 10 track GigabitEthernet0/1 20   ! -20 priority if uplink down
!
! Router B (secondary) — same VIP, lower priority
interface Vlan10
 ip address 10.1.1.3 255.255.255.0
 standby version 2
 standby 10 ip 10.1.1.1
 standby 10 priority 100
 standby 10 preempt

VRRP (Virtual Router Redundancy Protocol) — open standard, RFC 5798

! VRRP (works across vendors; Cisco syntax shown), VIP 10.1.1.1, VRID 10
interface Vlan10
 ip address 10.1.1.2 255.255.255.0
 vrrp 10 ip 10.1.1.1
 vrrp 10 priority 110
 vrrp 10 timers advertise 1
 vrrp 10 preempt          ! on by default; shown for clarity

GLBP (Gateway Load Balancing Protocol) — Cisco, active-active load sharing

! GLBP — active-active, single VIP 10.1.1.1, group 10
! Router A
interface Vlan10
 ip address 10.1.1.2 255.255.255.0
 glbp 10 ip 10.1.1.1
 glbp 10 priority 110
 glbp 10 preempt
 glbp 10 load-balancing weighted
 glbp 10 weighting 100
! Router B
interface Vlan10
 ip address 10.1.1.3 255.255.255.0
 glbp 10 ip 10.1.1.1
 glbp 10 priority 100
 glbp 10 preempt
 glbp 10 load-balancing weighted
 glbp 10 weighting 80

FHRP comparison

FeatureHSRPVRRPGLBP
StandardCisco proprietary (RFC 2281)Open (RFC 5798)Cisco proprietary
RolesActive / Standby / ListenMaster / BackupAVG / AVF
ElectionPriority (100), higher winsPriority (100), higher wins; owner = 255AVG by priority; forwarders share
Virtual MAC0000.0C07.ACxx (v1)0000.5E00.01xxup to 4 vMACs (0007.B4xx…)
Default hello / hold3 s / 10 s1 s adv / ~3 s down3 s / 10 s
Preemption defaultOff (must enable)OnOff (must enable)
Multicast / proto224.0.0.2 / 102, UDP 1985224.0.0.18, IP proto 112224.0.0.102, UDP 3222
Load sharingMultiple groups (MHSRP)Multiple groups (VRIDs)Native (single VIP, active-active)
Interface/object trackingYesYesYes
Use whenCisco-only shopMulti-vendor / standards-basedCisco, want per-flow gateway load sharing

Tip: All three support object/interface tracking so a router that loses its upstream link lowers its priority and steps aside, avoiding the “black hole” where the active gateway is up on the LAN side but has no path out.

Failover concepts

Active-passive vs active-active

Active-PassiveActive-Active
Traffic handlingOne node serves; the other idles as standbyAll nodes serve simultaneously
Resource use~50% (standby idle)Near 100% (all working)
Failover behaviorStandby promotes on failure (brief blip)Survivors absorb the load instantly
Capacity planningStandby must equal primaryMust have N+1 headroom (each node ≤ (N-1)/N load)
ComplexitySimpler; no state conflictsHarder; needs shared/replicated state, session sync
ExamplesHSRP/VRRP pair, firewall HA pairGLBP, LB server pool, ECMP, anycast

A key active-active caveat: if two nodes each run at 70% and one dies, the survivor needs 140% — it will be overloaded. Plan active-active capacity so any single node can absorb the failover load.

Heartbeat

Redundant peers exchange periodic heartbeat messages (FHRP hellos, LB cluster keepalives, firewall HA links) to know each other is alive. Losing N consecutive heartbeats declares the peer dead and triggers failover. Tuning is a trade-off:

Use BFD (Bidirectional Forwarding Detection) for fast, low-overhead liveness detection that many FHRPs and routing protocols can hook into for sub-second convergence without over-aggressive protocol timers.

Split-brain

Split-brain is the dangerous failure where the heartbeat/communication link between peers breaks but both peers are actually alive. Each concludes the other is dead and both become active — two masters answering for the same VIP, or two firewalls both holding the active state, causing MAC flaps, duplicate IPs, corrupted shared state, and asymmetric routing. Mitigations:

Preemption

Preemption governs what happens when a higher-priority device recovers:

Best practice: enable preemption with a delay (preempt delay minimum) so a rebooting router fully converges its routing table and forwarding plane before grabbing the active role — otherwise it becomes active while still black-holing traffic.

Load balancing (in depth)

A load balancer (LB) presents a single virtual IP (VIP) to clients and distributes incoming connections/requests across a pool of backend servers (“real servers”). It provides scale (add servers behind one address), availability (remove failed servers automatically via health checks), and flexibility (rolling deploys, SSL offload, routing).

L4 vs L7 load balancing

Layer 4 (Transport)Layer 7 (Application)
Operates onIP + TCP/UDP portHTTP(S), headers, URL, cookies, gRPC
Decision basis5-tuple (src/dst IP, ports, proto)Content: path, host, method, cookie, header
VisibilityOpaque payloadFull request inspection
FeaturesFast, simple, protocol-agnosticContent routing, header rewrite, WAF, caching, compression
PerformanceVery high throughput, low latencyHigher CPU (parses/terminates)
PersistenceSource-IP basedCookie/session based (precise)
TLSPass-through (or basic)Termination, re-encryption, SNI routing
ExamplesLVS/IPVS, AWS NLB, F5 (L4 VS)NGINX, HAProxy (http mode), Envoy, AWS ALB

L4 is chosen for raw speed and non-HTTP protocols; L7 is chosen when you need to route by URL/host, do TLS termination, rewrite headers, or apply application-aware policy.

Load balancing algorithms

AlgorithmHow it worksWhen to useCaveats
Round-robinRotate through servers in orderHomogeneous servers, uniform short requestsIgnores actual load; long requests skew it
Weighted round-robinRound-robin biased by per-server weightHeterogeneous servers (different CPU/RAM)Static weights don’t adapt to real-time load
Least connectionsSend to server with fewest active connectionsLong-lived / variable-length connections (DB, WebSocket)Needs connection-count tracking
Weighted least connectionsLeast-connections scaled by capacity weightMixed-capacity servers with long connectionsSlightly more state to maintain
Least response timeFewest active connections + lowest latencyLatency-sensitive servicesNeeds response-time probing
IP hash / source hashHash client IP → deterministic serverCheap session stickiness without cookiesUneven if clients sit behind few NATs/proxies
Consistent hashingHash key onto a ring; minimal remap on changeCaches, sharded backends, sticky at scaleMore complex; needs virtual nodes for balance
Random (+ two choices)Pick random (or best of two random)Simple, surprisingly good at scale”Power of two choices” needs load visibility

Rule of thumb: start with round-robin (or least-connections if request durations vary a lot), add weights for uneven hardware, and reach for hashing/consistent hashing only when you need stickiness or cache affinity.

Health checks

Health checks are what make an LB an availability tool rather than just a distributor. The LB continuously probes each backend and removes unhealthy ones from rotation:

Session persistence (sticky sessions)

Some applications keep per-user state in server memory, so a user’s requests must return to the same backend. Persistence methods:

Best practice: prefer stateless backends (store session in a shared store like Redis or a signed token) so you can load balance freely and lose no sessions on failover. Sticky sessions are a crutch that hurts even distribution and complicates rolling deploys.

SSL/TLS termination

Hardware vs software vs cloud load balancers

TypeExamplesProsCons
Hardware applianceF5 BIG-IP, Citrix ADC (NetScaler), A10Very high throughput, SSL offload ASICs, mature featuresExpensive, capacity is a box you must scale/replace, vendor lock-in
SoftwareHAProxy, NGINX, Envoy, LVS/IPVS, TraefikCheap/free, flexible, run anywhere, IaC-friendlyYou own scaling/HA/patching; performance depends on host
Cloud managedAWS ALB/NLB, GCP Cloud Load Balancing, Azure LBElastic, HA built-in, multi-AZ, pay-as-you-goLess control, per-request cost, provider-specific features
# HAProxy — L7, round-robin with health checks, cookie stickiness, TLS termination
global
    maxconn 20000

defaults
    mode http
    timeout connect 5s
    timeout client  30s
    timeout server  30s
    option httpchk GET /healthz

frontend web_in
    bind :80
    bind :443 ssl crt /etc/haproxy/certs/site.pem   # TLS termination
    redirect scheme https if !{ ssl_fc }
    default_backend web_pool

backend web_pool
    balance roundrobin
    cookie SRV insert indirect nocache               # sticky sessions
    server web1 10.0.1.11:8080 check inter 2s fall 3 rise 2 cookie s1 weight 100
    server web2 10.0.1.12:8080 check inter 2s fall 3 rise 2 cookie s2 weight 100
    server web3 10.0.1.13:8080 check inter 2s fall 3 rise 2 cookie s3 weight 50
# NGINX — least-connections upstream with health-relevant options
upstream app {
    least_conn;
    server 10.0.1.11:8080 max_fails=3 fail_timeout=10s;
    server 10.0.1.12:8080 max_fails=3 fail_timeout=10s;
    server 10.0.1.13:8080 backup;      # only used if others are down
}
server {
    listen 443 ssl;
    ssl_certificate     /etc/nginx/site.crt;
    ssl_certificate_key /etc/nginx/site.key;
    location / {
        proxy_pass http://app;
        proxy_next_upstream error timeout http_502 http_503;
    }
}

FHRP protects the gateway; the paths between devices need their own redundancy.

Bundle multiple physical links between two devices into one logical link (IEEE 802.3ad / LACP; Cisco EtherChannel; Linux bonding). Benefits: higher aggregate bandwidth and link-level redundancy — if one member fails, traffic redistributes over the survivors without STP reconvergence. Traffic is hashed across members (by MAC/IP/port), so a single flow does not exceed one member’s speed. See ./08-switching.md.

! Cisco LACP EtherChannel
interface range GigabitEthernet0/1 - 2
 channel-group 1 mode active        ! LACP
interface Port-channel1
 switchport mode trunk

Two uplinks from an access switch to two distribution switches create a physical loop. STP/RSTP blocks the redundant path to prevent broadcast storms, then unblocks it in ~seconds if the primary fails (RSTP converges much faster than classic STP). Modern designs prefer MLAG / vPC / stacking so both uplinks are active (no STP-blocked port) while still being loop-free — active-active uplinks instead of active-passive. Details in ./08-switching.md.

ECMP (Equal-Cost Multi-Path)

At Layer 3, when the routing table has multiple equal-cost paths to a destination, the router installs all of them and hashes flows across them — active-active load sharing and redundancy at the routing layer. If one next-hop fails, its share redistributes over the remaining paths on the next routing update (or immediately with BFD). ECMP underpins spine-leaf data-center fabrics and anycast. Flows are hashed per-5-tuple so a single flow stays on one path (avoids packet reordering).

Comparing the redundancy layers

MechanismLayerRedundancy forActive-active?
STP/RSTPL2Redundant switch links (loop-free)No (blocks backup)
MLAG / vPC / stackL2Dual-homed uplinksYes
LACP / EtherChannelL2Member links within one bundleYes
HSRP / VRRPL3Default gatewayNo (standby idle)
GLBPL3Default gatewayYes
ECMPL3Routed pathsYes
Load balancerL4/L7Server poolYes
AnycastL3Geographic/service endpointsYes

Designing redundant topologies

HA is layered — each tier removes SPOFs at its level:

  1. Component redundancy — dual power supplies (on separate PDUs/feeds), dual supervisors/route processors, dual NICs bonded, hot-swappable fans.
  2. Device redundancy — pairs of switches/routers/firewalls/LBs, tied together with FHRP (gateways), HA clustering (firewalls/LBs), and MLAG (switches).
  3. Link/path redundancy — dual uplinks (MLAG/ECMP), LACP bundles, and physically diverse fiber runs so a single backhoe cut can’t sever both.
  4. Site/geographic redundancy — replicate the service across data centers / cloud regions/AZs. Steer traffic with GSLB / DNS-based load balancing, anycast, or provider global LBs. This is where RTO/RPO and DR meet HA.

Canonical enterprise pattern — collapsed-core / two-tier: dual distribution/core switches (MLAG), each access switch dual-homed to both, FHRP (or an SVI on the MLAG pair) for the gateway VIP, dual firewalls in an HA pair, dual routers to two ISPs running BGP for internet redundancy.

Rules of thumb:

Best Practices

References