Skill 1.1.12

Design architectures that support real-time data processing by using WebSocket and publish-subscribe patterns (for example, by using API Gateway WebSocket APIs).

Key Concepts

An API Gateway WebSocket API keeps a persistent connection with each client and routes messages by a route selection expression to Lambda or other integrations. The $connect route authenticates the client and stores its connection ID (for example in DynamoDB with the user and subscribed topics), $disconnect removes it, and back-end code pushes messages to a client by calling the @connections management API with that ID.

The publish-subscribe side decouples producers from the connection layer: producers publish to SNS, EventBridge or Kinesis, and a consumer looks up which connections subscribe to the topic and posts to each. Connection limits, idle timeouts (10 minutes) and the maximum connection duration (2 hours) mean clients must reconnect, so subscriptions are stored server-side rather than in memory.