All Blueprints
Real-time Systemscomplex complexity
Real-time Chat at Scale
Architecture for chat systems handling millions of concurrent users - connection management, fanout, persistence, and moderation.
Architecture
System Components
Key building blocks of this architecture, layered from infrastructure up
01
Connection Layer
WebSocket gateway with sticky sessions and graceful failover.
WebSocketLoad BalancerSticky Sessions
02
Message Bus
Pub/sub for fanning messages to subscribers - see Redis vs Memcached.
Redis Pub/SubNATSKafka
03
Presence Service
Online/offline indicators and typing notifications.
RedisHeartbeatsThrottling
04
Persistence
Durable message storage with pagination and search.
PostgreSQLElasticsearchS3
05
Push & Email Fallback
Notify offline users via push and email digests.
FCMAPNsResend
06
Moderation
Automated and human moderation for user safety.
OpenAI ModerationPerspective APIQueue
Planning
Key Considerations
Important factors to keep in mind when implementing this architecture
Plan connection capacity per node and pool aggressively
Design idempotent message delivery with client-side dedup
Implement graceful degradation when servers are unreachable
Contact me if you're scaling chat past 100k concurrent.
Options
Alternatives to Consider
Other approaches that might fit your specific needs
Stream Chat or Sendbird for managed chat
Liveblocks or Ably for real-time primitives
Matrix for federated chat
Need help implementing this architecture?
I can help you adapt this blueprint to your specific requirements and guide implementation from planning through production deployment.
Discuss Your ProjectReal-time Systems
Related Architectures
Other blueprints in this category