惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
GRAHAM CLULEY
T
Tenable Blog
Know Your Adversary
Know Your Adversary
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy International News Feed
S
Security Affairs
NISL@THU
NISL@THU
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Schneier on Security
Schneier on Security
S
SegmentFault 最新的问题
S
Schneier on Security
G
Google Developers Blog
V
V2EX
C
Check Point Blog
U
Unit 42
Google DeepMind News
Google DeepMind News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
S
Secure Thoughts
博客园 - 司徒正美
Recorded Future
Recorded Future
P
Proofpoint News Feed
Spread Privacy
Spread Privacy
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
AI
AI
博客园 - 聂微东
N
News and Events Feed by Topic
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
Recent Commits to openclaw:main
Recent Commits to openclaw:main
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
Project Zero
Project Zero
W
WeLiveSecurity
博客园 - Franky

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Great Stack to Doesn't Work #8 — Load Balancer: "Traffic Incoming, Nothing Standing"
Mehmet TURAÇ · 2026-06-12 · via DEV Community

Great Stack to Doesn't Work #8

Load Balancer: "Traffic Incoming, Nothing Standing"

A survival guide for when everything goes wrong in production.


Your application handles 1,000 requests per second without breaking a sweat. You put a load balancer in front of it. Now it handles 200 requests per second and half of them return 502.

The load balancer, the thing you deployed to improve reliability, just became the single point of failure. Not because it's broken — because you configured it wrong.


Nginx vs HAProxy vs Envoy: The Decision Tree

These three dominate the load balancer space. They overlap significantly but each has a sweet spot.

Nginx: The Swiss army knife. Web server, reverse proxy, load balancer, static file server. If you're already running Nginx for your web server and need basic load balancing (round-robin, least connections, IP hash), adding upstream configuration is trivial. Configuration is file-based, hot-reloadable with nginx -s reload.

Best for: teams that want simplicity and are already in the Nginx ecosystem. Small to medium traffic. Static configuration that doesn't change often.

HAProxy: Purpose-built for load balancing. More sophisticated health checking, connection management, and traffic routing than Nginx. The stats page gives you real-time visibility into backend health, connection counts, and error rates. ACL-based routing is powerful for complex traffic patterns.

Best for: high-traffic environments where you need fine-grained control over connection behavior, advanced health checking, and detailed operational metrics.

Envoy: Built for service mesh and microservices. Dynamic configuration via xDS APIs (no file reloads). First-class support for gRPC, HTTP/2, and WebSocket. Built-in distributed tracing, circuit breaking, and rate limiting. Heavier and more complex than Nginx or HAProxy.

Best for: microservices architectures, especially when used as a sidecar proxy (Istio, Linkerd). Dynamic environments where backends change frequently. Teams that need service mesh capabilities.

The honest answer: for 80% of deployments, Nginx or HAProxy is sufficient. Envoy adds capabilities most teams don't need and complexity every team feels.


Connection Pooling and Keepalive: The Performance Multiplier

Every new TCP connection requires a three-way handshake: SYN, SYN-ACK, ACK. On a local network, that's ~0.5ms. Through TLS, add another 1-2ms for the TLS handshake. When your load balancer opens a new connection to a backend for every request, those milliseconds multiply by thousands of requests per second.

Upstream keepalive maintains persistent connections between the load balancer and your backends. Instead of opening a new connection per request, the load balancer reuses an existing one.

Nginx:

upstream backend {
    server 10.0.0.1:8080;
    server 10.0.0.2:8080;
    keepalive 64;          # Keep 64 idle connections per worker
    keepalive_timeout 60s;  # Close idle connections after 60 seconds
    keepalive_requests 1000; # Max requests per connection before recycling
}

server {
    location / {
        proxy_pass http://backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";  # Required for keepalive
    }
}

The proxy_http_version 1.1 and proxy_set_header Connection "" lines are critical. Without them, Nginx defaults to HTTP/1.0 for upstream connections, which doesn't support keepalive. This is the most common configuration mistake — keepalive is configured on the upstream block but disabled by the proxy settings.


Buffer Sizes: The Silent 502 Generator

