[{"data":1,"prerenderedAt":3925},["ShallowReactive",2],{"content-/topics/engineering/api-gateway-rate-limit-circuit-breaker-guide":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":5,"tags":11,"author":17,"featured":18,"series":19,"seriesOrder":20,"readingTime":21,"image":22,"body":23,"_type":3919,"_id":3920,"_source":3921,"_file":3922,"_stem":3923,"_extension":3924},"/topics/engineering/api-gateway-rate-limit-circuit-breaker-guide","engineering",false,"","API 网关与限流熔断降级完全指南：别让流量高峰把系统一波带走","API 网关不是转发器那么简单。本文系统讲清网关在认证、路由、限流、熔断、降级、灰度、观测中的职责，结合真实流量高峰场景，给出可落地的限流算法、熔断策略与故障隔离设计。","2026-03-08",[12,13,14,15,16],"API网关","限流","熔断","降级","高并发","小明",true,"large-scale-application-architecture",6,18,"/images/articles/api-gateway-rate-limit-circuit-breaker-guide-cover.jpg",{"type":24,"children":25,"toc":3854},"root",[26,34,40,45,58,78,83,88,106,111,116,140,145,173,178,182,189,194,222,227,234,339,345,350,373,378,401,413,416,422,428,435,440,446,451,457,462,490,495,501,506,511,523,526,532,537,545,550,555,578,583,589,706,712,717,735,746,751,754,760,766,771,776,781,786,792,797,802,815,821,826,849,854,860,871,876,894,900,1540,1545,1548,1554,1565,1571,1575,1598,1604,1608,1626,1632,1636,1659,1664,1711,1716,1719,1725,1730,1748,1754,1759,1787,1792,1815,1826,1832,1868,1874,2478,2483,2486,2492,2497,2502,2513,2519,2616,2622,2627,2632,2655,2661,2991,2996,3009,3012,3018,3024,3029,3062,3067,3073,3078,3083,3101,3107,3112,3145,3150,3168,3171,3177,3182,3187,3193,3221,3227,3255,3261,3389,3392,3398,3403,3409,3414,3420,3425,3431,3436,3442,3447,3453,3458,3464,3469,3586,3591,3594,3600,3605,3640,3645,3676,3681,3721,3726,3766,3769,3774,3779,3822,3827,3835,3840,3848],{"type":27,"tag":28,"props":29,"children":31},"element","h1",{"id":30},"api-网关与限流熔断降级完全指南别让流量高峰把系统一波带走",[32],{"type":33,"value":8},"text",{"type":27,"tag":35,"props":36,"children":37},"p",{},[38],{"type":33,"value":39},"很多系统真正崩掉的那一刻，不是机器突然坏了，而是请求太诚实了。",{"type":27,"tag":35,"props":41,"children":42},{},[43],{"type":33,"value":44},"用户来得太多，请求一个不落地全打进来，下游一个比一个努力，最后全链路一起趴下。",{"type":27,"tag":35,"props":46,"children":47},{},[48,50,56],{"type":33,"value":49},"这时候你会发现，系统不是死于“没有功能”，而是死于",{"type":27,"tag":51,"props":52,"children":53},"strong",{},[54],{"type":33,"value":55},"没有边界",{"type":33,"value":57},"。",{"type":27,"tag":59,"props":60,"children":61},"ul",{},[62,68,73],{"type":27,"tag":63,"props":64,"children":65},"li",{},[66],{"type":33,"value":67},"没人拦住异常流量",{"type":27,"tag":63,"props":69,"children":70},{},[71],{"type":33,"value":72},"没人把不同租户、不同接口、不同依赖分开对待",{"type":27,"tag":63,"props":74,"children":75},{},[76],{"type":33,"value":77},"没人决定什么时候该拒绝，什么时候该降级，什么时候该快速失败",{"type":27,"tag":35,"props":79,"children":80},{},[81],{"type":33,"value":82},"API 网关存在的价值，就在这里。",{"type":27,"tag":35,"props":84,"children":85},{},[86],{"type":33,"value":87},"很多团队把网关理解成：",{"type":27,"tag":59,"props":89,"children":90},{},[91,96,101],{"type":27,"tag":63,"props":92,"children":93},{},[94],{"type":33,"value":95},"路由转发",{"type":27,"tag":63,"props":97,"children":98},{},[99],{"type":33,"value":100},"统一鉴权",{"type":27,"tag":63,"props":102,"children":103},{},[104],{"type":33,"value":105},"配几个 header",{"type":27,"tag":35,"props":107,"children":108},{},[109],{"type":33,"value":110},"这些当然都是网关的工作，但远远不够。",{"type":27,"tag":35,"props":112,"children":113},{},[114],{"type":33,"value":115},"一个真正成熟的网关层，承担的是：",{"type":27,"tag":117,"props":118,"children":119},"ol",{},[120,125,130,135],{"type":27,"tag":63,"props":121,"children":122},{},[123],{"type":33,"value":124},"流量入口治理",{"type":27,"tag":63,"props":126,"children":127},{},[128],{"type":33,"value":129},"接口访问控制",{"type":27,"tag":63,"props":131,"children":132},{},[133],{"type":33,"value":134},"系统自我保护",{"type":27,"tag":63,"props":136,"children":137},{},[138],{"type":33,"value":139},"灰度和观测枢纽",{"type":27,"tag":35,"props":141,"children":142},{},[143],{"type":33,"value":144},"这篇文章想讲清楚的，不是“网关是什么”，而是：",{"type":27,"tag":59,"props":146,"children":147},{},[148,153,158,163,168],{"type":27,"tag":63,"props":149,"children":150},{},[151],{"type":33,"value":152},"什么时候需要 API 网关",{"type":27,"tag":63,"props":154,"children":155},{},[156],{"type":33,"value":157},"限流该放在网关、应用还是下游",{"type":27,"tag":63,"props":159,"children":160},{},[161],{"type":33,"value":162},"熔断和降级到底在保护谁",{"type":27,"tag":63,"props":164,"children":165},{},[166],{"type":33,"value":167},"怎样设计高峰期的系统保护策略",{"type":27,"tag":63,"props":169,"children":170},{},[171],{"type":33,"value":172},"网关做太多会不会变成新的单点风险",{"type":27,"tag":35,"props":174,"children":175},{},[176],{"type":33,"value":177},"如果你经历过大促、活动抢购、开放平台调用洪峰，这篇会很实用。",{"type":27,"tag":179,"props":180,"children":181},"hr",{},[],{"type":27,"tag":183,"props":184,"children":186},"h2",{"id":185},"一先讲本质网关是入口层的交通警察不是纯转发器",[187],{"type":33,"value":188},"一、先讲本质：网关是入口层的交通警察，不是纯转发器",{"type":27,"tag":35,"props":190,"children":191},{},[192],{"type":33,"value":193},"没有网关时，请求通常直接进入不同服务。看起来简单，但规模一大就会暴露问题：",{"type":27,"tag":59,"props":195,"children":196},{},[197,202,207,212,217],{"type":27,"tag":63,"props":198,"children":199},{},[200],{"type":33,"value":201},"认证逻辑散落各服务",{"type":27,"tag":63,"props":203,"children":204},{},[205],{"type":33,"value":206},"流量策略不统一",{"type":27,"tag":63,"props":208,"children":209},{},[210],{"type":33,"value":211},"错误码和限流口径不一致",{"type":27,"tag":63,"props":213,"children":214},{},[215],{"type":33,"value":216},"灰度、黑白名单、租户控制无统一入口",{"type":27,"tag":63,"props":218,"children":219},{},[220],{"type":33,"value":221},"一旦攻击或流量异常，保护动作只能各自为战",{"type":27,"tag":35,"props":223,"children":224},{},[225],{"type":33,"value":226},"网关真正解决的，是把这些“入口问题”收口到一层。",{"type":27,"tag":228,"props":229,"children":231},"h3",{"id":230},"_11-网关最核心的四类职责",[232],{"type":33,"value":233},"1.1 网关最核心的四类职责",{"type":27,"tag":235,"props":236,"children":237},"table",{},[238,262],{"type":27,"tag":239,"props":240,"children":241},"thead",{},[242],{"type":27,"tag":243,"props":244,"children":245},"tr",{},[246,252,257],{"type":27,"tag":247,"props":248,"children":249},"th",{},[250],{"type":33,"value":251},"职责",{"type":27,"tag":247,"props":253,"children":254},{},[255],{"type":33,"value":256},"解决什么问题",{"type":27,"tag":247,"props":258,"children":259},{},[260],{"type":33,"value":261},"为什么适合放网关",{"type":27,"tag":263,"props":264,"children":265},"tbody",{},[266,285,303,321],{"type":27,"tag":243,"props":267,"children":268},{},[269,275,280],{"type":27,"tag":270,"props":271,"children":272},"td",{},[273],{"type":33,"value":274},"认证与鉴权",{"type":27,"tag":270,"props":276,"children":277},{},[278],{"type":33,"value":279},"谁能进、能进到哪",{"type":27,"tag":270,"props":281,"children":282},{},[283],{"type":33,"value":284},"入口统一最省重复",{"type":27,"tag":243,"props":286,"children":287},{},[288,293,298],{"type":27,"tag":270,"props":289,"children":290},{},[291],{"type":33,"value":292},"路由与协议转换",{"type":27,"tag":270,"props":294,"children":295},{},[296],{"type":33,"value":297},"请求应该去哪里",{"type":27,"tag":270,"props":299,"children":300},{},[301],{"type":33,"value":302},"客户端和内部拓扑解耦",{"type":27,"tag":243,"props":304,"children":305},{},[306,311,316],{"type":27,"tag":270,"props":307,"children":308},{},[309],{"type":33,"value":310},"流量治理",{"type":27,"tag":270,"props":312,"children":313},{},[314],{"type":33,"value":315},"谁能进多少、何时拒绝",{"type":27,"tag":270,"props":317,"children":318},{},[319],{"type":33,"value":320},"入口层最先看到总流量",{"type":27,"tag":243,"props":322,"children":323},{},[324,329,334],{"type":27,"tag":270,"props":325,"children":326},{},[327],{"type":33,"value":328},"观测与灰度",{"type":27,"tag":270,"props":330,"children":331},{},[332],{"type":33,"value":333},"看得见、控得住",{"type":27,"tag":270,"props":335,"children":336},{},[337],{"type":33,"value":338},"最适合做统一埋点和分流",{"type":27,"tag":228,"props":340,"children":342},{"id":341},"_12-但网关不该做什么",[343],{"type":33,"value":344},"1.2 但网关不该做什么",{"type":27,"tag":35,"props":346,"children":347},{},[348],{"type":33,"value":349},"常见错误是把网关做成“什么都能塞的地方”：",{"type":27,"tag":59,"props":351,"children":352},{},[353,358,363,368],{"type":27,"tag":63,"props":354,"children":355},{},[356],{"type":33,"value":357},"大量业务规则放网关",{"type":27,"tag":63,"props":359,"children":360},{},[361],{"type":33,"value":362},"复杂聚合逻辑放网关",{"type":27,"tag":63,"props":364,"children":365},{},[366],{"type":33,"value":367},"数据库存取放网关",{"type":27,"tag":63,"props":369,"children":370},{},[371],{"type":33,"value":372},"长耗时计算也放网关",{"type":27,"tag":35,"props":374,"children":375},{},[376],{"type":33,"value":377},"这样做的结果通常是：",{"type":27,"tag":59,"props":379,"children":380},{},[381,386,391,396],{"type":27,"tag":63,"props":382,"children":383},{},[384],{"type":33,"value":385},"网关越来越胖",{"type":27,"tag":63,"props":387,"children":388},{},[389],{"type":33,"value":390},"入口层故障影响面最大",{"type":27,"tag":63,"props":392,"children":393},{},[394],{"type":33,"value":395},"调试复杂度飙升",{"type":27,"tag":63,"props":397,"children":398},{},[399],{"type":33,"value":400},"所有团队都来改网关",{"type":27,"tag":35,"props":402,"children":403},{},[404,406,411],{"type":33,"value":405},"网关要做的是",{"type":27,"tag":51,"props":407,"children":408},{},[409],{"type":33,"value":410},"保护和治理入口",{"type":33,"value":412},"，不是替代后端业务层。",{"type":27,"tag":179,"props":414,"children":415},{},[],{"type":27,"tag":183,"props":417,"children":419},{"id":418},"二什么时候真的需要网关",[420],{"type":33,"value":421},"二、什么时候真的需要网关",{"type":27,"tag":228,"props":423,"children":425},{"id":424},"_21-三种非常典型的场景",[426],{"type":33,"value":427},"2.1 三种非常典型的场景",{"type":27,"tag":429,"props":430,"children":432},"h4",{"id":431},"场景-a客户端多后端服务也多",[433],{"type":33,"value":434},"场景 A：客户端多，后端服务也多",{"type":27,"tag":35,"props":436,"children":437},{},[438],{"type":33,"value":439},"Web、App、小程序、开放平台都在访问不同服务，如果没有网关，认证、限流、协议适配会在每个服务里重复实现。",{"type":27,"tag":429,"props":441,"children":443},{"id":442},"场景-b入口流量不均匀且高峰明显",[444],{"type":33,"value":445},"场景 B：入口流量不均匀且高峰明显",{"type":27,"tag":35,"props":447,"children":448},{},[449],{"type":33,"value":450},"比如活动会场、抢购、开放 API 调用，这些请求会呈现明显峰值，没有入口层保护很容易直接把后端打穿。",{"type":27,"tag":429,"props":452,"children":454},{"id":453},"场景-c需要统一治理能力",[455],{"type":33,"value":456},"场景 C：需要统一治理能力",{"type":27,"tag":35,"props":458,"children":459},{},[460],{"type":33,"value":461},"包括：",{"type":27,"tag":59,"props":463,"children":464},{},[465,470,475,480,485],{"type":27,"tag":63,"props":466,"children":467},{},[468],{"type":33,"value":469},"黑白名单",{"type":27,"tag":63,"props":471,"children":472},{},[473],{"type":33,"value":474},"限流规则",{"type":27,"tag":63,"props":476,"children":477},{},[478],{"type":33,"value":479},"风险控制",{"type":27,"tag":63,"props":481,"children":482},{},[483],{"type":33,"value":484},"灰度发布",{"type":27,"tag":63,"props":486,"children":487},{},[488],{"type":33,"value":489},"统一日志和 tracing",{"type":27,"tag":35,"props":491,"children":492},{},[493],{"type":33,"value":494},"这些事情放在服务内部做，不但重复，还很难保证口径一致。",{"type":27,"tag":228,"props":496,"children":498},{"id":497},"_22-什么情况下别把网关搞太重",[499],{"type":33,"value":500},"2.2 什么情况下别把网关搞太重",{"type":27,"tag":35,"props":502,"children":503},{},[504],{"type":33,"value":505},"如果系统还很小、入口单一、流量平稳，过早做重量级网关平台可能收益不大。先用轻量代理 + 统一中间件，也许更合适。",{"type":27,"tag":35,"props":507,"children":508},{},[509],{"type":33,"value":510},"问题不在于“有没有网关”，而在于：",{"type":27,"tag":512,"props":513,"children":514},"blockquote",{},[515],{"type":27,"tag":35,"props":516,"children":517},{},[518],{"type":27,"tag":51,"props":519,"children":520},{},[521],{"type":33,"value":522},"你的入口复杂度，是否已经大到值得为统一治理单独付出成本。",{"type":27,"tag":179,"props":524,"children":525},{},[],{"type":27,"tag":183,"props":527,"children":529},{"id":528},"三限流到底限什么不是只限-qps而是限风险",[530],{"type":33,"value":531},"三、限流到底限什么：不是只限 QPS，而是限风险",{"type":27,"tag":35,"props":533,"children":534},{},[535],{"type":33,"value":536},"很多人第一次做限流，最先想到的是：",{"type":27,"tag":512,"props":538,"children":539},{},[540],{"type":27,"tag":35,"props":541,"children":542},{},[543],{"type":33,"value":544},"每秒最多 1000 个请求。",{"type":27,"tag":35,"props":546,"children":547},{},[548],{"type":33,"value":549},"这个思路太粗。",{"type":27,"tag":35,"props":551,"children":552},{},[553],{"type":33,"value":554},"系统真正需要限制的，通常是不同维度上的风险暴露：",{"type":27,"tag":59,"props":556,"children":557},{},[558,563,568,573],{"type":27,"tag":63,"props":559,"children":560},{},[561],{"type":33,"value":562},"某个租户打得太猛",{"type":27,"tag":63,"props":564,"children":565},{},[566],{"type":33,"value":567},"某个用户在刷接口",{"type":27,"tag":63,"props":569,"children":570},{},[571],{"type":33,"value":572},"某个热点活动流量突然爆发",{"type":27,"tag":63,"props":574,"children":575},{},[576],{"type":33,"value":577},"某个高成本接口被持续滥用",{"type":27,"tag":35,"props":579,"children":580},{},[581],{"type":33,"value":582},"所以限流不只是“全局一个数”，而是分层次的。",{"type":27,"tag":228,"props":584,"children":586},{"id":585},"_31-常见限流维度",[587],{"type":33,"value":588},"3.1 常见限流维度",{"type":27,"tag":235,"props":590,"children":591},{},[592,613],{"type":27,"tag":239,"props":593,"children":594},{},[595],{"type":27,"tag":243,"props":596,"children":597},{},[598,603,608],{"type":27,"tag":247,"props":599,"children":600},{},[601],{"type":33,"value":602},"维度",{"type":27,"tag":247,"props":604,"children":605},{},[606],{"type":33,"value":607},"适用场景",{"type":27,"tag":247,"props":609,"children":610},{},[611],{"type":33,"value":612},"例子",{"type":27,"tag":263,"props":614,"children":615},{},[616,634,652,670,688],{"type":27,"tag":243,"props":617,"children":618},{},[619,624,629],{"type":27,"tag":270,"props":620,"children":621},{},[622],{"type":33,"value":623},"全局限流",{"type":27,"tag":270,"props":625,"children":626},{},[627],{"type":33,"value":628},"保护整体系统",{"type":27,"tag":270,"props":630,"children":631},{},[632],{"type":33,"value":633},"总入口每秒不超过 5 万",{"type":27,"tag":243,"props":635,"children":636},{},[637,642,647],{"type":27,"tag":270,"props":638,"children":639},{},[640],{"type":33,"value":641},"接口限流",{"type":27,"tag":270,"props":643,"children":644},{},[645],{"type":33,"value":646},"高成本接口保护",{"type":27,"tag":270,"props":648,"children":649},{},[650],{"type":33,"value":651},"下单接口每秒不超过 2000",{"type":27,"tag":243,"props":653,"children":654},{},[655,660,665],{"type":27,"tag":270,"props":656,"children":657},{},[658],{"type":33,"value":659},"用户限流",{"type":27,"tag":270,"props":661,"children":662},{},[663],{"type":33,"value":664},"防刷、防滥用",{"type":27,"tag":270,"props":666,"children":667},{},[668],{"type":33,"value":669},"单用户每分钟 60 次",{"type":27,"tag":243,"props":671,"children":672},{},[673,678,683],{"type":27,"tag":270,"props":674,"children":675},{},[676],{"type":33,"value":677},"租户限流",{"type":27,"tag":270,"props":679,"children":680},{},[681],{"type":33,"value":682},"多租户隔离",{"type":27,"tag":270,"props":684,"children":685},{},[686],{"type":33,"value":687},"大客户不能把中小客户挤死",{"type":27,"tag":243,"props":689,"children":690},{},[691,696,701],{"type":27,"tag":270,"props":692,"children":693},{},[694],{"type":33,"value":695},"下游限流",{"type":27,"tag":270,"props":697,"children":698},{},[699],{"type":33,"value":700},"保护稀缺依赖",{"type":27,"tag":270,"props":702,"children":703},{},[704],{"type":33,"value":705},"调支付网关 QPS 不超过 500",{"type":27,"tag":228,"props":707,"children":709},{"id":708},"_32-限流的目的不是公平而是保核心",[710],{"type":33,"value":711},"3.2 限流的目的不是“公平”，而是“保核心”",{"type":27,"tag":35,"props":713,"children":714},{},[715],{"type":33,"value":716},"大促期间最重要的，不一定是让所有请求都进来，而是让：",{"type":27,"tag":59,"props":718,"children":719},{},[720,725,730],{"type":27,"tag":63,"props":721,"children":722},{},[723],{"type":33,"value":724},"下单主链路优先",{"type":27,"tag":63,"props":726,"children":727},{},[728],{"type":33,"value":729},"登录和支付优先",{"type":27,"tag":63,"props":731,"children":732},{},[733],{"type":33,"value":734},"非核心接口必要时降级或直接拒绝",{"type":27,"tag":35,"props":736,"children":737},{},[738,740,745],{"type":33,"value":739},"这叫",{"type":27,"tag":51,"props":741,"children":742},{},[743],{"type":33,"value":744},"流量分级",{"type":33,"value":57},{"type":27,"tag":35,"props":747,"children":748},{},[749],{"type":33,"value":750},"没有分级的限流，很多时候只是平均地拒绝所有人，听起来公平，业务上很亏。",{"type":27,"tag":179,"props":752,"children":753},{},[],{"type":27,"tag":183,"props":755,"children":757},{"id":756},"四常用限流算法到底怎么选",[758],{"type":33,"value":759},"四、常用限流算法，到底怎么选",{"type":27,"tag":228,"props":761,"children":763},{"id":762},"_41-固定窗口简单但边界突刺明显",[764],{"type":33,"value":765},"4.1 固定窗口：简单，但边界突刺明显",{"type":27,"tag":35,"props":767,"children":768},{},[769],{"type":33,"value":770},"固定窗口就是每个时间窗口统计一次。",{"type":27,"tag":35,"props":772,"children":773},{},[774],{"type":33,"value":775},"优点：好实现。",{"type":27,"tag":35,"props":777,"children":778},{},[779],{"type":33,"value":780},"缺点：边界时刻可能双倍突刺。",{"type":27,"tag":35,"props":782,"children":783},{},[784],{"type":33,"value":785},"例如最后 1 秒打满 100 次，下一秒开头再打满 100 次，短时间会冲出 200 次。",{"type":27,"tag":228,"props":787,"children":789},{"id":788},"_42-滑动窗口更平滑但实现稍复杂",[790],{"type":33,"value":791},"4.2 滑动窗口：更平滑，但实现稍复杂",{"type":27,"tag":35,"props":793,"children":794},{},[795],{"type":33,"value":796},"把统计窗口细分后滑动计算，更贴近真实流量。",{"type":27,"tag":35,"props":798,"children":799},{},[800],{"type":33,"value":801},"适合：",{"type":27,"tag":59,"props":803,"children":804},{},[805,810],{"type":27,"tag":63,"props":806,"children":807},{},[808],{"type":33,"value":809},"风险控制接口",{"type":27,"tag":63,"props":811,"children":812},{},[813],{"type":33,"value":814},"对突刺更敏感的依赖",{"type":27,"tag":228,"props":816,"children":818},{"id":817},"_43-令牌桶适合控制平均速率同时允许有限突发",[819],{"type":33,"value":820},"4.3 令牌桶：适合控制平均速率，同时允许有限突发",{"type":27,"tag":35,"props":822,"children":823},{},[824],{"type":33,"value":825},"这是工程里最常见也最好用的一类算法。",{"type":27,"tag":59,"props":827,"children":828},{},[829,834,839,844],{"type":27,"tag":63,"props":830,"children":831},{},[832],{"type":33,"value":833},"令牌按固定速率生成",{"type":27,"tag":63,"props":835,"children":836},{},[837],{"type":33,"value":838},"请求来时拿令牌",{"type":27,"tag":63,"props":840,"children":841},{},[842],{"type":33,"value":843},"有令牌就放行",{"type":27,"tag":63,"props":845,"children":846},{},[847],{"type":33,"value":848},"没令牌就拒绝或排队",{"type":27,"tag":35,"props":850,"children":851},{},[852],{"type":33,"value":853},"优点：既能控制长期速率，又能容忍短时突发。",{"type":27,"tag":228,"props":855,"children":857},{"id":856},"_44-漏桶适合把突发流量整形成稳定输出",[858],{"type":33,"value":859},"4.4 漏桶：适合把突发流量整形成稳定输出",{"type":27,"tag":35,"props":861,"children":862},{},[863,865,870],{"type":33,"value":864},"如果下游系统承受不了尖峰，漏桶更适合。它强调",{"type":27,"tag":51,"props":866,"children":867},{},[868],{"type":33,"value":869},"固定流出速率",{"type":33,"value":57},{"type":27,"tag":35,"props":872,"children":873},{},[874],{"type":33,"value":875},"适用于：",{"type":27,"tag":59,"props":877,"children":878},{},[879,884,889],{"type":27,"tag":63,"props":880,"children":881},{},[882],{"type":33,"value":883},"某些老旧下游系统",{"type":27,"tag":63,"props":885,"children":886},{},[887],{"type":33,"value":888},"第三方依赖调用",{"type":27,"tag":63,"props":890,"children":891},{},[892],{"type":33,"value":893},"对流量平滑性要求更高的链路",{"type":27,"tag":228,"props":895,"children":897},{"id":896},"_45-一个简单的令牌桶示例",[898],{"type":33,"value":899},"4.5 一个简单的令牌桶示例",{"type":27,"tag":901,"props":902,"children":906},"pre",{"className":903,"code":904,"language":905,"meta":7,"style":7},"language-ts shiki shiki-themes github-dark","class TokenBucket {\n  private tokens: number\n  private lastRefillAt: number\n\n  constructor(\n    private capacity: number,\n    private refillPerSecond: number,\n  ) {\n    this.tokens = capacity\n    this.lastRefillAt = Date.now()\n  }\n\n  allow(): boolean {\n    const now = Date.now()\n    const elapsedSeconds = (now - this.lastRefillAt) / 1000\n    const refill = Math.floor(elapsedSeconds * this.refillPerSecond)\n\n    if (refill > 0) {\n      this.tokens = Math.min(this.capacity, this.tokens + refill)\n      this.lastRefillAt = now\n    }\n\n    if (this.tokens \u003C= 0) {\n      return false\n    }\n\n    this.tokens -= 1\n    return true\n  }\n}\n","ts",[907],{"type":27,"tag":908,"props":909,"children":910},"code",{"__ignoreMap":7},[911,935,961,982,991,1005,1032,1057,1066,1090,1122,1131,1139,1166,1197,1244,1290,1298,1326,1385,1406,1415,1423,1457,1471,1479,1487,1509,1523,1531],{"type":27,"tag":912,"props":913,"children":916},"span",{"class":914,"line":915},"line",1,[917,923,929],{"type":27,"tag":912,"props":918,"children":920},{"style":919},"--shiki-default:#F97583",[921],{"type":33,"value":922},"class",{"type":27,"tag":912,"props":924,"children":926},{"style":925},"--shiki-default:#B392F0",[927],{"type":33,"value":928}," TokenBucket",{"type":27,"tag":912,"props":930,"children":932},{"style":931},"--shiki-default:#E1E4E8",[933],{"type":33,"value":934}," {\n",{"type":27,"tag":912,"props":936,"children":938},{"class":914,"line":937},2,[939,944,950,955],{"type":27,"tag":912,"props":940,"children":941},{"style":919},[942],{"type":33,"value":943},"  private",{"type":27,"tag":912,"props":945,"children":947},{"style":946},"--shiki-default:#FFAB70",[948],{"type":33,"value":949}," tokens",{"type":27,"tag":912,"props":951,"children":952},{"style":919},[953],{"type":33,"value":954},":",{"type":27,"tag":912,"props":956,"children":958},{"style":957},"--shiki-default:#79B8FF",[959],{"type":33,"value":960}," number\n",{"type":27,"tag":912,"props":962,"children":964},{"class":914,"line":963},3,[965,969,974,978],{"type":27,"tag":912,"props":966,"children":967},{"style":919},[968],{"type":33,"value":943},{"type":27,"tag":912,"props":970,"children":971},{"style":946},[972],{"type":33,"value":973}," lastRefillAt",{"type":27,"tag":912,"props":975,"children":976},{"style":919},[977],{"type":33,"value":954},{"type":27,"tag":912,"props":979,"children":980},{"style":957},[981],{"type":33,"value":960},{"type":27,"tag":912,"props":983,"children":985},{"class":914,"line":984},4,[986],{"type":27,"tag":912,"props":987,"children":988},{"emptyLinePlaceholder":18},[989],{"type":33,"value":990},"\n",{"type":27,"tag":912,"props":992,"children":994},{"class":914,"line":993},5,[995,1000],{"type":27,"tag":912,"props":996,"children":997},{"style":919},[998],{"type":33,"value":999},"  constructor",{"type":27,"tag":912,"props":1001,"children":1002},{"style":931},[1003],{"type":33,"value":1004},"(\n",{"type":27,"tag":912,"props":1006,"children":1007},{"class":914,"line":20},[1008,1013,1018,1022,1027],{"type":27,"tag":912,"props":1009,"children":1010},{"style":919},[1011],{"type":33,"value":1012},"    private",{"type":27,"tag":912,"props":1014,"children":1015},{"style":946},[1016],{"type":33,"value":1017}," capacity",{"type":27,"tag":912,"props":1019,"children":1020},{"style":919},[1021],{"type":33,"value":954},{"type":27,"tag":912,"props":1023,"children":1024},{"style":957},[1025],{"type":33,"value":1026}," number",{"type":27,"tag":912,"props":1028,"children":1029},{"style":931},[1030],{"type":33,"value":1031},",\n",{"type":27,"tag":912,"props":1033,"children":1035},{"class":914,"line":1034},7,[1036,1040,1045,1049,1053],{"type":27,"tag":912,"props":1037,"children":1038},{"style":919},[1039],{"type":33,"value":1012},{"type":27,"tag":912,"props":1041,"children":1042},{"style":946},[1043],{"type":33,"value":1044}," refillPerSecond",{"type":27,"tag":912,"props":1046,"children":1047},{"style":919},[1048],{"type":33,"value":954},{"type":27,"tag":912,"props":1050,"children":1051},{"style":957},[1052],{"type":33,"value":1026},{"type":27,"tag":912,"props":1054,"children":1055},{"style":931},[1056],{"type":33,"value":1031},{"type":27,"tag":912,"props":1058,"children":1060},{"class":914,"line":1059},8,[1061],{"type":27,"tag":912,"props":1062,"children":1063},{"style":931},[1064],{"type":33,"value":1065},"  ) {\n",{"type":27,"tag":912,"props":1067,"children":1069},{"class":914,"line":1068},9,[1070,1075,1080,1085],{"type":27,"tag":912,"props":1071,"children":1072},{"style":957},[1073],{"type":33,"value":1074},"    this",{"type":27,"tag":912,"props":1076,"children":1077},{"style":931},[1078],{"type":33,"value":1079},".tokens ",{"type":27,"tag":912,"props":1081,"children":1082},{"style":919},[1083],{"type":33,"value":1084},"=",{"type":27,"tag":912,"props":1086,"children":1087},{"style":931},[1088],{"type":33,"value":1089}," capacity\n",{"type":27,"tag":912,"props":1091,"children":1093},{"class":914,"line":1092},10,[1094,1098,1103,1107,1112,1117],{"type":27,"tag":912,"props":1095,"children":1096},{"style":957},[1097],{"type":33,"value":1074},{"type":27,"tag":912,"props":1099,"children":1100},{"style":931},[1101],{"type":33,"value":1102},".lastRefillAt ",{"type":27,"tag":912,"props":1104,"children":1105},{"style":919},[1106],{"type":33,"value":1084},{"type":27,"tag":912,"props":1108,"children":1109},{"style":931},[1110],{"type":33,"value":1111}," Date.",{"type":27,"tag":912,"props":1113,"children":1114},{"style":925},[1115],{"type":33,"value":1116},"now",{"type":27,"tag":912,"props":1118,"children":1119},{"style":931},[1120],{"type":33,"value":1121},"()\n",{"type":27,"tag":912,"props":1123,"children":1125},{"class":914,"line":1124},11,[1126],{"type":27,"tag":912,"props":1127,"children":1128},{"style":931},[1129],{"type":33,"value":1130},"  }\n",{"type":27,"tag":912,"props":1132,"children":1134},{"class":914,"line":1133},12,[1135],{"type":27,"tag":912,"props":1136,"children":1137},{"emptyLinePlaceholder":18},[1138],{"type":33,"value":990},{"type":27,"tag":912,"props":1140,"children":1142},{"class":914,"line":1141},13,[1143,1148,1153,1157,1162],{"type":27,"tag":912,"props":1144,"children":1145},{"style":925},[1146],{"type":33,"value":1147},"  allow",{"type":27,"tag":912,"props":1149,"children":1150},{"style":931},[1151],{"type":33,"value":1152},"()",{"type":27,"tag":912,"props":1154,"children":1155},{"style":919},[1156],{"type":33,"value":954},{"type":27,"tag":912,"props":1158,"children":1159},{"style":957},[1160],{"type":33,"value":1161}," boolean",{"type":27,"tag":912,"props":1163,"children":1164},{"style":931},[1165],{"type":33,"value":934},{"type":27,"tag":912,"props":1167,"children":1169},{"class":914,"line":1168},14,[1170,1175,1180,1185,1189,1193],{"type":27,"tag":912,"props":1171,"children":1172},{"style":919},[1173],{"type":33,"value":1174},"    const",{"type":27,"tag":912,"props":1176,"children":1177},{"style":957},[1178],{"type":33,"value":1179}," now",{"type":27,"tag":912,"props":1181,"children":1182},{"style":919},[1183],{"type":33,"value":1184}," =",{"type":27,"tag":912,"props":1186,"children":1187},{"style":931},[1188],{"type":33,"value":1111},{"type":27,"tag":912,"props":1190,"children":1191},{"style":925},[1192],{"type":33,"value":1116},{"type":27,"tag":912,"props":1194,"children":1195},{"style":931},[1196],{"type":33,"value":1121},{"type":27,"tag":912,"props":1198,"children":1200},{"class":914,"line":1199},15,[1201,1205,1210,1214,1219,1224,1229,1234,1239],{"type":27,"tag":912,"props":1202,"children":1203},{"style":919},[1204],{"type":33,"value":1174},{"type":27,"tag":912,"props":1206,"children":1207},{"style":957},[1208],{"type":33,"value":1209}," elapsedSeconds",{"type":27,"tag":912,"props":1211,"children":1212},{"style":919},[1213],{"type":33,"value":1184},{"type":27,"tag":912,"props":1215,"children":1216},{"style":931},[1217],{"type":33,"value":1218}," (now ",{"type":27,"tag":912,"props":1220,"children":1221},{"style":919},[1222],{"type":33,"value":1223},"-",{"type":27,"tag":912,"props":1225,"children":1226},{"style":957},[1227],{"type":33,"value":1228}," this",{"type":27,"tag":912,"props":1230,"children":1231},{"style":931},[1232],{"type":33,"value":1233},".lastRefillAt) ",{"type":27,"tag":912,"props":1235,"children":1236},{"style":919},[1237],{"type":33,"value":1238},"/",{"type":27,"tag":912,"props":1240,"children":1241},{"style":957},[1242],{"type":33,"value":1243}," 1000\n",{"type":27,"tag":912,"props":1245,"children":1247},{"class":914,"line":1246},16,[1248,1252,1257,1261,1266,1271,1276,1281,1285],{"type":27,"tag":912,"props":1249,"children":1250},{"style":919},[1251],{"type":33,"value":1174},{"type":27,"tag":912,"props":1253,"children":1254},{"style":957},[1255],{"type":33,"value":1256}," refill",{"type":27,"tag":912,"props":1258,"children":1259},{"style":919},[1260],{"type":33,"value":1184},{"type":27,"tag":912,"props":1262,"children":1263},{"style":931},[1264],{"type":33,"value":1265}," Math.",{"type":27,"tag":912,"props":1267,"children":1268},{"style":925},[1269],{"type":33,"value":1270},"floor",{"type":27,"tag":912,"props":1272,"children":1273},{"style":931},[1274],{"type":33,"value":1275},"(elapsedSeconds ",{"type":27,"tag":912,"props":1277,"children":1278},{"style":919},[1279],{"type":33,"value":1280},"*",{"type":27,"tag":912,"props":1282,"children":1283},{"style":957},[1284],{"type":33,"value":1228},{"type":27,"tag":912,"props":1286,"children":1287},{"style":931},[1288],{"type":33,"value":1289},".refillPerSecond)\n",{"type":27,"tag":912,"props":1291,"children":1293},{"class":914,"line":1292},17,[1294],{"type":27,"tag":912,"props":1295,"children":1296},{"emptyLinePlaceholder":18},[1297],{"type":33,"value":990},{"type":27,"tag":912,"props":1299,"children":1300},{"class":914,"line":21},[1301,1306,1311,1316,1321],{"type":27,"tag":912,"props":1302,"children":1303},{"style":919},[1304],{"type":33,"value":1305},"    if",{"type":27,"tag":912,"props":1307,"children":1308},{"style":931},[1309],{"type":33,"value":1310}," (refill ",{"type":27,"tag":912,"props":1312,"children":1313},{"style":919},[1314],{"type":33,"value":1315},">",{"type":27,"tag":912,"props":1317,"children":1318},{"style":957},[1319],{"type":33,"value":1320}," 0",{"type":27,"tag":912,"props":1322,"children":1323},{"style":931},[1324],{"type":33,"value":1325},") {\n",{"type":27,"tag":912,"props":1327,"children":1329},{"class":914,"line":1328},19,[1330,1335,1339,1343,1347,1352,1357,1362,1367,1371,1375,1380],{"type":27,"tag":912,"props":1331,"children":1332},{"style":957},[1333],{"type":33,"value":1334},"      this",{"type":27,"tag":912,"props":1336,"children":1337},{"style":931},[1338],{"type":33,"value":1079},{"type":27,"tag":912,"props":1340,"children":1341},{"style":919},[1342],{"type":33,"value":1084},{"type":27,"tag":912,"props":1344,"children":1345},{"style":931},[1346],{"type":33,"value":1265},{"type":27,"tag":912,"props":1348,"children":1349},{"style":925},[1350],{"type":33,"value":1351},"min",{"type":27,"tag":912,"props":1353,"children":1354},{"style":931},[1355],{"type":33,"value":1356},"(",{"type":27,"tag":912,"props":1358,"children":1359},{"style":957},[1360],{"type":33,"value":1361},"this",{"type":27,"tag":912,"props":1363,"children":1364},{"style":931},[1365],{"type":33,"value":1366},".capacity, ",{"type":27,"tag":912,"props":1368,"children":1369},{"style":957},[1370],{"type":33,"value":1361},{"type":27,"tag":912,"props":1372,"children":1373},{"style":931},[1374],{"type":33,"value":1079},{"type":27,"tag":912,"props":1376,"children":1377},{"style":919},[1378],{"type":33,"value":1379},"+",{"type":27,"tag":912,"props":1381,"children":1382},{"style":931},[1383],{"type":33,"value":1384}," refill)\n",{"type":27,"tag":912,"props":1386,"children":1388},{"class":914,"line":1387},20,[1389,1393,1397,1401],{"type":27,"tag":912,"props":1390,"children":1391},{"style":957},[1392],{"type":33,"value":1334},{"type":27,"tag":912,"props":1394,"children":1395},{"style":931},[1396],{"type":33,"value":1102},{"type":27,"tag":912,"props":1398,"children":1399},{"style":919},[1400],{"type":33,"value":1084},{"type":27,"tag":912,"props":1402,"children":1403},{"style":931},[1404],{"type":33,"value":1405}," now\n",{"type":27,"tag":912,"props":1407,"children":1409},{"class":914,"line":1408},21,[1410],{"type":27,"tag":912,"props":1411,"children":1412},{"style":931},[1413],{"type":33,"value":1414},"    }\n",{"type":27,"tag":912,"props":1416,"children":1418},{"class":914,"line":1417},22,[1419],{"type":27,"tag":912,"props":1420,"children":1421},{"emptyLinePlaceholder":18},[1422],{"type":33,"value":990},{"type":27,"tag":912,"props":1424,"children":1426},{"class":914,"line":1425},23,[1427,1431,1436,1440,1444,1449,1453],{"type":27,"tag":912,"props":1428,"children":1429},{"style":919},[1430],{"type":33,"value":1305},{"type":27,"tag":912,"props":1432,"children":1433},{"style":931},[1434],{"type":33,"value":1435}," (",{"type":27,"tag":912,"props":1437,"children":1438},{"style":957},[1439],{"type":33,"value":1361},{"type":27,"tag":912,"props":1441,"children":1442},{"style":931},[1443],{"type":33,"value":1079},{"type":27,"tag":912,"props":1445,"children":1446},{"style":919},[1447],{"type":33,"value":1448},"\u003C=",{"type":27,"tag":912,"props":1450,"children":1451},{"style":957},[1452],{"type":33,"value":1320},{"type":27,"tag":912,"props":1454,"children":1455},{"style":931},[1456],{"type":33,"value":1325},{"type":27,"tag":912,"props":1458,"children":1460},{"class":914,"line":1459},24,[1461,1466],{"type":27,"tag":912,"props":1462,"children":1463},{"style":919},[1464],{"type":33,"value":1465},"      return",{"type":27,"tag":912,"props":1467,"children":1468},{"style":957},[1469],{"type":33,"value":1470}," false\n",{"type":27,"tag":912,"props":1472,"children":1474},{"class":914,"line":1473},25,[1475],{"type":27,"tag":912,"props":1476,"children":1477},{"style":931},[1478],{"type":33,"value":1414},{"type":27,"tag":912,"props":1480,"children":1482},{"class":914,"line":1481},26,[1483],{"type":27,"tag":912,"props":1484,"children":1485},{"emptyLinePlaceholder":18},[1486],{"type":33,"value":990},{"type":27,"tag":912,"props":1488,"children":1490},{"class":914,"line":1489},27,[1491,1495,1499,1504],{"type":27,"tag":912,"props":1492,"children":1493},{"style":957},[1494],{"type":33,"value":1074},{"type":27,"tag":912,"props":1496,"children":1497},{"style":931},[1498],{"type":33,"value":1079},{"type":27,"tag":912,"props":1500,"children":1501},{"style":919},[1502],{"type":33,"value":1503},"-=",{"type":27,"tag":912,"props":1505,"children":1506},{"style":957},[1507],{"type":33,"value":1508}," 1\n",{"type":27,"tag":912,"props":1510,"children":1512},{"class":914,"line":1511},28,[1513,1518],{"type":27,"tag":912,"props":1514,"children":1515},{"style":919},[1516],{"type":33,"value":1517},"    return",{"type":27,"tag":912,"props":1519,"children":1520},{"style":957},[1521],{"type":33,"value":1522}," true\n",{"type":27,"tag":912,"props":1524,"children":1526},{"class":914,"line":1525},29,[1527],{"type":27,"tag":912,"props":1528,"children":1529},{"style":931},[1530],{"type":33,"value":1130},{"type":27,"tag":912,"props":1532,"children":1534},{"class":914,"line":1533},30,[1535],{"type":27,"tag":912,"props":1536,"children":1537},{"style":931},[1538],{"type":33,"value":1539},"}\n",{"type":27,"tag":35,"props":1541,"children":1542},{},[1543],{"type":33,"value":1544},"线上通常不会直接用进程内版本做全局限流，但这段代码能说明核心思想。",{"type":27,"tag":179,"props":1546,"children":1547},{},[],{"type":27,"tag":183,"props":1549,"children":1551},{"id":1550},"五限流该放哪一层网关应用还是下游",[1552],{"type":33,"value":1553},"五、限流该放哪一层：网关、应用、还是下游",{"type":27,"tag":35,"props":1555,"children":1556},{},[1557,1559,1564],{"type":33,"value":1558},"正确答案通常不是“选一个”，而是",{"type":27,"tag":51,"props":1560,"children":1561},{},[1562],{"type":33,"value":1563},"分层限流",{"type":33,"value":57},{"type":27,"tag":228,"props":1566,"children":1568},{"id":1567},"_51-网关限流挡住最前面的风险",[1569],{"type":33,"value":1570},"5.1 网关限流：挡住最前面的风险",{"type":27,"tag":35,"props":1572,"children":1573},{},[1574],{"type":33,"value":801},{"type":27,"tag":59,"props":1576,"children":1577},{},[1578,1583,1588,1593],{"type":27,"tag":63,"props":1579,"children":1580},{},[1581],{"type":33,"value":1582},"IP / 用户 / 租户维度控制",{"type":27,"tag":63,"props":1584,"children":1585},{},[1586],{"type":33,"value":1587},"公开 API 防刷",{"type":27,"tag":63,"props":1589,"children":1590},{},[1591],{"type":33,"value":1592},"活动入口洪峰控制",{"type":27,"tag":63,"props":1594,"children":1595},{},[1596],{"type":33,"value":1597},"黑白名单和风控前置",{"type":27,"tag":228,"props":1599,"children":1601},{"id":1600},"_52-应用层限流保护具体业务能力",[1602],{"type":33,"value":1603},"5.2 应用层限流：保护具体业务能力",{"type":27,"tag":35,"props":1605,"children":1606},{},[1607],{"type":33,"value":801},{"type":27,"tag":59,"props":1609,"children":1610},{},[1611,1616,1621],{"type":27,"tag":63,"props":1612,"children":1613},{},[1614],{"type":33,"value":1615},"某个高成本业务逻辑",{"type":27,"tag":63,"props":1617,"children":1618},{},[1619],{"type":33,"value":1620},"某个热点聚合接口",{"type":27,"tag":63,"props":1622,"children":1623},{},[1624],{"type":33,"value":1625},"依赖某些昂贵资源的场景",{"type":27,"tag":228,"props":1627,"children":1629},{"id":1628},"_53-下游依赖限流保护最脆弱资源",[1630],{"type":33,"value":1631},"5.3 下游依赖限流：保护最脆弱资源",{"type":27,"tag":35,"props":1633,"children":1634},{},[1635],{"type":33,"value":801},{"type":27,"tag":59,"props":1637,"children":1638},{},[1639,1644,1649,1654],{"type":27,"tag":63,"props":1640,"children":1641},{},[1642],{"type":33,"value":1643},"支付渠道",{"type":27,"tag":63,"props":1645,"children":1646},{},[1647],{"type":33,"value":1648},"短信服务",{"type":27,"tag":63,"props":1650,"children":1651},{},[1652],{"type":33,"value":1653},"搜索集群",{"type":27,"tag":63,"props":1655,"children":1656},{},[1657],{"type":33,"value":1658},"老系统或第三方接口",{"type":27,"tag":35,"props":1660,"children":1661},{},[1662],{"type":33,"value":1663},"一个成熟体系通常是：",{"type":27,"tag":901,"props":1665,"children":1668},{"className":1666,"code":1667,"language":33,"meta":7,"style":7},"language-text shiki shiki-themes github-dark","网关先挡总流量和明显异常\n  ↓\n应用层控制业务热点和高成本路径\n  ↓\n依赖调用侧再保护具体下游\n",[1669],{"type":27,"tag":908,"props":1670,"children":1671},{"__ignoreMap":7},[1672,1680,1688,1696,1703],{"type":27,"tag":912,"props":1673,"children":1674},{"class":914,"line":915},[1675],{"type":27,"tag":912,"props":1676,"children":1677},{},[1678],{"type":33,"value":1679},"网关先挡总流量和明显异常\n",{"type":27,"tag":912,"props":1681,"children":1682},{"class":914,"line":937},[1683],{"type":27,"tag":912,"props":1684,"children":1685},{},[1686],{"type":33,"value":1687},"  ↓\n",{"type":27,"tag":912,"props":1689,"children":1690},{"class":914,"line":963},[1691],{"type":27,"tag":912,"props":1692,"children":1693},{},[1694],{"type":33,"value":1695},"应用层控制业务热点和高成本路径\n",{"type":27,"tag":912,"props":1697,"children":1698},{"class":914,"line":984},[1699],{"type":27,"tag":912,"props":1700,"children":1701},{},[1702],{"type":33,"value":1687},{"type":27,"tag":912,"props":1704,"children":1705},{"class":914,"line":993},[1706],{"type":27,"tag":912,"props":1707,"children":1708},{},[1709],{"type":33,"value":1710},"依赖调用侧再保护具体下游\n",{"type":27,"tag":35,"props":1712,"children":1713},{},[1714],{"type":33,"value":1715},"如果只在最末端限流，你等于让大部分无效请求已经穿过了整个系统。",{"type":27,"tag":179,"props":1717,"children":1718},{},[],{"type":27,"tag":183,"props":1720,"children":1722},{"id":1721},"六熔断到底在保护谁",[1723],{"type":33,"value":1724},"六、熔断到底在保护谁",{"type":27,"tag":35,"props":1726,"children":1727},{},[1728],{"type":33,"value":1729},"很多人以为熔断是“某个接口挂了就报错”。其实它真正保护的是：",{"type":27,"tag":117,"props":1731,"children":1732},{},[1733,1738,1743],{"type":27,"tag":63,"props":1734,"children":1735},{},[1736],{"type":33,"value":1737},"调用方线程池 / 连接池",{"type":27,"tag":63,"props":1739,"children":1740},{},[1741],{"type":33,"value":1742},"下游已经不健康的系统",{"type":27,"tag":63,"props":1744,"children":1745},{},[1746],{"type":33,"value":1747},"整条调用链的剩余可用性",{"type":27,"tag":228,"props":1749,"children":1751},{"id":1750},"_61-一个典型故障传播过程",[1752],{"type":33,"value":1753},"6.1 一个典型故障传播过程",{"type":27,"tag":35,"props":1755,"children":1756},{},[1757],{"type":33,"value":1758},"没有熔断时：",{"type":27,"tag":59,"props":1760,"children":1761},{},[1762,1767,1772,1777,1782],{"type":27,"tag":63,"props":1763,"children":1764},{},[1765],{"type":33,"value":1766},"下游服务变慢",{"type":27,"tag":63,"props":1768,"children":1769},{},[1770],{"type":33,"value":1771},"上游请求持续堆积等待",{"type":27,"tag":63,"props":1773,"children":1774},{},[1775],{"type":33,"value":1776},"线程池、连接池被占满",{"type":27,"tag":63,"props":1778,"children":1779},{},[1780],{"type":33,"value":1781},"更多请求开始超时",{"type":27,"tag":63,"props":1783,"children":1784},{},[1785],{"type":33,"value":1786},"整个系统逐步雪崩",{"type":27,"tag":35,"props":1788,"children":1789},{},[1790],{"type":33,"value":1791},"有熔断时：",{"type":27,"tag":59,"props":1793,"children":1794},{},[1795,1800,1805,1810],{"type":27,"tag":63,"props":1796,"children":1797},{},[1798],{"type":33,"value":1799},"检测到错误率或延迟异常",{"type":27,"tag":63,"props":1801,"children":1802},{},[1803],{"type":33,"value":1804},"快速失败，停止继续压下游",{"type":27,"tag":63,"props":1806,"children":1807},{},[1808],{"type":33,"value":1809},"触发降级逻辑",{"type":27,"tag":63,"props":1811,"children":1812},{},[1813],{"type":33,"value":1814},"给下游恢复窗口",{"type":27,"tag":35,"props":1816,"children":1817},{},[1818,1820,1825],{"type":33,"value":1819},"这就是为什么熔断不是“放弃请求”，而是",{"type":27,"tag":51,"props":1821,"children":1822},{},[1823],{"type":33,"value":1824},"保护整体系统存活",{"type":33,"value":57},{"type":27,"tag":228,"props":1827,"children":1829},{"id":1828},"_62-熔断的三个状态",[1830],{"type":33,"value":1831},"6.2 熔断的三个状态",{"type":27,"tag":59,"props":1833,"children":1834},{},[1835,1846,1857],{"type":27,"tag":63,"props":1836,"children":1837},{},[1838,1844],{"type":27,"tag":908,"props":1839,"children":1841},{"className":1840},[],[1842],{"type":33,"value":1843},"Closed",{"type":33,"value":1845},"：正常放量",{"type":27,"tag":63,"props":1847,"children":1848},{},[1849,1855],{"type":27,"tag":908,"props":1850,"children":1852},{"className":1851},[],[1853],{"type":33,"value":1854},"Open",{"type":33,"value":1856},"：直接拒绝，走降级",{"type":27,"tag":63,"props":1858,"children":1859},{},[1860,1866],{"type":27,"tag":908,"props":1861,"children":1863},{"className":1862},[],[1864],{"type":33,"value":1865},"Half-Open",{"type":33,"value":1867},"：小流量试探恢复情况",{"type":27,"tag":228,"props":1869,"children":1871},{"id":1870},"_63-一个简单示例",[1872],{"type":33,"value":1873},"6.3 一个简单示例",{"type":27,"tag":901,"props":1875,"children":1877},{"className":903,"code":1876,"language":905,"meta":7,"style":7},"type BreakerState = 'closed' | 'open' | 'half-open'\n\nclass CircuitBreaker {\n  private failures = 0\n  private openedAt = 0\n  private state: BreakerState = 'closed'\n\n  constructor(\n    private failureThreshold: number,\n    private recoveryTimeoutMs: number,\n  ) {}\n\n  canRequest() {\n    if (this.state === 'open') {\n      if (Date.now() - this.openedAt > this.recoveryTimeoutMs) {\n        this.state = 'half-open'\n        return true\n      }\n      return false\n    }\n    return true\n  }\n\n  recordSuccess() {\n    this.failures = 0\n    this.state = 'closed'\n  }\n\n  recordFailure() {\n    this.failures += 1\n    if (this.failures >= this.failureThreshold) {\n      this.state = 'open'\n      this.openedAt = Date.now()\n    }\n  }\n}\n",[1878],{"type":27,"tag":908,"props":1879,"children":1880},{"__ignoreMap":7},[1881,1923,1930,1946,1967,1987,2016,2023,2034,2058,2082,2090,2097,2110,2143,2191,2211,2223,2231,2242,2249,2260,2267,2274,2286,2306,2325,2332,2339,2351,2371,2405,2426,2454,2462,2470],{"type":27,"tag":912,"props":1882,"children":1883},{"class":914,"line":915},[1884,1889,1894,1898,1904,1909,1914,1918],{"type":27,"tag":912,"props":1885,"children":1886},{"style":919},[1887],{"type":33,"value":1888},"type",{"type":27,"tag":912,"props":1890,"children":1891},{"style":925},[1892],{"type":33,"value":1893}," BreakerState",{"type":27,"tag":912,"props":1895,"children":1896},{"style":919},[1897],{"type":33,"value":1184},{"type":27,"tag":912,"props":1899,"children":1901},{"style":1900},"--shiki-default:#9ECBFF",[1902],{"type":33,"value":1903}," 'closed'",{"type":27,"tag":912,"props":1905,"children":1906},{"style":919},[1907],{"type":33,"value":1908}," |",{"type":27,"tag":912,"props":1910,"children":1911},{"style":1900},[1912],{"type":33,"value":1913}," 'open'",{"type":27,"tag":912,"props":1915,"children":1916},{"style":919},[1917],{"type":33,"value":1908},{"type":27,"tag":912,"props":1919,"children":1920},{"style":1900},[1921],{"type":33,"value":1922}," 'half-open'\n",{"type":27,"tag":912,"props":1924,"children":1925},{"class":914,"line":937},[1926],{"type":27,"tag":912,"props":1927,"children":1928},{"emptyLinePlaceholder":18},[1929],{"type":33,"value":990},{"type":27,"tag":912,"props":1931,"children":1932},{"class":914,"line":963},[1933,1937,1942],{"type":27,"tag":912,"props":1934,"children":1935},{"style":919},[1936],{"type":33,"value":922},{"type":27,"tag":912,"props":1938,"children":1939},{"style":925},[1940],{"type":33,"value":1941}," CircuitBreaker",{"type":27,"tag":912,"props":1943,"children":1944},{"style":931},[1945],{"type":33,"value":934},{"type":27,"tag":912,"props":1947,"children":1948},{"class":914,"line":984},[1949,1953,1958,1962],{"type":27,"tag":912,"props":1950,"children":1951},{"style":919},[1952],{"type":33,"value":943},{"type":27,"tag":912,"props":1954,"children":1955},{"style":946},[1956],{"type":33,"value":1957}," failures",{"type":27,"tag":912,"props":1959,"children":1960},{"style":919},[1961],{"type":33,"value":1184},{"type":27,"tag":912,"props":1963,"children":1964},{"style":957},[1965],{"type":33,"value":1966}," 0\n",{"type":27,"tag":912,"props":1968,"children":1969},{"class":914,"line":993},[1970,1974,1979,1983],{"type":27,"tag":912,"props":1971,"children":1972},{"style":919},[1973],{"type":33,"value":943},{"type":27,"tag":912,"props":1975,"children":1976},{"style":946},[1977],{"type":33,"value":1978}," openedAt",{"type":27,"tag":912,"props":1980,"children":1981},{"style":919},[1982],{"type":33,"value":1184},{"type":27,"tag":912,"props":1984,"children":1985},{"style":957},[1986],{"type":33,"value":1966},{"type":27,"tag":912,"props":1988,"children":1989},{"class":914,"line":20},[1990,1994,1999,2003,2007,2011],{"type":27,"tag":912,"props":1991,"children":1992},{"style":919},[1993],{"type":33,"value":943},{"type":27,"tag":912,"props":1995,"children":1996},{"style":946},[1997],{"type":33,"value":1998}," state",{"type":27,"tag":912,"props":2000,"children":2001},{"style":919},[2002],{"type":33,"value":954},{"type":27,"tag":912,"props":2004,"children":2005},{"style":925},[2006],{"type":33,"value":1893},{"type":27,"tag":912,"props":2008,"children":2009},{"style":919},[2010],{"type":33,"value":1184},{"type":27,"tag":912,"props":2012,"children":2013},{"style":1900},[2014],{"type":33,"value":2015}," 'closed'\n",{"type":27,"tag":912,"props":2017,"children":2018},{"class":914,"line":1034},[2019],{"type":27,"tag":912,"props":2020,"children":2021},{"emptyLinePlaceholder":18},[2022],{"type":33,"value":990},{"type":27,"tag":912,"props":2024,"children":2025},{"class":914,"line":1059},[2026,2030],{"type":27,"tag":912,"props":2027,"children":2028},{"style":919},[2029],{"type":33,"value":999},{"type":27,"tag":912,"props":2031,"children":2032},{"style":931},[2033],{"type":33,"value":1004},{"type":27,"tag":912,"props":2035,"children":2036},{"class":914,"line":1068},[2037,2041,2046,2050,2054],{"type":27,"tag":912,"props":2038,"children":2039},{"style":919},[2040],{"type":33,"value":1012},{"type":27,"tag":912,"props":2042,"children":2043},{"style":946},[2044],{"type":33,"value":2045}," failureThreshold",{"type":27,"tag":912,"props":2047,"children":2048},{"style":919},[2049],{"type":33,"value":954},{"type":27,"tag":912,"props":2051,"children":2052},{"style":957},[2053],{"type":33,"value":1026},{"type":27,"tag":912,"props":2055,"children":2056},{"style":931},[2057],{"type":33,"value":1031},{"type":27,"tag":912,"props":2059,"children":2060},{"class":914,"line":1092},[2061,2065,2070,2074,2078],{"type":27,"tag":912,"props":2062,"children":2063},{"style":919},[2064],{"type":33,"value":1012},{"type":27,"tag":912,"props":2066,"children":2067},{"style":946},[2068],{"type":33,"value":2069}," recoveryTimeoutMs",{"type":27,"tag":912,"props":2071,"children":2072},{"style":919},[2073],{"type":33,"value":954},{"type":27,"tag":912,"props":2075,"children":2076},{"style":957},[2077],{"type":33,"value":1026},{"type":27,"tag":912,"props":2079,"children":2080},{"style":931},[2081],{"type":33,"value":1031},{"type":27,"tag":912,"props":2083,"children":2084},{"class":914,"line":1124},[2085],{"type":27,"tag":912,"props":2086,"children":2087},{"style":931},[2088],{"type":33,"value":2089},"  ) {}\n",{"type":27,"tag":912,"props":2091,"children":2092},{"class":914,"line":1133},[2093],{"type":27,"tag":912,"props":2094,"children":2095},{"emptyLinePlaceholder":18},[2096],{"type":33,"value":990},{"type":27,"tag":912,"props":2098,"children":2099},{"class":914,"line":1141},[2100,2105],{"type":27,"tag":912,"props":2101,"children":2102},{"style":925},[2103],{"type":33,"value":2104},"  canRequest",{"type":27,"tag":912,"props":2106,"children":2107},{"style":931},[2108],{"type":33,"value":2109},"() {\n",{"type":27,"tag":912,"props":2111,"children":2112},{"class":914,"line":1168},[2113,2117,2121,2125,2130,2135,2139],{"type":27,"tag":912,"props":2114,"children":2115},{"style":919},[2116],{"type":33,"value":1305},{"type":27,"tag":912,"props":2118,"children":2119},{"style":931},[2120],{"type":33,"value":1435},{"type":27,"tag":912,"props":2122,"children":2123},{"style":957},[2124],{"type":33,"value":1361},{"type":27,"tag":912,"props":2126,"children":2127},{"style":931},[2128],{"type":33,"value":2129},".state ",{"type":27,"tag":912,"props":2131,"children":2132},{"style":919},[2133],{"type":33,"value":2134},"===",{"type":27,"tag":912,"props":2136,"children":2137},{"style":1900},[2138],{"type":33,"value":1913},{"type":27,"tag":912,"props":2140,"children":2141},{"style":931},[2142],{"type":33,"value":1325},{"type":27,"tag":912,"props":2144,"children":2145},{"class":914,"line":1199},[2146,2151,2156,2160,2165,2169,2173,2178,2182,2186],{"type":27,"tag":912,"props":2147,"children":2148},{"style":919},[2149],{"type":33,"value":2150},"      if",{"type":27,"tag":912,"props":2152,"children":2153},{"style":931},[2154],{"type":33,"value":2155}," (Date.",{"type":27,"tag":912,"props":2157,"children":2158},{"style":925},[2159],{"type":33,"value":1116},{"type":27,"tag":912,"props":2161,"children":2162},{"style":931},[2163],{"type":33,"value":2164},"() ",{"type":27,"tag":912,"props":2166,"children":2167},{"style":919},[2168],{"type":33,"value":1223},{"type":27,"tag":912,"props":2170,"children":2171},{"style":957},[2172],{"type":33,"value":1228},{"type":27,"tag":912,"props":2174,"children":2175},{"style":931},[2176],{"type":33,"value":2177},".openedAt ",{"type":27,"tag":912,"props":2179,"children":2180},{"style":919},[2181],{"type":33,"value":1315},{"type":27,"tag":912,"props":2183,"children":2184},{"style":957},[2185],{"type":33,"value":1228},{"type":27,"tag":912,"props":2187,"children":2188},{"style":931},[2189],{"type":33,"value":2190},".recoveryTimeoutMs) {\n",{"type":27,"tag":912,"props":2192,"children":2193},{"class":914,"line":1246},[2194,2199,2203,2207],{"type":27,"tag":912,"props":2195,"children":2196},{"style":957},[2197],{"type":33,"value":2198},"        this",{"type":27,"tag":912,"props":2200,"children":2201},{"style":931},[2202],{"type":33,"value":2129},{"type":27,"tag":912,"props":2204,"children":2205},{"style":919},[2206],{"type":33,"value":1084},{"type":27,"tag":912,"props":2208,"children":2209},{"style":1900},[2210],{"type":33,"value":1922},{"type":27,"tag":912,"props":2212,"children":2213},{"class":914,"line":1292},[2214,2219],{"type":27,"tag":912,"props":2215,"children":2216},{"style":919},[2217],{"type":33,"value":2218},"        return",{"type":27,"tag":912,"props":2220,"children":2221},{"style":957},[2222],{"type":33,"value":1522},{"type":27,"tag":912,"props":2224,"children":2225},{"class":914,"line":21},[2226],{"type":27,"tag":912,"props":2227,"children":2228},{"style":931},[2229],{"type":33,"value":2230},"      }\n",{"type":27,"tag":912,"props":2232,"children":2233},{"class":914,"line":1328},[2234,2238],{"type":27,"tag":912,"props":2235,"children":2236},{"style":919},[2237],{"type":33,"value":1465},{"type":27,"tag":912,"props":2239,"children":2240},{"style":957},[2241],{"type":33,"value":1470},{"type":27,"tag":912,"props":2243,"children":2244},{"class":914,"line":1387},[2245],{"type":27,"tag":912,"props":2246,"children":2247},{"style":931},[2248],{"type":33,"value":1414},{"type":27,"tag":912,"props":2250,"children":2251},{"class":914,"line":1408},[2252,2256],{"type":27,"tag":912,"props":2253,"children":2254},{"style":919},[2255],{"type":33,"value":1517},{"type":27,"tag":912,"props":2257,"children":2258},{"style":957},[2259],{"type":33,"value":1522},{"type":27,"tag":912,"props":2261,"children":2262},{"class":914,"line":1417},[2263],{"type":27,"tag":912,"props":2264,"children":2265},{"style":931},[2266],{"type":33,"value":1130},{"type":27,"tag":912,"props":2268,"children":2269},{"class":914,"line":1425},[2270],{"type":27,"tag":912,"props":2271,"children":2272},{"emptyLinePlaceholder":18},[2273],{"type":33,"value":990},{"type":27,"tag":912,"props":2275,"children":2276},{"class":914,"line":1459},[2277,2282],{"type":27,"tag":912,"props":2278,"children":2279},{"style":925},[2280],{"type":33,"value":2281},"  recordSuccess",{"type":27,"tag":912,"props":2283,"children":2284},{"style":931},[2285],{"type":33,"value":2109},{"type":27,"tag":912,"props":2287,"children":2288},{"class":914,"line":1473},[2289,2293,2298,2302],{"type":27,"tag":912,"props":2290,"children":2291},{"style":957},[2292],{"type":33,"value":1074},{"type":27,"tag":912,"props":2294,"children":2295},{"style":931},[2296],{"type":33,"value":2297},".failures ",{"type":27,"tag":912,"props":2299,"children":2300},{"style":919},[2301],{"type":33,"value":1084},{"type":27,"tag":912,"props":2303,"children":2304},{"style":957},[2305],{"type":33,"value":1966},{"type":27,"tag":912,"props":2307,"children":2308},{"class":914,"line":1481},[2309,2313,2317,2321],{"type":27,"tag":912,"props":2310,"children":2311},{"style":957},[2312],{"type":33,"value":1074},{"type":27,"tag":912,"props":2314,"children":2315},{"style":931},[2316],{"type":33,"value":2129},{"type":27,"tag":912,"props":2318,"children":2319},{"style":919},[2320],{"type":33,"value":1084},{"type":27,"tag":912,"props":2322,"children":2323},{"style":1900},[2324],{"type":33,"value":2015},{"type":27,"tag":912,"props":2326,"children":2327},{"class":914,"line":1489},[2328],{"type":27,"tag":912,"props":2329,"children":2330},{"style":931},[2331],{"type":33,"value":1130},{"type":27,"tag":912,"props":2333,"children":2334},{"class":914,"line":1511},[2335],{"type":27,"tag":912,"props":2336,"children":2337},{"emptyLinePlaceholder":18},[2338],{"type":33,"value":990},{"type":27,"tag":912,"props":2340,"children":2341},{"class":914,"line":1525},[2342,2347],{"type":27,"tag":912,"props":2343,"children":2344},{"style":925},[2345],{"type":33,"value":2346},"  recordFailure",{"type":27,"tag":912,"props":2348,"children":2349},{"style":931},[2350],{"type":33,"value":2109},{"type":27,"tag":912,"props":2352,"children":2353},{"class":914,"line":1533},[2354,2358,2362,2367],{"type":27,"tag":912,"props":2355,"children":2356},{"style":957},[2357],{"type":33,"value":1074},{"type":27,"tag":912,"props":2359,"children":2360},{"style":931},[2361],{"type":33,"value":2297},{"type":27,"tag":912,"props":2363,"children":2364},{"style":919},[2365],{"type":33,"value":2366},"+=",{"type":27,"tag":912,"props":2368,"children":2369},{"style":957},[2370],{"type":33,"value":1508},{"type":27,"tag":912,"props":2372,"children":2374},{"class":914,"line":2373},31,[2375,2379,2383,2387,2391,2396,2400],{"type":27,"tag":912,"props":2376,"children":2377},{"style":919},[2378],{"type":33,"value":1305},{"type":27,"tag":912,"props":2380,"children":2381},{"style":931},[2382],{"type":33,"value":1435},{"type":27,"tag":912,"props":2384,"children":2385},{"style":957},[2386],{"type":33,"value":1361},{"type":27,"tag":912,"props":2388,"children":2389},{"style":931},[2390],{"type":33,"value":2297},{"type":27,"tag":912,"props":2392,"children":2393},{"style":919},[2394],{"type":33,"value":2395},">=",{"type":27,"tag":912,"props":2397,"children":2398},{"style":957},[2399],{"type":33,"value":1228},{"type":27,"tag":912,"props":2401,"children":2402},{"style":931},[2403],{"type":33,"value":2404},".failureThreshold) {\n",{"type":27,"tag":912,"props":2406,"children":2408},{"class":914,"line":2407},32,[2409,2413,2417,2421],{"type":27,"tag":912,"props":2410,"children":2411},{"style":957},[2412],{"type":33,"value":1334},{"type":27,"tag":912,"props":2414,"children":2415},{"style":931},[2416],{"type":33,"value":2129},{"type":27,"tag":912,"props":2418,"children":2419},{"style":919},[2420],{"type":33,"value":1084},{"type":27,"tag":912,"props":2422,"children":2423},{"style":1900},[2424],{"type":33,"value":2425}," 'open'\n",{"type":27,"tag":912,"props":2427,"children":2429},{"class":914,"line":2428},33,[2430,2434,2438,2442,2446,2450],{"type":27,"tag":912,"props":2431,"children":2432},{"style":957},[2433],{"type":33,"value":1334},{"type":27,"tag":912,"props":2435,"children":2436},{"style":931},[2437],{"type":33,"value":2177},{"type":27,"tag":912,"props":2439,"children":2440},{"style":919},[2441],{"type":33,"value":1084},{"type":27,"tag":912,"props":2443,"children":2444},{"style":931},[2445],{"type":33,"value":1111},{"type":27,"tag":912,"props":2447,"children":2448},{"style":925},[2449],{"type":33,"value":1116},{"type":27,"tag":912,"props":2451,"children":2452},{"style":931},[2453],{"type":33,"value":1121},{"type":27,"tag":912,"props":2455,"children":2457},{"class":914,"line":2456},34,[2458],{"type":27,"tag":912,"props":2459,"children":2460},{"style":931},[2461],{"type":33,"value":1414},{"type":27,"tag":912,"props":2463,"children":2465},{"class":914,"line":2464},35,[2466],{"type":27,"tag":912,"props":2467,"children":2468},{"style":931},[2469],{"type":33,"value":1130},{"type":27,"tag":912,"props":2471,"children":2473},{"class":914,"line":2472},36,[2474],{"type":27,"tag":912,"props":2475,"children":2476},{"style":931},[2477],{"type":33,"value":1539},{"type":27,"tag":35,"props":2479,"children":2480},{},[2481],{"type":33,"value":2482},"真实生产里会基于时间窗口、错误率、慢调用比等更细指标来做，但逻辑核心一致。",{"type":27,"tag":179,"props":2484,"children":2485},{},[],{"type":27,"tag":183,"props":2487,"children":2489},{"id":2488},"七降级不是认输而是给核心路径让路",[2490],{"type":33,"value":2491},"七、降级不是认输，而是给核心路径让路",{"type":27,"tag":35,"props":2493,"children":2494},{},[2495],{"type":33,"value":2496},"降级最容易被误解成“功能阉割”。",{"type":27,"tag":35,"props":2498,"children":2499},{},[2500],{"type":33,"value":2501},"更准确的理解是：",{"type":27,"tag":512,"props":2503,"children":2504},{},[2505],{"type":27,"tag":35,"props":2506,"children":2507},{},[2508],{"type":27,"tag":51,"props":2509,"children":2510},{},[2511],{"type":33,"value":2512},"在资源紧张或依赖异常时，优先保住最核心链路。",{"type":27,"tag":228,"props":2514,"children":2516},{"id":2515},"_71-常见降级策略",[2517],{"type":33,"value":2518},"7.1 常见降级策略",{"type":27,"tag":235,"props":2520,"children":2521},{},[2522,2541],{"type":27,"tag":239,"props":2523,"children":2524},{},[2525],{"type":27,"tag":243,"props":2526,"children":2527},{},[2528,2533,2537],{"type":27,"tag":247,"props":2529,"children":2530},{},[2531],{"type":33,"value":2532},"策略",{"type":27,"tag":247,"props":2534,"children":2535},{},[2536],{"type":33,"value":607},{"type":27,"tag":247,"props":2538,"children":2539},{},[2540],{"type":33,"value":612},{"type":27,"tag":263,"props":2542,"children":2543},{},[2544,2562,2580,2598],{"type":27,"tag":243,"props":2545,"children":2546},{},[2547,2552,2557],{"type":27,"tag":270,"props":2548,"children":2549},{},[2550],{"type":33,"value":2551},"返回兜底数据",{"type":27,"tag":270,"props":2553,"children":2554},{},[2555],{"type":33,"value":2556},"推荐、榜单、装饰性模块",{"type":27,"tag":270,"props":2558,"children":2559},{},[2560],{"type":33,"value":2561},"推荐位返回默认内容",{"type":27,"tag":243,"props":2563,"children":2564},{},[2565,2570,2575],{"type":27,"tag":270,"props":2566,"children":2567},{},[2568],{"type":33,"value":2569},"关闭非核心能力",{"type":27,"tag":270,"props":2571,"children":2572},{},[2573],{"type":33,"value":2574},"评论、收藏、营销提示",{"type":27,"tag":270,"props":2576,"children":2577},{},[2578],{"type":33,"value":2579},"秒杀时临时关闭评论摘要",{"type":27,"tag":243,"props":2581,"children":2582},{},[2583,2588,2593],{"type":27,"tag":270,"props":2584,"children":2585},{},[2586],{"type":33,"value":2587},"只读模式",{"type":27,"tag":270,"props":2589,"children":2590},{},[2591],{"type":33,"value":2592},"写链路异常时",{"type":27,"tag":270,"props":2594,"children":2595},{},[2596],{"type":33,"value":2597},"订单查询可用，下单暂缓",{"type":27,"tag":243,"props":2599,"children":2600},{},[2601,2606,2611],{"type":27,"tag":270,"props":2602,"children":2603},{},[2604],{"type":33,"value":2605},"预计算结果",{"type":27,"tag":270,"props":2607,"children":2608},{},[2609],{"type":33,"value":2610},"配置、榜单、静态聚合",{"type":27,"tag":270,"props":2612,"children":2613},{},[2614],{"type":33,"value":2615},"活动页直接返回缓存快照",{"type":27,"tag":228,"props":2617,"children":2619},{"id":2618},"_72-降级必须提前设计不是故障时临场发挥",[2620],{"type":33,"value":2621},"7.2 降级必须提前设计，不是故障时临场发挥",{"type":27,"tag":35,"props":2623,"children":2624},{},[2625],{"type":33,"value":2626},"如果系统只有“全功能运行”和“完全报错”两种状态，那它在高峰时会很脆。",{"type":27,"tag":35,"props":2628,"children":2629},{},[2630],{"type":33,"value":2631},"成熟团队会提前定义：",{"type":27,"tag":59,"props":2633,"children":2634},{},[2635,2640,2645,2650],{"type":27,"tag":63,"props":2636,"children":2637},{},[2638],{"type":33,"value":2639},"哪些接口是 P0，必须保",{"type":27,"tag":63,"props":2641,"children":2642},{},[2643],{"type":33,"value":2644},"哪些功能可弱化",{"type":27,"tag":63,"props":2646,"children":2647},{},[2648],{"type":33,"value":2649},"哪些返回可以用旧数据兜底",{"type":27,"tag":63,"props":2651,"children":2652},{},[2653],{"type":33,"value":2654},"哪些依赖超时后直接放弃",{"type":27,"tag":228,"props":2656,"children":2658},{"id":2657},"_73-一个降级例子",[2659],{"type":33,"value":2660},"7.3 一个降级例子",{"type":27,"tag":901,"props":2662,"children":2664},{"className":903,"code":2663,"language":905,"meta":7,"style":7},"export async function getHomepageData(userId: string) {\n  const [banner, flashSale, recommendations] = await Promise.all([\n    bannerService.getBanner(),\n    flashSaleService.getFlashSale().catch(() => null),\n    recommendationService.getRecommendations(userId).catch(() => []),\n  ])\n\n  return {\n    banner,\n    flashSale,\n    recommendations,\n    degraded: !flashSale || recommendations.length === 0,\n  }\n}\n",[2665],{"type":27,"tag":908,"props":2666,"children":2667},{"__ignoreMap":7},[2668,2713,2784,2802,2845,2880,2888,2895,2907,2915,2923,2931,2977,2984],{"type":27,"tag":912,"props":2669,"children":2670},{"class":914,"line":915},[2671,2676,2681,2686,2691,2695,2700,2704,2709],{"type":27,"tag":912,"props":2672,"children":2673},{"style":919},[2674],{"type":33,"value":2675},"export",{"type":27,"tag":912,"props":2677,"children":2678},{"style":919},[2679],{"type":33,"value":2680}," async",{"type":27,"tag":912,"props":2682,"children":2683},{"style":919},[2684],{"type":33,"value":2685}," function",{"type":27,"tag":912,"props":2687,"children":2688},{"style":925},[2689],{"type":33,"value":2690}," getHomepageData",{"type":27,"tag":912,"props":2692,"children":2693},{"style":931},[2694],{"type":33,"value":1356},{"type":27,"tag":912,"props":2696,"children":2697},{"style":946},[2698],{"type":33,"value":2699},"userId",{"type":27,"tag":912,"props":2701,"children":2702},{"style":919},[2703],{"type":33,"value":954},{"type":27,"tag":912,"props":2705,"children":2706},{"style":957},[2707],{"type":33,"value":2708}," string",{"type":27,"tag":912,"props":2710,"children":2711},{"style":931},[2712],{"type":33,"value":1325},{"type":27,"tag":912,"props":2714,"children":2715},{"class":914,"line":937},[2716,2721,2726,2731,2736,2741,2745,2750,2755,2759,2764,2769,2774,2779],{"type":27,"tag":912,"props":2717,"children":2718},{"style":919},[2719],{"type":33,"value":2720},"  const",{"type":27,"tag":912,"props":2722,"children":2723},{"style":931},[2724],{"type":33,"value":2725}," [",{"type":27,"tag":912,"props":2727,"children":2728},{"style":957},[2729],{"type":33,"value":2730},"banner",{"type":27,"tag":912,"props":2732,"children":2733},{"style":931},[2734],{"type":33,"value":2735},", ",{"type":27,"tag":912,"props":2737,"children":2738},{"style":957},[2739],{"type":33,"value":2740},"flashSale",{"type":27,"tag":912,"props":2742,"children":2743},{"style":931},[2744],{"type":33,"value":2735},{"type":27,"tag":912,"props":2746,"children":2747},{"style":957},[2748],{"type":33,"value":2749},"recommendations",{"type":27,"tag":912,"props":2751,"children":2752},{"style":931},[2753],{"type":33,"value":2754},"] ",{"type":27,"tag":912,"props":2756,"children":2757},{"style":919},[2758],{"type":33,"value":1084},{"type":27,"tag":912,"props":2760,"children":2761},{"style":919},[2762],{"type":33,"value":2763}," await",{"type":27,"tag":912,"props":2765,"children":2766},{"style":957},[2767],{"type":33,"value":2768}," Promise",{"type":27,"tag":912,"props":2770,"children":2771},{"style":931},[2772],{"type":33,"value":2773},".",{"type":27,"tag":912,"props":2775,"children":2776},{"style":925},[2777],{"type":33,"value":2778},"all",{"type":27,"tag":912,"props":2780,"children":2781},{"style":931},[2782],{"type":33,"value":2783},"([\n",{"type":27,"tag":912,"props":2785,"children":2786},{"class":914,"line":963},[2787,2792,2797],{"type":27,"tag":912,"props":2788,"children":2789},{"style":931},[2790],{"type":33,"value":2791},"    bannerService.",{"type":27,"tag":912,"props":2793,"children":2794},{"style":925},[2795],{"type":33,"value":2796},"getBanner",{"type":27,"tag":912,"props":2798,"children":2799},{"style":931},[2800],{"type":33,"value":2801},"(),\n",{"type":27,"tag":912,"props":2803,"children":2804},{"class":914,"line":984},[2805,2810,2815,2820,2825,2830,2835,2840],{"type":27,"tag":912,"props":2806,"children":2807},{"style":931},[2808],{"type":33,"value":2809},"    flashSaleService.",{"type":27,"tag":912,"props":2811,"children":2812},{"style":925},[2813],{"type":33,"value":2814},"getFlashSale",{"type":27,"tag":912,"props":2816,"children":2817},{"style":931},[2818],{"type":33,"value":2819},"().",{"type":27,"tag":912,"props":2821,"children":2822},{"style":925},[2823],{"type":33,"value":2824},"catch",{"type":27,"tag":912,"props":2826,"children":2827},{"style":931},[2828],{"type":33,"value":2829},"(() ",{"type":27,"tag":912,"props":2831,"children":2832},{"style":919},[2833],{"type":33,"value":2834},"=>",{"type":27,"tag":912,"props":2836,"children":2837},{"style":957},[2838],{"type":33,"value":2839}," null",{"type":27,"tag":912,"props":2841,"children":2842},{"style":931},[2843],{"type":33,"value":2844},"),\n",{"type":27,"tag":912,"props":2846,"children":2847},{"class":914,"line":993},[2848,2853,2858,2863,2867,2871,2875],{"type":27,"tag":912,"props":2849,"children":2850},{"style":931},[2851],{"type":33,"value":2852},"    recommendationService.",{"type":27,"tag":912,"props":2854,"children":2855},{"style":925},[2856],{"type":33,"value":2857},"getRecommendations",{"type":27,"tag":912,"props":2859,"children":2860},{"style":931},[2861],{"type":33,"value":2862},"(userId).",{"type":27,"tag":912,"props":2864,"children":2865},{"style":925},[2866],{"type":33,"value":2824},{"type":27,"tag":912,"props":2868,"children":2869},{"style":931},[2870],{"type":33,"value":2829},{"type":27,"tag":912,"props":2872,"children":2873},{"style":919},[2874],{"type":33,"value":2834},{"type":27,"tag":912,"props":2876,"children":2877},{"style":931},[2878],{"type":33,"value":2879}," []),\n",{"type":27,"tag":912,"props":2881,"children":2882},{"class":914,"line":20},[2883],{"type":27,"tag":912,"props":2884,"children":2885},{"style":931},[2886],{"type":33,"value":2887},"  ])\n",{"type":27,"tag":912,"props":2889,"children":2890},{"class":914,"line":1034},[2891],{"type":27,"tag":912,"props":2892,"children":2893},{"emptyLinePlaceholder":18},[2894],{"type":33,"value":990},{"type":27,"tag":912,"props":2896,"children":2897},{"class":914,"line":1059},[2898,2903],{"type":27,"tag":912,"props":2899,"children":2900},{"style":919},[2901],{"type":33,"value":2902},"  return",{"type":27,"tag":912,"props":2904,"children":2905},{"style":931},[2906],{"type":33,"value":934},{"type":27,"tag":912,"props":2908,"children":2909},{"class":914,"line":1068},[2910],{"type":27,"tag":912,"props":2911,"children":2912},{"style":931},[2913],{"type":33,"value":2914},"    banner,\n",{"type":27,"tag":912,"props":2916,"children":2917},{"class":914,"line":1092},[2918],{"type":27,"tag":912,"props":2919,"children":2920},{"style":931},[2921],{"type":33,"value":2922},"    flashSale,\n",{"type":27,"tag":912,"props":2924,"children":2925},{"class":914,"line":1124},[2926],{"type":27,"tag":912,"props":2927,"children":2928},{"style":931},[2929],{"type":33,"value":2930},"    recommendations,\n",{"type":27,"tag":912,"props":2932,"children":2933},{"class":914,"line":1133},[2934,2939,2944,2949,2954,2959,2964,2969,2973],{"type":27,"tag":912,"props":2935,"children":2936},{"style":931},[2937],{"type":33,"value":2938},"    degraded: ",{"type":27,"tag":912,"props":2940,"children":2941},{"style":919},[2942],{"type":33,"value":2943},"!",{"type":27,"tag":912,"props":2945,"children":2946},{"style":931},[2947],{"type":33,"value":2948},"flashSale ",{"type":27,"tag":912,"props":2950,"children":2951},{"style":919},[2952],{"type":33,"value":2953},"||",{"type":27,"tag":912,"props":2955,"children":2956},{"style":931},[2957],{"type":33,"value":2958}," recommendations.",{"type":27,"tag":912,"props":2960,"children":2961},{"style":957},[2962],{"type":33,"value":2963},"length",{"type":27,"tag":912,"props":2965,"children":2966},{"style":919},[2967],{"type":33,"value":2968}," ===",{"type":27,"tag":912,"props":2970,"children":2971},{"style":957},[2972],{"type":33,"value":1320},{"type":27,"tag":912,"props":2974,"children":2975},{"style":931},[2976],{"type":33,"value":1031},{"type":27,"tag":912,"props":2978,"children":2979},{"class":914,"line":1141},[2980],{"type":27,"tag":912,"props":2981,"children":2982},{"style":931},[2983],{"type":33,"value":1130},{"type":27,"tag":912,"props":2985,"children":2986},{"class":914,"line":1168},[2987],{"type":27,"tag":912,"props":2988,"children":2989},{"style":931},[2990],{"type":33,"value":1539},{"type":27,"tag":35,"props":2992,"children":2993},{},[2994],{"type":33,"value":2995},"这里不是“所有失败都吞掉”，而是清楚地区分：",{"type":27,"tag":59,"props":2997,"children":2998},{},[2999,3004],{"type":27,"tag":63,"props":3000,"children":3001},{},[3002],{"type":33,"value":3003},"哪个能力失效还能接受",{"type":27,"tag":63,"props":3005,"children":3006},{},[3007],{"type":33,"value":3008},"哪个能力不能影响主页面可用",{"type":27,"tag":179,"props":3010,"children":3011},{},[],{"type":27,"tag":183,"props":3013,"children":3015},{"id":3014},"八网关层还能做什么灰度隔离观测",[3016],{"type":33,"value":3017},"八、网关层还能做什么：灰度、隔离、观测",{"type":27,"tag":228,"props":3019,"children":3021},{"id":3020},"_81-灰度发布",[3022],{"type":33,"value":3023},"8.1 灰度发布",{"type":27,"tag":35,"props":3025,"children":3026},{},[3027],{"type":33,"value":3028},"网关是最适合做流量分流的地方。可以按：",{"type":27,"tag":59,"props":3030,"children":3031},{},[3032,3037,3042,3047,3052,3057],{"type":27,"tag":63,"props":3033,"children":3034},{},[3035],{"type":33,"value":3036},"用户 ID",{"type":27,"tag":63,"props":3038,"children":3039},{},[3040],{"type":33,"value":3041},"租户",{"type":27,"tag":63,"props":3043,"children":3044},{},[3045],{"type":33,"value":3046},"地区",{"type":27,"tag":63,"props":3048,"children":3049},{},[3050],{"type":33,"value":3051},"header",{"type":27,"tag":63,"props":3053,"children":3054},{},[3055],{"type":33,"value":3056},"cookie",{"type":27,"tag":63,"props":3058,"children":3059},{},[3060],{"type":33,"value":3061},"实验桶",{"type":27,"tag":35,"props":3063,"children":3064},{},[3065],{"type":33,"value":3066},"把小部分流量导入新版本。",{"type":27,"tag":228,"props":3068,"children":3070},{"id":3069},"_82-租户隔离和优先级保护",[3071],{"type":33,"value":3072},"8.2 租户隔离和优先级保护",{"type":27,"tag":35,"props":3074,"children":3075},{},[3076],{"type":33,"value":3077},"多租户系统常见问题是，大客户或异常租户把公共资源吃满。",{"type":27,"tag":35,"props":3079,"children":3080},{},[3081],{"type":33,"value":3082},"网关层适合做：",{"type":27,"tag":59,"props":3084,"children":3085},{},[3086,3091,3096],{"type":27,"tag":63,"props":3087,"children":3088},{},[3089],{"type":33,"value":3090},"租户配额",{"type":27,"tag":63,"props":3092,"children":3093},{},[3094],{"type":33,"value":3095},"优先级通道",{"type":27,"tag":63,"props":3097,"children":3098},{},[3099],{"type":33,"value":3100},"不同 SLA 的差异化限流",{"type":27,"tag":228,"props":3102,"children":3104},{"id":3103},"_83-统一观测",[3105],{"type":33,"value":3106},"8.3 统一观测",{"type":27,"tag":35,"props":3108,"children":3109},{},[3110],{"type":33,"value":3111},"网关能天然拿到：",{"type":27,"tag":59,"props":3113,"children":3114},{},[3115,3120,3125,3130,3135,3140],{"type":27,"tag":63,"props":3116,"children":3117},{},[3118],{"type":33,"value":3119},"接口入口 QPS",{"type":27,"tag":63,"props":3121,"children":3122},{},[3123],{"type":33,"value":3124},"状态码分布",{"type":27,"tag":63,"props":3126,"children":3127},{},[3128],{"type":33,"value":3129},"限流命中次数",{"type":27,"tag":63,"props":3131,"children":3132},{},[3133],{"type":33,"value":3134},"熔断次数",{"type":27,"tag":63,"props":3136,"children":3137},{},[3138],{"type":33,"value":3139},"下游路由分布",{"type":27,"tag":63,"props":3141,"children":3142},{},[3143],{"type":33,"value":3144},"延迟分位数",{"type":27,"tag":35,"props":3146,"children":3147},{},[3148],{"type":33,"value":3149},"如果没有这层观测，你通常会在故障后才意识到：",{"type":27,"tag":59,"props":3151,"children":3152},{},[3153,3158,3163],{"type":27,"tag":63,"props":3154,"children":3155},{},[3156],{"type":33,"value":3157},"到底是入口打爆了",{"type":27,"tag":63,"props":3159,"children":3160},{},[3161],{"type":33,"value":3162},"还是某个下游先慢了",{"type":27,"tag":63,"props":3164,"children":3165},{},[3166],{"type":33,"value":3167},"还是某个租户在恶意刷接口",{"type":27,"tag":179,"props":3169,"children":3170},{},[],{"type":27,"tag":183,"props":3172,"children":3174},{"id":3173},"九网关本身也会变成风险点怎么避免",[3175],{"type":33,"value":3176},"九、网关本身也会变成风险点，怎么避免",{"type":27,"tag":35,"props":3178,"children":3179},{},[3180],{"type":33,"value":3181},"这点必须讲透。",{"type":27,"tag":35,"props":3183,"children":3184},{},[3185],{"type":33,"value":3186},"API 网关治理得好，是保护层；治理得差，它自己就是最大的单点风险。",{"type":27,"tag":228,"props":3188,"children":3190},{"id":3189},"_91-常见问题",[3191],{"type":33,"value":3192},"9.1 常见问题",{"type":27,"tag":59,"props":3194,"children":3195},{},[3196,3201,3206,3211,3216],{"type":27,"tag":63,"props":3197,"children":3198},{},[3199],{"type":33,"value":3200},"网关逻辑过重",{"type":27,"tag":63,"props":3202,"children":3203},{},[3204],{"type":33,"value":3205},"所有新需求都往网关里塞",{"type":27,"tag":63,"props":3207,"children":3208},{},[3209],{"type":33,"value":3210},"配置变更缺少审计",{"type":27,"tag":63,"props":3212,"children":3213},{},[3214],{"type":33,"value":3215},"单实例或单集群承压过高",{"type":27,"tag":63,"props":3217,"children":3218},{},[3219],{"type":33,"value":3220},"限流和熔断策略全是手工临时修改",{"type":27,"tag":228,"props":3222,"children":3224},{"id":3223},"_92-防止网关变成超级单点的做法",[3225],{"type":33,"value":3226},"9.2 防止网关变成“超级单点”的做法",{"type":27,"tag":117,"props":3228,"children":3229},{},[3230,3235,3240,3245,3250],{"type":27,"tag":63,"props":3231,"children":3232},{},[3233],{"type":33,"value":3234},"网关只做入口治理，不做重业务",{"type":27,"tag":63,"props":3236,"children":3237},{},[3238],{"type":33,"value":3239},"网关配置要版本化和审计化",{"type":27,"tag":63,"props":3241,"children":3242},{},[3243],{"type":33,"value":3244},"网关自身也要水平扩展",{"type":27,"tag":63,"props":3246,"children":3247},{},[3248],{"type":33,"value":3249},"网关规则改动要支持灰度",{"type":27,"tag":63,"props":3251,"children":3252},{},[3253],{"type":33,"value":3254},"网关要有独立的限流 / 熔断 / tracing 观测",{"type":27,"tag":228,"props":3256,"children":3258},{"id":3257},"_93-一张职责边界表",[3259],{"type":33,"value":3260},"9.3 一张职责边界表",{"type":27,"tag":235,"props":3262,"children":3263},{},[3264,3285],{"type":27,"tag":239,"props":3265,"children":3266},{},[3267],{"type":27,"tag":243,"props":3268,"children":3269},{},[3270,3275,3280],{"type":27,"tag":247,"props":3271,"children":3272},{},[3273],{"type":33,"value":3274},"能力",{"type":27,"tag":247,"props":3276,"children":3277},{},[3278],{"type":33,"value":3279},"放网关",{"type":27,"tag":247,"props":3281,"children":3282},{},[3283],{"type":33,"value":3284},"放业务服务",{"type":27,"tag":263,"props":3286,"children":3287},{},[3288,3306,3322,3339,3355,3373],{"type":27,"tag":243,"props":3289,"children":3290},{},[3291,3296,3301],{"type":27,"tag":270,"props":3292,"children":3293},{},[3294],{"type":33,"value":3295},"认证鉴权",{"type":27,"tag":270,"props":3297,"children":3298},{},[3299],{"type":33,"value":3300},"✅",{"type":27,"tag":270,"props":3302,"children":3303},{},[3304],{"type":33,"value":3305},"可补充细粒度权限",{"type":27,"tag":243,"props":3307,"children":3308},{},[3309,3313,3317],{"type":27,"tag":270,"props":3310,"children":3311},{},[3312],{"type":33,"value":95},{"type":27,"tag":270,"props":3314,"children":3315},{},[3316],{"type":33,"value":3300},{"type":27,"tag":270,"props":3318,"children":3319},{},[3320],{"type":33,"value":3321},"❌",{"type":27,"tag":243,"props":3323,"children":3324},{},[3325,3330,3334],{"type":27,"tag":270,"props":3326,"children":3327},{},[3328],{"type":33,"value":3329},"IP / 用户基础限流",{"type":27,"tag":270,"props":3331,"children":3332},{},[3333],{"type":33,"value":3300},{"type":27,"tag":270,"props":3335,"children":3336},{},[3337],{"type":33,"value":3338},"可补充",{"type":27,"tag":243,"props":3340,"children":3341},{},[3342,3347,3351],{"type":27,"tag":270,"props":3343,"children":3344},{},[3345],{"type":33,"value":3346},"复杂业务规则",{"type":27,"tag":270,"props":3348,"children":3349},{},[3350],{"type":33,"value":3321},{"type":27,"tag":270,"props":3352,"children":3353},{},[3354],{"type":33,"value":3300},{"type":27,"tag":243,"props":3356,"children":3357},{},[3358,3363,3368],{"type":27,"tag":270,"props":3359,"children":3360},{},[3361],{"type":33,"value":3362},"聚合多个领域数据",{"type":27,"tag":270,"props":3364,"children":3365},{},[3366],{"type":33,"value":3367},"谨慎，少量",{"type":27,"tag":270,"props":3369,"children":3370},{},[3371],{"type":33,"value":3372},"✅ BFF / 服务层",{"type":27,"tag":243,"props":3374,"children":3375},{},[3376,3381,3385],{"type":27,"tag":270,"props":3377,"children":3378},{},[3379],{"type":33,"value":3380},"数据库存取",{"type":27,"tag":270,"props":3382,"children":3383},{},[3384],{"type":33,"value":3321},{"type":27,"tag":270,"props":3386,"children":3387},{},[3388],{"type":33,"value":3300},{"type":27,"tag":179,"props":3390,"children":3391},{},[],{"type":27,"tag":183,"props":3393,"children":3395},{"id":3394},"十一个完整的高峰保护方案长什么样",[3396],{"type":33,"value":3397},"十、一个完整的高峰保护方案长什么样",{"type":27,"tag":35,"props":3399,"children":3400},{},[3401],{"type":33,"value":3402},"以大促会场为例，可以这样设计：",{"type":27,"tag":228,"props":3404,"children":3406},{"id":3405},"第-1-层cdn-边缘缓存",[3407],{"type":33,"value":3408},"第 1 层：CDN + 边缘缓存",{"type":27,"tag":35,"props":3410,"children":3411},{},[3412],{"type":33,"value":3413},"静态资源、弱动态配置先在最外层吸收重复访问。",{"type":27,"tag":228,"props":3415,"children":3417},{"id":3416},"第-2-层网关总入口限流",[3418],{"type":33,"value":3419},"第 2 层：网关总入口限流",{"type":27,"tag":35,"props":3421,"children":3422},{},[3423],{"type":33,"value":3424},"按 IP、用户、租户、接口级别做第一轮流量裁剪。",{"type":27,"tag":228,"props":3426,"children":3428},{"id":3427},"第-3-层应用层热点接口限流",[3429],{"type":33,"value":3430},"第 3 层：应用层热点接口限流",{"type":27,"tag":35,"props":3432,"children":3433},{},[3434],{"type":33,"value":3435},"例如下单、优惠计算、抢购资格校验。",{"type":27,"tag":228,"props":3437,"children":3439},{"id":3438},"第-4-层依赖熔断与降级",[3440],{"type":33,"value":3441},"第 4 层：依赖熔断与降级",{"type":27,"tag":35,"props":3443,"children":3444},{},[3445],{"type":33,"value":3446},"营销、推荐、评论等非核心依赖一旦变慢立即降级。",{"type":27,"tag":228,"props":3448,"children":3450},{"id":3449},"第-5-层数据层保护",[3451],{"type":33,"value":3452},"第 5 层：数据层保护",{"type":27,"tag":35,"props":3454,"children":3455},{},[3456],{"type":33,"value":3457},"库存、订单、支付链路再做最后的容量保护和优先级保障。",{"type":27,"tag":228,"props":3459,"children":3461},{"id":3460},"_101-一个真实收益对比示例",[3462],{"type":33,"value":3463},"10.1 一个真实收益对比示例",{"type":27,"tag":35,"props":3465,"children":3466},{},[3467],{"type":33,"value":3468},"某次活动页治理前后：",{"type":27,"tag":235,"props":3470,"children":3471},{},[3472,3494],{"type":27,"tag":239,"props":3473,"children":3474},{},[3475],{"type":27,"tag":243,"props":3476,"children":3477},{},[3478,3483,3489],{"type":27,"tag":247,"props":3479,"children":3480},{},[3481],{"type":33,"value":3482},"指标",{"type":27,"tag":247,"props":3484,"children":3486},{"align":3485},"right",[3487],{"type":33,"value":3488},"优化前",{"type":27,"tag":247,"props":3490,"children":3491},{"align":3485},[3492],{"type":33,"value":3493},"优化后",{"type":27,"tag":263,"props":3495,"children":3496},{},[3497,3514,3532,3550,3568],{"type":27,"tag":243,"props":3498,"children":3499},{},[3500,3505,3510],{"type":27,"tag":270,"props":3501,"children":3502},{},[3503],{"type":33,"value":3504},"高峰入口 QPS",{"type":27,"tag":270,"props":3506,"children":3507},{"align":3485},[3508],{"type":33,"value":3509},"62000",{"type":27,"tag":270,"props":3511,"children":3512},{"align":3485},[3513],{"type":33,"value":3509},{"type":27,"tag":243,"props":3515,"children":3516},{},[3517,3522,3527],{"type":27,"tag":270,"props":3518,"children":3519},{},[3520],{"type":33,"value":3521},"应用层实际承压 QPS",{"type":27,"tag":270,"props":3523,"children":3524},{"align":3485},[3525],{"type":33,"value":3526},"41000",{"type":27,"tag":270,"props":3528,"children":3529},{"align":3485},[3530],{"type":33,"value":3531},"14000",{"type":27,"tag":243,"props":3533,"children":3534},{},[3535,3540,3545],{"type":27,"tag":270,"props":3536,"children":3537},{},[3538],{"type":33,"value":3539},"下单接口超时率",{"type":27,"tag":270,"props":3541,"children":3542},{"align":3485},[3543],{"type":33,"value":3544},"7.2%",{"type":27,"tag":270,"props":3546,"children":3547},{"align":3485},[3548],{"type":33,"value":3549},"0.8%",{"type":27,"tag":243,"props":3551,"children":3552},{},[3553,3558,3563],{"type":27,"tag":270,"props":3554,"children":3555},{},[3556],{"type":33,"value":3557},"推荐服务错误扩散",{"type":27,"tag":270,"props":3559,"children":3560},{"align":3485},[3561],{"type":33,"value":3562},"影响主链路",{"type":27,"tag":270,"props":3564,"children":3565},{"align":3485},[3566],{"type":33,"value":3567},"被隔离",{"type":27,"tag":243,"props":3569,"children":3570},{},[3571,3576,3581],{"type":27,"tag":270,"props":3572,"children":3573},{},[3574],{"type":33,"value":3575},"大促扩容实例数",{"type":27,"tag":270,"props":3577,"children":3578},{"align":3485},[3579],{"type":33,"value":3580},"48",{"type":27,"tag":270,"props":3582,"children":3583},{"align":3485},[3584],{"type":33,"value":3585},"26",{"type":27,"tag":35,"props":3587,"children":3588},{},[3589],{"type":33,"value":3590},"这就是入口治理的价值：不是流量变少了，而是无效流量和非核心流量不再把全系统一起带崩。",{"type":27,"tag":179,"props":3592,"children":3593},{},[],{"type":27,"tag":183,"props":3595,"children":3597},{"id":3596},"十一给团队的-api-网关与流量治理检查清单",[3598],{"type":33,"value":3599},"十一、给团队的 API 网关与流量治理检查清单",{"type":27,"tag":228,"props":3601,"children":3603},{"id":3602},"网关职责层",[3604],{"type":33,"value":3602},{"type":27,"tag":59,"props":3606,"children":3609},{"className":3607},[3608],"contains-task-list",[3610,3622,3631],{"type":27,"tag":63,"props":3611,"children":3614},{"className":3612},[3613],"task-list-item",[3615,3620],{"type":27,"tag":3616,"props":3617,"children":3619},"input",{"disabled":18,"type":3618},"checkbox",[],{"type":33,"value":3621}," 是否明确网关只做入口治理，不承载重业务",{"type":27,"tag":63,"props":3623,"children":3625},{"className":3624},[3613],[3626,3629],{"type":27,"tag":3616,"props":3627,"children":3628},{"disabled":18,"type":3618},[],{"type":33,"value":3630}," 是否统一了鉴权、路由、基础限流和观测",{"type":27,"tag":63,"props":3632,"children":3634},{"className":3633},[3613],[3635,3638],{"type":27,"tag":3616,"props":3636,"children":3637},{"disabled":18,"type":3618},[],{"type":33,"value":3639}," 是否支持灰度和快速回滚",{"type":27,"tag":228,"props":3641,"children":3643},{"id":3642},"限流策略层",[3644],{"type":33,"value":3642},{"type":27,"tag":59,"props":3646,"children":3648},{"className":3647},[3608],[3649,3658,3667],{"type":27,"tag":63,"props":3650,"children":3652},{"className":3651},[3613],[3653,3656],{"type":27,"tag":3616,"props":3654,"children":3655},{"disabled":18,"type":3618},[],{"type":33,"value":3657}," 是否区分全局、接口、用户、租户、下游维度",{"type":27,"tag":63,"props":3659,"children":3661},{"className":3660},[3613],[3662,3665],{"type":27,"tag":3616,"props":3663,"children":3664},{"disabled":18,"type":3618},[],{"type":33,"value":3666}," 是否按业务优先级做分级保护",{"type":27,"tag":63,"props":3668,"children":3670},{"className":3669},[3613],[3671,3674],{"type":27,"tag":3616,"props":3672,"children":3673},{"disabled":18,"type":3618},[],{"type":33,"value":3675}," 是否有热点接口专项策略",{"type":27,"tag":228,"props":3677,"children":3679},{"id":3678},"熔断降级层",[3680],{"type":33,"value":3678},{"type":27,"tag":59,"props":3682,"children":3684},{"className":3683},[3608],[3685,3694,3703,3712],{"type":27,"tag":63,"props":3686,"children":3688},{"className":3687},[3613],[3689,3692],{"type":27,"tag":3616,"props":3690,"children":3691},{"disabled":18,"type":3618},[],{"type":33,"value":3693}," 是否对关键下游做了熔断",{"type":27,"tag":63,"props":3695,"children":3697},{"className":3696},[3613],[3698,3701],{"type":27,"tag":3616,"props":3699,"children":3700},{"disabled":18,"type":3618},[],{"type":33,"value":3702}," 是否提前设计了降级返回",{"type":27,"tag":63,"props":3704,"children":3706},{"className":3705},[3613],[3707,3710],{"type":27,"tag":3616,"props":3708,"children":3709},{"disabled":18,"type":3618},[],{"type":33,"value":3711}," 是否支持半开试探恢复",{"type":27,"tag":63,"props":3713,"children":3715},{"className":3714},[3613],[3716,3719],{"type":27,"tag":3616,"props":3717,"children":3718},{"disabled":18,"type":3618},[],{"type":33,"value":3720}," 是否对失败重试有边界控制",{"type":27,"tag":228,"props":3722,"children":3724},{"id":3723},"观测治理层",[3725],{"type":33,"value":3723},{"type":27,"tag":59,"props":3727,"children":3729},{"className":3728},[3608],[3730,3739,3748,3757],{"type":27,"tag":63,"props":3731,"children":3733},{"className":3732},[3613],[3734,3737],{"type":27,"tag":3616,"props":3735,"children":3736},{"disabled":18,"type":3618},[],{"type":33,"value":3738}," 是否能看到限流命中和熔断次数",{"type":27,"tag":63,"props":3740,"children":3742},{"className":3741},[3613],[3743,3746],{"type":27,"tag":3616,"props":3744,"children":3745},{"disabled":18,"type":3618},[],{"type":33,"value":3747}," 是否有入口到下游的 tracing",{"type":27,"tag":63,"props":3749,"children":3751},{"className":3750},[3613],[3752,3755],{"type":27,"tag":3616,"props":3753,"children":3754},{"disabled":18,"type":3618},[],{"type":33,"value":3756}," 是否能识别某个租户或接口异常放量",{"type":27,"tag":63,"props":3758,"children":3760},{"className":3759},[3613],[3761,3764],{"type":27,"tag":3616,"props":3762,"children":3763},{"disabled":18,"type":3618},[],{"type":33,"value":3765}," 是否有高峰保护演练",{"type":27,"tag":179,"props":3767,"children":3768},{},[],{"type":27,"tag":183,"props":3770,"children":3772},{"id":3771},"总结",[3773],{"type":33,"value":3771},{"type":27,"tag":35,"props":3775,"children":3776},{},[3777],{"type":33,"value":3778},"把 API 网关、限流、熔断、降级讲透，可以收敛成 5 句话：",{"type":27,"tag":117,"props":3780,"children":3781},{},[3782,3790,3798,3806,3814],{"type":27,"tag":63,"props":3783,"children":3784},{},[3785],{"type":27,"tag":51,"props":3786,"children":3787},{},[3788],{"type":33,"value":3789},"网关的核心价值是统一入口治理，不是单纯转发。",{"type":27,"tag":63,"props":3791,"children":3792},{},[3793],{"type":27,"tag":51,"props":3794,"children":3795},{},[3796],{"type":33,"value":3797},"限流限的不是请求数，而是系统风险暴露。",{"type":27,"tag":63,"props":3799,"children":3800},{},[3801],{"type":27,"tag":51,"props":3802,"children":3803},{},[3804],{"type":33,"value":3805},"熔断保护的是整条调用链，不只是某个下游。",{"type":27,"tag":63,"props":3807,"children":3808},{},[3809],{"type":27,"tag":51,"props":3810,"children":3811},{},[3812],{"type":33,"value":3813},"降级不是认输，而是让核心路径继续活着。",{"type":27,"tag":63,"props":3815,"children":3816},{},[3817],{"type":27,"tag":51,"props":3818,"children":3819},{},[3820],{"type":33,"value":3821},"真正成熟的方案一定是分层治理：边缘、网关、应用、依赖各有职责。",{"type":27,"tag":35,"props":3823,"children":3824},{},[3825],{"type":33,"value":3826},"如果你只记住一句话，我希望是这一句：",{"type":27,"tag":512,"props":3828,"children":3829},{},[3830],{"type":27,"tag":35,"props":3831,"children":3832},{},[3833],{"type":33,"value":3834},"好的入口治理，不是让所有请求都进来，而是让最重要的请求在最糟糕的时候也能进来。",{"type":27,"tag":35,"props":3836,"children":3837},{},[3838],{"type":33,"value":3839},"否则高峰一到，系统最先学会的不是弹性，而是——",{"type":27,"tag":35,"props":3841,"children":3842},{},[3843],{"type":27,"tag":51,"props":3844,"children":3845},{},[3846],{"type":33,"value":3847},"集体躺平。",{"type":27,"tag":3849,"props":3850,"children":3851},"style",{},[3852],{"type":33,"value":3853},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":963,"depth":963,"links":3855},[3856,3860,3868,3872,3879,3884,3889,3894,3899,3904,3912,3918],{"id":185,"depth":937,"text":188,"children":3857},[3858,3859],{"id":230,"depth":963,"text":233},{"id":341,"depth":963,"text":344},{"id":418,"depth":937,"text":421,"children":3861},[3862,3867],{"id":424,"depth":963,"text":427,"children":3863},[3864,3865,3866],{"id":431,"depth":984,"text":434},{"id":442,"depth":984,"text":445},{"id":453,"depth":984,"text":456},{"id":497,"depth":963,"text":500},{"id":528,"depth":937,"text":531,"children":3869},[3870,3871],{"id":585,"depth":963,"text":588},{"id":708,"depth":963,"text":711},{"id":756,"depth":937,"text":759,"children":3873},[3874,3875,3876,3877,3878],{"id":762,"depth":963,"text":765},{"id":788,"depth":963,"text":791},{"id":817,"depth":963,"text":820},{"id":856,"depth":963,"text":859},{"id":896,"depth":963,"text":899},{"id":1550,"depth":937,"text":1553,"children":3880},[3881,3882,3883],{"id":1567,"depth":963,"text":1570},{"id":1600,"depth":963,"text":1603},{"id":1628,"depth":963,"text":1631},{"id":1721,"depth":937,"text":1724,"children":3885},[3886,3887,3888],{"id":1750,"depth":963,"text":1753},{"id":1828,"depth":963,"text":1831},{"id":1870,"depth":963,"text":1873},{"id":2488,"depth":937,"text":2491,"children":3890},[3891,3892,3893],{"id":2515,"depth":963,"text":2518},{"id":2618,"depth":963,"text":2621},{"id":2657,"depth":963,"text":2660},{"id":3014,"depth":937,"text":3017,"children":3895},[3896,3897,3898],{"id":3020,"depth":963,"text":3023},{"id":3069,"depth":963,"text":3072},{"id":3103,"depth":963,"text":3106},{"id":3173,"depth":937,"text":3176,"children":3900},[3901,3902,3903],{"id":3189,"depth":963,"text":3192},{"id":3223,"depth":963,"text":3226},{"id":3257,"depth":963,"text":3260},{"id":3394,"depth":937,"text":3397,"children":3905},[3906,3907,3908,3909,3910,3911],{"id":3405,"depth":963,"text":3408},{"id":3416,"depth":963,"text":3419},{"id":3427,"depth":963,"text":3430},{"id":3438,"depth":963,"text":3441},{"id":3449,"depth":963,"text":3452},{"id":3460,"depth":963,"text":3463},{"id":3596,"depth":937,"text":3599,"children":3913},[3914,3915,3916,3917],{"id":3602,"depth":963,"text":3602},{"id":3642,"depth":963,"text":3642},{"id":3678,"depth":963,"text":3678},{"id":3723,"depth":963,"text":3723},{"id":3771,"depth":937,"text":3771},"markdown","content:topics:engineering:api-gateway-rate-limit-circuit-breaker-guide.md","content","topics/engineering/api-gateway-rate-limit-circuit-breaker-guide.md","topics/engineering/api-gateway-rate-limit-circuit-breaker-guide","md",1777109947907]