0
0
HLDsystem_design~12 mins

Long polling and Server-Sent Events in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Long polling and Server-Sent Events

This system demonstrates two ways to push updates from a server to a client: Long Polling and Server-Sent Events (SSE). It supports real-time notifications with minimal delay and efficient resource use.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +--------------------+
  |                    |
Long Polling Service   SSE Service
  |                    |
  v                    v
Database <-----------> Cache
Components
User
client
Initiates requests and receives real-time updates
Load Balancer
load_balancer
Distributes incoming user requests evenly to API Gateway instances
API Gateway
api_gateway
Routes requests to either Long Polling or SSE service based on client capability
Long Polling Service
service
Handles long polling connections by holding requests until new data is available or timeout
Server-Sent Events (SSE) Service
service
Maintains open HTTP connections to push updates to clients as events occur
Database
database
Stores persistent data and event updates
Cache
cache
Stores recent events for quick access to reduce database load
Request Flow - 9 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayLong Polling Service or SSE Service
Long Polling Service or SSE ServiceCache
CacheLong Polling Service or SSE Service
Long Polling Service or SSE ServiceDatabase
DatabaseLong Polling Service or SSE Service
Long Polling Service or SSE ServiceUser
Long Polling Service or SSE ServiceCache
Failure Scenario
Component Fails:Cache
Impact:Cache misses increase, causing more database queries and higher latency
Mitigation:System falls back to database queries; add cache replication or fallback cache to reduce load
Architecture Quiz - 3 Questions
Test your understanding
Which component decides whether to use Long Polling or Server-Sent Events?
ACache
BAPI Gateway
CLoad Balancer
DDatabase
Design Principle
This architecture shows how to efficiently deliver real-time updates using two methods: Long Polling holds client requests open to wait for new data, while Server-Sent Events keep a persistent connection to push updates. Using a cache reduces database load and improves response times.