When your backend sends a response, Nginx buffers it before forwarding to the client. If the response exceeds the buffer size, Nginx writes to a temporary file on disk. If even that fails (disk full, permissions, or buffering disabled), you get a 502.

proxy_buffer_size 16k;         # Buffer for the first part of the response (headers)
proxy_buffers 8 16k;           # 8 buffers of 16k each for the body
proxy_busy_buffers_size 32k;   # How much can be sent to the client while still buffering

Default proxy_buffer_size is 4k or 8k depending on the platform. If your backend returns large headers (big cookies, verbose auth tokens, lots of custom headers), 4k isn't enough. The response gets truncated. 502.

How to diagnose: if you see upstream sent too big header while reading response header from upstream in Nginx error logs, increase proxy_buffer_size.

For large response bodies (reports, data exports, file downloads), consider proxy_buffering off to stream directly from backend to client without buffering. This reduces memory usage but means the backend connection stays open for the entire transfer duration.


Rate Limiting: Protecting Your Backends

Rate limiting at the load balancer layer protects your backends from traffic spikes, abuse, and accidental DDoS from misbehaving clients.

Request-based rate limiting (Nginx):

limit_req_zone $binary_remote_addr zone=api:10m rate=100r/s;

server {
    location /api/ {
        limit_req zone=api burst=200 nodelay;
        proxy_pass http://backend;
    }
}

This allows 100 requests per second per IP. The burst=200 allows brief spikes up to 200 requests, and nodelay processes burst requests immediately instead of queuing them.

Connection-based rate limiting:

limit_conn_zone $binary_remote_addr zone=conn:10m;

server {
    location / {
        limit_conn conn 50;  # Max 50 concurrent connections per IP
        proxy_pass http://backend;
    }
}

Connection limits protect against slowloris attacks and clients that open hundreds of connections without closing them.

Choose the right key for rate limiting. $binary_remote_addr works for direct client connections. Behind a CDN or another proxy, all requests come from the CDN's IP — you need to rate limit on a header like X-Forwarded-For or a custom API key header instead.


SSL Termination: More Than Just Certificates

SSL termination at the load balancer means clients connect via HTTPS to the load balancer, and the load balancer connects to backends via HTTP. This offloads the crypto work from your backends and centralizes certificate management.

OCSP stapling eliminates the latency of clients checking certificate revocation status:

ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;

SSL session caching avoids repeating the full TLS handshake for returning clients:

ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
ssl_session_tickets off;  # Or on, but rotate keys

Protocol and cipher selection:

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
ssl_prefer_server_ciphers on;

Disable TLS 1.0 and 1.1 — they're deprecated. Prefer TLS 1.3 when clients support it; the handshake is faster (1-RTT vs 2-RTT) and the cipher suites are simpler.


WebSocket Proxying: The Upgrade Dance

WebSocket connections start as HTTP and upgrade to a persistent bidirectional channel. Load balancers need explicit configuration to handle the upgrade.

location /ws {
    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400s;   # 24 hours — don't timeout idle connections
    proxy_send_timeout 86400s;
}

Without the Upgrade and Connection headers, the load balancer treats the WebSocket request as a regular HTTP request and closes the connection after the first response.

The proxy_read_timeout is critical. Default is 60 seconds. WebSocket connections are often idle for long periods (waiting for events). A 60-second timeout kills idle connections, forcing clients to reconnect constantly.

For health checks on WebSocket backends, use a separate HTTP health check endpoint. Don't try to WebSocket handshake as a health check — it's fragile and slow.


Health Checks: Active vs Passive

Passive health checks monitor real traffic. If a backend returns 5 errors in 10 seconds, mark it as unhealthy and stop sending traffic for 30 seconds. This is reactive — you don't detect problems until real users are affected.

Nginx (open-source) only supports passive health checks:

upstream backend {
    server 10.0.0.1:8080 max_fails=3 fail_timeout=30s;
    server 10.0.0.2:8080 max_fails=3 fail_timeout=30s;
}

Active health checks send synthetic requests to backends on a schedule. If a backend fails the health check, it's removed from the pool before any user traffic reaches it. This is proactive.

HAProxy:

backend api_servers
    option httpchk GET /health
    http-check expect status 200
    server srv1 10.0.0.1:8080 check inter 5s fall 3 rise 2
    server srv2 10.0.0.2:8080 check inter 5s fall 3 rise 2

