Separate the socket from the routing state
How connection registries and subscription mappings route published events to WebSocket clients while handling disconnects, reconnects, and slow consumers. · advanced
A persistent WebSocket connection is a delivery address, not a subscription. API Gateway holds the socket; short-lived handlers maintain application state. A connection registry associates a connection ID with its principal, tenant, endpoint, and lifetime. A subscription mapping associates an authorized topic with connection IDs.
This design accepts subscribe and publish commands through the socket. Route handlers update membership or enqueue an authorized publication. A separate worker resolves its recipients and calls PostToConnection for each one. API Gateway does not automatically turn application topics into WebSocket broadcasts. The diagram shows application interactions; routine service acknowledgments are omitted.
The selected interfaces matter: the gateway must expose API Gateway routes and its connection-management API, the registry must support keyed membership queries and conditional updates, and the backlog must support SQS visibility and deletion semantics. Similar-looking messaging services are not interchangeable implementations of these contracts.
| Role | Selected component | Nearby alternatives | Contract they lack |
|---|---|---|---|
| Socket gateway | API Gateway | ELB; AppSync | API Gateway routes and PostToConnection |
| Queryable membership | DynamoDB | EventBridge; SNS | Keyed registry queries and conditional updates |
| Work backlog | SQS | Kinesis Data Streams; Data Firehose | SQS visibility and per-message deletion |
1 / 6 Clients send subscription and publication commands over their established API Gateway WebSocket connections.
AWS architecture icons are the property of Amazon Web Services. BlowStack is not affiliated with or endorsed by AWS.