You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
+-----------------+------------------+
| Field | Type |
+-----------------+------------------+
| chat_id | UUID (PK) |
| type | ENUM (1:1/group) |
| created_at | TIMESTAMP |
+-----------------+------------------+
5. Message Delivery Status
Message States:
SENT → Message saved to server
DELIVERED → Pushed to recipient's device
READ → Recipient opened the chat
Implementation:
1. Sender sends message → Server stores with status=SENT
2. Server pushes to recipient → Update status=DELIVERED
3. Recipient opens chat → Client sends read receipt
4. Server updates status=READ, notifies sender
6. Group Messaging
Small Groups (< 100)
Fan-out on write
Push to each member immediately
Large Groups (100-500)
Hybrid approach
Push to online members
Others poll on app open
Message to Group:
1. Save message to group chat storage
2. Lookup online members (from presence service)
3. Push to online members via WebSocket
4. Offline members: Save in their inbox queue
7. Presence/Online Status
Redis Structure:
Key: presence:<user_id>
Value: { server_id, last_seen, status }
TTL: 60 seconds
Heartbeat every 30 seconds to maintain online status
8. Media Handling
Upload Flow:
1. Client requests upload URL (pre-signed S3 URL)
2. Client uploads directly to S3
3. Client sends message with media_url
4. Generate thumbnails asynchronously
Delivery:
- Images served via CDN
- Videos: Multiple quality levels
9. Offline Message Delivery
When user comes online:
1. Fetch undelivered messages from inbox queue
2. Send via WebSocket
3. Mark as delivered
4. Clear from queue