inter 5s: check every 5 seconds. fall 3: mark unhealthy after 3 consecutive failures. rise 2: mark healthy again after 2 consecutive successes.

The ideal is both: active health checks to detect unhealthy backends proactively, passive health checks as a safety net for failures that the health check endpoint doesn't catch (like the health endpoint returning 200 while the application is actually deadlocked — the theme of Episode #4).


War Story: The Night of 502s

E-commerce platform. Nginx load balancer. 8 backend servers. Normal evening traffic: 15,000 requests per second. Black Friday preview campaign launched at 20:00.

20:05 — Traffic spikes to 45,000 rps. Load balancer CPU is fine. Backends are handling it.

20:12 — 502 errors start appearing. 2%, then 5%, then 15%. Backend servers show 40% CPU usage. They're not overloaded.

20:20 — On-call engineer checks Nginx error logs: no live upstreams while connecting to upstream. All 8 backends are marked as unhealthy.

What happened: the backends were responding, but slowly. Under 3x normal traffic, response times went from 50ms to 800ms. Nginx's proxy_read_timeout was set to the default: 60 seconds. That wasn't the problem. The problem was proxy_connect_timeout: 5 seconds. Under load, the backends' TCP accept queues filled up. New connections took 6 seconds to establish. Nginx marked them as failed (connect timeout). After max_fails=3 — three timeouts in fail_timeout=30s — Nginx marked the backend as unhealthy.

All 8 backends hit the same threshold within minutes of each other. All marked unhealthy. No backends left. 100% 502s.

The fix:

  1. Increased proxy_connect_timeout to 15 seconds.
  2. Increased backend somaxconn and application listen backlog to 65535.
  3. Increased keepalive connections to reduce new connection overhead.
  4. Added max_fails=5 instead of the default 1 (yes, Nginx's default max_fails is 1).

The backends were never overloaded. They were slow to accept new connections under burst load, and the load balancer's aggressive failure detection made the problem worse.


War Story: The SSL Certificate Surprise

Less technical, more organizational. The SSL certificate for the production domain expired at 06:00 on a Tuesday. Auto-renewal was configured but pointed to a DNS provider account that someone had changed the password on 3 months earlier. The renewal failed silently. The monitoring check for certificate expiry was set to alert at 7 days — but the team had suppressed that alert because "it auto-renews, we don't need the noise."

At 06:00, every HTTPS request to the platform failed. Browser users got a scary red warning page. API clients got TLS handshake errors. Mobile apps crashed because they enforced certificate pinning.

Time to diagnosis: 12 minutes (fast — someone was already awake).
Time to fix: 4 hours. Issuing a new certificate required DNS validation, which required accessing the DNS provider, which required a password reset, which required access to an email account that was tied to an employee who had left the company.

Lessons:

  1. Never suppress certificate expiry alerts. Set them at 30 days, 14 days, and 3 days.
  2. Monitor the actual renewal process, not just the expiry date. If renewal fails, alert immediately.
  3. DNS provider credentials are as critical as production credentials. Store them in the same secret manager.
  4. Certificate pinning in mobile apps means you can't recover by switching to a different certificate authority quickly. Consider HPKP alternatives or pin to the CA, not the leaf certificate.

Key Takeaways

The load balancer is infrastructure you interact with through configuration, not code. Every default is a decision someone made for a general case that probably doesn't match your specific case.

Connection keepalive between the load balancer and backends is the single highest-impact configuration change for most setups. Followed by correct buffer sizes, then timeouts.

Health checks should be active, not just passive. Passive checks detect problems after users are affected. Active checks detect problems before.

And manage your SSL certificates like the critical infrastructure they are. An expired certificate is a total outage with a 4-hour recovery time if you haven't prepared.



Over to You

Nginx, HAProxy, or Envoy? What's your go-to and why? Any load balancer misconfiguration horror stories?


If you enjoyed this, I write about production engineering, AI systems, and the messy reality of building software at scale.

Follow me:

This is part of the **Great Stack to Doesn't Work* series — a survival guide for when everything goes wrong in production. Follow the series to catch every episode.*