The Billion-Dollar Question
When you're serving 2 billion logged-in users per month like YouTube, every architectural decision has massive implications on infrastructure costs. Let's break down why YouTube chose Server-Sent Events (SSE) over WebSockets, and how this "simple" choice saves millions of dollars annually.
Understanding the Use Case
YouTube needs to push real-time updates to users:
- πΉ New video notifications from subscribed channels
- π¬ Live chat messages during streams
- π Like count updates
- π Community post notifications
- π Live streaming viewer counts
Key insight: Notice something? All these are one-way communications - server to client. Users don't need to send continuous data back to the server.
The Cost Breakdown: SSE vs WebSockets
Let's examine the infrastructure requirements and costs for each approach.
WebSockets: The Heavyweight Champion
Connection Type: Full-Duplex (Two-way) Protocol: Custom WebSocket protocol Connection Management: Complex sticky sessions required
- Load balancers need sticky sessions (session affinity)
- Connections must stay on the same server
- Complex horizontal scaling
- Higher memory footprint per connection (~8KB per connection)
- Custom protocols require special proxy/CDN handling
Cost Impact at YouTube Scale
WebSocket Infrastructure:
2 billion users Γ 8KB memory per WebSocket = 16 TB RAM
- Dedicated WebSocket servers (can't easily share with HTTP)
- Special load balancer configurations
- CDN complexity/bypass costs = Massive infrastructure costs
SSE: The Efficient Contender
Connection Type: Half-Duplex (One-way) Protocol: Standard HTTP/HTTPS Connection Management: Standard HTTP load balancing
- Works with standard HTTP load balancers (no sticky sessions!)
- Easy horizontal scaling
- Lower memory footprint (~2KB per connection)
- HTTP/2 multiplexing support
- Works through standard CDNs and proxies
SSE Cost Impact at Scale
SSE Infrastructure:
2 billion users Γ 2KB memory per SSE = 4 TB RAM
- Can share existing HTTP infrastructure
- Standard load balancing (no special config)
- CDN friendly (works like regular HTTP) = 75% less cost than WebSockets!
Real-World Cost Savings
Let's do some back-of-the-envelope math for YouTube's scale:
Scenario: 100 Million Concurrent Users
WebSocket Approach:
Server Requirements:
- 10,000 dedicated WebSocket servers (10K connections each)
- Each server: $200/month
- Special load balancers: $5,000/month each Γ 100
- Monthly cost: $2,500,000
Memory: 100M Γ 8KB = 800 GB Bandwidth overhead: ~20% higher (WebSocket frame overhead)
SSE Approach:
Server Requirements:
- Can use existing HTTP infrastructure
- 3,000 servers handling multiple duties (33K connections each)
- Each server: $200/month
- Standard load balancers: Already in place
- Monthly cost: $600,000
Memory: 100M Γ 2KB = 200 GB Bandwidth overhead: Minimal (standard HTTP)
Annual Savings: ~$22.8 million π
Technical Advantages Beyond Cost
SSE provides several technical advantages that go beyond just cost savings.
1. HTTP/2 Multiplexing Magic
One TCP connection can handle multiple SSE streams:
javascript1// One TCP connection, multiple SSE streams 2GET /notifications β Stream 1 3GET /live-updates β Stream 2 4GET /chat β Stream 3 5// All over ONE TCP connection!
WebSockets require separate connections for each stream.
2. Automatic Reconnection
SSE handles reconnection automatically:
javascript1// SSE handles this automatically 2const eventSource = new EventSource('/events'); 3// If connection drops, browser auto-reconnects 4// and sends Last-Event-ID to resume from where it dropped
With WebSockets, you must implement this yourself with manual retry logic and state tracking.
3. CDN & Proxy Friendly
SSE uses standard HTTP, so it works seamlessly with:
- Cloudflare
- Akamai
- AWS CloudFront
- Corporate proxies
- Firewalls
WebSockets often get blocked or require special configuration.
4. Infrastructure Reuse
YouTube's existing infrastructure:
- HTTP Load Balancers β (SSE works here)
- Nginx/Apache servers β (SSE works here)
- CDN layer β (SSE works here)
- DDoS protection β (SSE works here)
- Rate limiting β (SSE works here)
- Monitoring tools β (SSE works here)
No need for separate WebSocket infrastructure!
When WebSockets Would Cost More
Let's examine a bidirectional chat application at scale:

WebSockets for Chat
Advantages:
- β Native bidirectional support
- β Lower latency for client β server
Disadvantages:
- β More complex infrastructure
- β Higher memory per connection
SSE + HTTP POST for Chat
Approach:
- β SSE for server β client messages
- β Regular HTTP POST for client β server messages
- β Simpler infrastructure
- β Lower memory usage
- β οΈ Slightly higher latency for client messages (negligible for chat)
Verdict: For most chat applications, SSE + POST is still more cost-effective!
1. Sticky Sessions Nightmare
WebSocket Problem:
User connects to Server A Server A goes down User gets routed to Server B WebSocket connection lost β Must reconnect
SSE Solution:
User connects to any server Server goes down β Auto-reconnects to any available server No session stickiness needed!
2. Scaling Complexity
Adding new WebSocket servers:
- Update load balancer config
- Ensure session persistence
- Drain existing connections
- Test sticky session routing
- Monitor connection distribution
Adding new SSE servers:
- Add server to pool
- Done! β
3. Monitoring & Debugging
WebSocket debugging:
- Custom tools needed
- Binary frames harder to inspect
- Connection state tracking complex
SSE debugging:
- Standard HTTP tools work
- Plain text events
- curl works out of the box!
YouTube's Architecture Wins
By choosing SSE, YouTube gets:
- π° Lower Infrastructure Costs - 75% less memory per connection, no special WebSocket servers, standard load balancing
- π Better Scalability - Easy horizontal scaling, no sticky sessions, HTTP/2 multiplexing
- π οΈ Simpler Operations - Use existing HTTP stack, standard monitoring tools, easier debugging
- π Better Global Performance - Works through CDNs, no proxy issues, firewall friendly
- β‘ Built-in Resilience - Automatic reconnection, event ID tracking, browser-native support
Code Comparison: The Simplicity Factor
Let's compare the implementation complexity:
WebSocket Server (Complex)
javascript1// Requires special WebSocket library 2const WebSocket = require('ws'); 3const wss = new WebSocket.Server({ port: 8080 }); 4 5wss.on('connection', (ws) => { 6 // Manual ping/pong for health check 7 ws.isAlive = true; 8 ws.on('pong', () => ws.isAlive = true); 9 10 // Send message 11 ws.send(JSON.stringify({ type: 'notification', data: '...' })); 12}); 13 14// Manual cleanup of dead connections 15setInterval(() => { 16 wss.clients.forEach((ws) => { 17 if (!ws.isAlive) return ws.terminate(); 18 ws.isAlive = false; 19 ws.ping(); 20 }); 21}, 30000);
SSE Server (Simple)
javascript1// Uses standard HTTP 2app.get('/events', (req, res) => { 3 res.setHeader('Content-Type', 'text/event-stream'); 4 res.write('data: notification\n\n'); 5 // Connection cleanup handled by HTTP layer 6});
SSE is literally 4 lines vs 20+ lines for the same functionality!
The Bottom Line
For YouTube's use case:
- β Only need server β client communication
- β Millions of concurrent connections
- β Standard HTTP infrastructure available
- β Global CDN distribution needed
- β Cost optimization critical
SSE is the obvious choice.
WebSockets are great for:
- Real-time multiplayer games (constant bidirectional data)
- Collaborative editing (like Google Docs)
- Trading platforms (microsecond latency matters)
But for notifications, updates, and feeds? SSE saves millions while being simpler.
Takeaway for Your Projects
Ask yourself:
- Do I need bidirectional communication?
- No β Use SSE
- Yes β Still consider SSE + HTTP POST
- Do I need ultra-low latency (<100ms)?
- No β Use SSE
- Yes β Consider WebSockets
- Am I optimizing for scale and cost?
- Yes β Use SSE
- No β Either works
Rule of thumb: Start with SSE. Only upgrade to WebSockets when you have a proven need for bidirectional real-time communication.
Conclusion
YouTube didn't choose SSE because it's "good enough" - they chose it because it's the optimal solution for their specific needs. When serving billions of users, every architectural decision matters, and SSE provides the perfect balance of simplicity, cost-effectiveness, and scalability.
For most applications requiring real-time server-to-client updates, SSE is not just a viable optionβit's often the best choice. The cost savings, operational simplicity, and infrastructure reuse make it a compelling solution for any application at scale.