Skip to main content

[Chat App] Architecture - High Level Design


Here are the infrastructure components and their relationships and responsibilities:

Chat App Infrastructure

Infrastructure components

⚙️ Compute & Routing

  • HTTP Load Balancer:Distributes REST API traffic evenly across HTTP servers to ensure scalability and high availability.
  • WebSocket Load Balancer:Balances long-lived WebSocket connections, helping the system handle many concurrent users reliably.
  • EC2 Instances (HTTP):Handle stateless API operations like user creation and message history retrieval, allowing horizontal scaling.
  • EC2 Instances (WebSocket):Maintain persistent connections for real-time features like sending/receiving messages, ensuring low-latency interaction.

🫙 Data Storage

  • DynamoDB:Provides fast read-write, scalable storage for various chat-related data: users, rooms, messages, and user-room relationships—all with flexible schema support and high throughput.

⚡️ Real-time Communication

  • Redis:Stores WebSocket connection IDs and enables cross-server message broadcasting between WebSocket EC2 instances.

Component responsibilities

  1. HTTP GET /users endpoint
    Client sends a request to retrieve all user data. The backend queries User DynamoDB and returns the result.

  2. HTTP POST /users endpoint
    Client creates a new user. The backend processes the data and writes it to User DynamoDB.

  3. HTTP GET /rooms/{room_id}/messages endpoint
    Client requests the message history of a chat room. The backend fetches the messages from messages DynamoDB and returns them.

  4. WebSocket create_room action
    Client sends a command to create a chat room via WebSocket. The backend stores the user-to-room relation in user_rooms DynamoDB.

  5. WebSocket create_room (continued)
    The system also creates the room metadata and stores it in rooms DynamoDB.

  6. WebSocket create_message action
    Client sends a new message via WebSocket. The backend stores it in messages DynamoDB.

  7. Redis Broadcast
    The system uses Redis to store WebSocket connection IDs and serve as a broadcast intermediary. This allows different WS EC2 nodes to be aware of existing connections, enabling real-time message forwarding to users, even if they are connected to different servers.