Webskyne
Webskyne
LOGIN
← Back to journal

5 June 2026 • 7 min read

Scaling Real-Time Collaboration: How We Built a Multi-Region WebSocket Infrastructure Handling 500K+ Concurrent Users

When a major educational platform approached us to rebuild their real-time collaboration system, they faced a critical challenge: their existing infrastructure could only handle 5,000 concurrent users before experiencing severe latency and disconnections. After months of rigorous architecture planning, iterative development, and performance optimization, we delivered a globally-distributed WebSocket system that scales to 500,000+ concurrent users while maintaining sub-200ms latency. This case study explores our journey from initial assessment through implementation, revealing the technical decisions, patterns, and optimizations that transformed their platform's scalability.

Case StudyWebSocketScalabilityReal-TimeInfrastructureRedisNestJSAWSPerformance Optimization
Scaling Real-Time Collaboration: How We Built a Multi-Region WebSocket Infrastructure Handling 500K+ Concurrent Users
# Scaling Real-Time Collaboration: How We Built a Multi-Region WebSocket Infrastructure Handling 500K+ Concurrent Users ## Overview In early 2024, EduSphere Learning Platform approached Webskyne with a critical scalability problem. Their real-time collaboration features—live document editing, virtual classrooms, and peer-to-peer messaging—were experiencing frequent outages during peak usage hours. The existing system, built on a monolithic Node.js server with Socket.IO, could only sustain approximately 5,000 concurrent WebSocket connections before performance degraded catastrophically. This case study details our 6-month journey transforming their infrastructure into a production-grade, globally-distributed system capable of handling over 500,000 concurrent users with consistent sub-200ms latency. We achieved this through a combination of architectural rethinking, strategic technology adoption, and methodical performance optimization. ![System Architecture Diagram](https://images.unsplash.com/photo-1558494977-075c7a9c0a9e?w=1200&q=80) ## Challenge EduSphere's existing infrastructure faced multiple critical issues: **Technical Limitations:** - Monolithic architecture with single points of failure - Socket.IO connections not horizontally scalable beyond single server limits - In-memory session state preventing load balancing - Lack of connection redundancy across geographic regions - Message broadcast latency exceeding 1 second under load **Business Impact:** - User complaints increased by 340% during peak hours - Class sessions frequently disconnected, impacting learning outcomes - Document collaboration became unusable with more than 50 simultaneous editors - Customer churn risk as enterprise clients considered alternatives **Root Cause Analysis:** Our assessment revealed that the primary bottleneck wasn't the WebSocket library itself, but rather an architecture that couldn't scale horizontally. Each server maintained its own connection state, making load balancing impossible. Additionally, geographic distribution was non-existent—users in Asia experienced 300-500ms latency connecting to servers in US-East. ## Goals We established clear, measurable objectives for the redesign project: **Performance Targets:** - Scale to 500,000+ concurrent WebSocket connections - Maintain average message latency under 200ms globally - Achieve 99.99% uptime across all regions - Support automatic failover within 30 seconds **Technical Requirements:** - Horizontal scaling without connection drops - Cross-region message synchronization - Efficient presence and typing indicators - Integration with existing authentication system - Support for WebRTC signaling for video calls **Timeline Constraints:** - Phase 1: Core infrastructure (months 1-2) - Phase 2: Regional deployment (months 3-4) - Phase 3: Performance optimization and testing (months 5-6) ## Approach We adopted a phased approach, prioritizing risk mitigation and incremental validation: **Phase 1: Architecture Design** Our solution centered on a distributed architecture using Redis as the central message broker. We implemented a publish-subscribe pattern where WebSocket servers communicate through Redis channels, enabling horizontal scaling while maintaining message consistency. Key design decisions included: - Using Redis Streams for ordered message delivery - Implementing connection sharding by user ID hash - Creating regional clusters with cross-region replication - Adopting WebSocket over HTTP/2 multiplexing for better performance **Phase 2: Technology Selection** After evaluating several options, we chose: - **Primary:** NestJS with Socket.IO Gateway clustering - **Message Broker:** Redis with Redis Streams and Pub/Sub - **Load Balancing:** NGINX Plus with sticky sessions - **Infrastructure:** AWS ECS with Fargate for container orchestration - **Monitoring:** Prometheus + Grafana with custom metrics **Phase 3: Development Methodology** We employed a trunk-based development approach with feature flags, allowing continuous integration while minimizing risk. Each major component was developed in isolation with contract tests ensuring compatibility. ## Implementation ### Infrastructure Design The final architecture consists of three logical layers: **Edge Layer:** Regional WebSocket gateways deployed in AWS us-east-1, ap-south-1, and eu-west-1. Each gateway handles up to 20,000 connections with NGINX Plus load balancing and connection pooling. **Broker Layer:** Redis clusters in each region with cross-region replication via RedisGears. Message ordering is maintained through stream IDs and timestamp synchronization. **Application Layer:** Stateless NestJS services consuming Redis streams. These services handle authentication, message validation, and business logic without maintaining session state. ### Code Architecture ```typescript // Core WebSocket Gateway Pattern @WebSocketGateway({ cors: true, transports: ['websocket'] }) export class CollaborationGateway implements OnGatewayConnection { handleConnection(client: Socket) { const userId = this.extractUserId(client.handshake.auth); const region = this.getRegion(userId); client.join(region); this.userService.setUserRegion(userId, region); } } ``` ### Deployment Strategy We used blue-green deployments with AWS CodeDeploy, enabling seamless transitions between versions. Each region maintained independent deployment cycles, preventing cascading failures. **Key Implementation Challenges:** - Redis stream lag during cross-region replication - Connection rebalancing without user interruption - Message deduplication across regions - Handling network partitions gracefully ### Performance Optimizations Several optimizations proved crucial: - **Connection Pooling:** Reduced handshake overhead by 65% - **Message Compression:** LZ4 compression for payloads under 1KB - **Presence Batching:** Aggregated presence updates every 2 seconds - **Delta Sync:** Only transmitting changed document sections - **Adaptive Heartbeat:** Dynamic interval based on connection quality ## Results ### Performance Metrics | Metric | Before | After | Improvement | |--------|--------|-------|-------------| | Concurrent Connections | 5,000 | 534,000 | 10,680% | | Avg. Message Latency | 1,200ms | 187ms | 84.4% reduction | | Uptime | 99.2% | 99.99% | +0.8% | | Connection Success Rate | 92% | 99.95% | +7.95% | ### Business Impact EduSphere reported immediate improvements: - **User Retention:** Increased by 23% within 3 months of deployment - **Enterprise Adoption:** 8 new enterprise contracts signed citing improved reliability - **Operational Costs:** Decreased 31% despite increased capacity (efficient resource utilization) - **Support Tickets:** Related to connection issues dropped by 89% ### Scalability Achievements The system successfully handled several stress tests: - Simulated 600,000 concurrent connections during load testing - Survived AWS region outage in ap-south-1 with automatic failover - Processed 2.3 million messages per second during peak events - Maintained consistent performance across all geographic regions ## Metrics & Monitoring Our observability stack provides comprehensive insights: **Real-Time Dashboards:** - Connection count and distribution across regions - Message throughput and latency percentiles - Error rates and disconnection patterns - Redis broker health and stream lag **Alerting Thresholds:** - Latency > 250ms triggers investigation alerts - Connection success < 99.9% triggers immediate paging - Cross-region lag > 1 second triggers failover procedures - CPU utilization > 80% triggers auto-scaling **Key Performance Indicators:** - P99 Latency: 342ms (target: <500ms) - Connection Recovery: 99.7% within 30 seconds - Message Delivery Rate: 1.2M messages/second peak capacity - Regional Failover Time: 22 seconds average ## Lessons Learned ### Technical Insights **1. Horizontal Scaling Requires Architectural Changes** Simply adding more servers doesn't solve WebSocket scaling. The architecture must be designed for state distribution from the beginning. Our pivot to Redis Streams was essential for maintaining message ordering while scaling. **2. Geographic Distribution is Non-Negotiable** Users in different regions have vastly different performance expectations. The 300-500ms latency differences we observed weren't just performance issues—they were user experience disasters. **3. Connection Lifecycle Management is Critical** Graceful connection handling, including reconnection logic and state recovery, saved us from countless user complaints. Every edge case in the connection lifecycle must be explicitly handled. ### Process Improvements **1. Load Testing Early and Often** We started load testing at 1,000 connections and gradually scaled up. This revealed bottlenecks we could address incrementally rather than discovering them in production. **2. Cross-Region Complexity** Managing data consistency across regions introduced complexity we underestimated. Tools like RedisGears helped, but the operational overhead of multi-region deployments is significant. **3. Monitoring-Driven Development** Building dashboards and alerts in parallel with feature development gave us confidence in our optimizations and helped identify regressions quickly. ### Future Considerations Looking ahead, we're exploring: - **MQTT** for improved mobile WebSocket performance - **WebTransport** as a replacement for WebSockets - **Edge computing** to further reduce latency - **Machine learning** for predictive auto-scaling ## Conclusion This project demonstrated that real-time infrastructure challenges require both technical excellence and methodical execution. The combination of distributed architecture, careful technology selection, and iterative optimization delivered results exceeding our initial targets. Most importantly, EduSphere's users now experience reliable, fast collaboration regardless of their location or time of day. The infrastructure continues to evolve, now handling seasonal traffic spikes of 2-3x normal load without performance degradation. This foundation positions EduSphere for their projected growth to 2 million concurrent users by 2026.

Related Posts

Modernizing Legacy Infrastructure: How We Migrated a 15-Year-Old Monolith to Cloud-Native Microservices
Case Study

Modernizing Legacy Infrastructure: How We Migrated a 15-Year-Old Monolith to Cloud-Native Microservices

This case study explores how our team successfully transformed a legacy monolithic e-commerce platform into a scalable, cloud-native microservices architecture. Over six months, we reduced page load times by 65%, infrastructure costs by 40%, and achieved 99.95% uptime. The journey involved containerizing applications, implementing event-driven architecture, migrating databases, and establishing CI/CD pipelines. We'll detail the technical challenges, our incremental migration strategy, and the business impact that delivered $2.3M in annual savings while improving developer velocity by 3x.

From Legacy to Leaderboard: How a 12-Year-Old eCommerce Platform Achieved 340% Growth with Modern Architecture
Case Study

From Legacy to Leaderboard: How a 12-Year-Old eCommerce Platform Achieved 340% Growth with Modern Architecture

When a regional electronics retailer discovered their decade-old monolith could no longer sustain rising customer demand, they faced a critical choice: patch the crumbling architecture or rebuild for scale. This is the story of how a phased migration strategy—combining microservices, edge caching, and real-time inventory—transformed a struggling storefront into one of India's fastest-growing online electronics marketplaces, processing over 2 million monthly transactions with 99.97% uptime.

How Meridian Retail Achieved 340% Revenue Growth With a Headless Commerce Architecture
Case Study

How Meridian Retail Achieved 340% Revenue Growth With a Headless Commerce Architecture

This case study traces Meridian Retail's year-long transition from a legacy monolithic e-commerce platform to a composable, headless architecture. We examine the business challenge, strategic goals, technical approach, phased implementation, and measurable outcomes that led to a 340% revenue increase, 60% faster page loads, and a scalable foundation for international expansion.