Message Status Tracking in a Chat Application
System DesignModel answerLast updated
Build the infrastructure for tracking and displaying message state (sent, delivered, read) in a messaging platform serving millions of users.
You're designing the status-tracking subsystem for a messaging platform. When a user sends a message, the UI must reflect three sequential states: acknowledged by infrastructure, received on the recipient's client, and opened by the recipient. Updates should appear immediately when both parties have connectivity, and synchronize correctly after either party reconnects.
Scope
- The underlying messaging infrastructure exists: clients maintain long-lived server connections, and messages persist until acknowledged by receiving devices. You're adding the status layer on top.
- Begin with direct messaging between two users; extend to multi-participant conversations once the foundation is clear.
- This platform operates at significant scale, making status traffic one of the highest-volume data flows.
Requirements
- Status progresses in one direction only: once marked as opened, a message cannot revert to merely delivered.
- You should define reasonable traffic assumptions since none are provided.
- Consider but don't assume answers for: privacy controls, multiple simultaneous sessions per account, and end-to-end encryption.
Discussion Points
- For group conversations, should senders see individual member status, aggregated status ("seen by all"), or both views?
- If users disable read confirmations, does that also hide others' confirmations from them?
- When one account has multiple active sessions, does reading on any session count universally?
- With end-to-end encryption, what can the server observe?
- After extended disconnection, how quickly must status synchronize when a user returns?
- What user base size and message volume should drive the design?
Hints
Hint 1
Think about what each device sends and when: the recipient's client knows when messages arrive and when the user views them, but how does that information travel back?
Hint 2
High volume means millions of status updates per second. Consider batching, watermarks ('read through message X'), and whether every state transition needs separate tracking.
Hint 3
Group chats amplify everything: one message to 100 members could mean 200 status events (delivered + read) per member. How do you prevent fan-out explosion?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Status Model
Define three progressive states: accepted (server confirmed), delivered (on recipient's device), read (recipient viewed). These form a strict sequence—no backward transitions. Each message carries a unique identifier and timestamp.
The recipient's client is authoritative for delivered and read; the server confirms accepted immediately upon receiving from sender.
Core Flow: Direct Messaging
Sending path:
- Sender's client transmits message over persistent connection
- Server responds immediately with accepted status + message ID
- Server forwards to recipient's device when online, or queues if offline
- Recipient's client confirms delivery with an ACK containing the message ID
- When recipient opens the conversation and scrolls to the message, client sends read acknowledgment
- Server routes both delivered and read events back to sender's client
Offline handling:
- If recipient is offline, server queues the message. When recipient reconnects, server delivers queued messages and recipient's ACKs flow back.
- If sender goes offline after sending, server persists status updates. On reconnect, sender's client receives all accumulated status changes.
State Storage
Server storage:
- Per-message status: last known state for each message (accepted/delivered/read) with timestamp
- Retention: keep status for ~30 days after read, or until confirmed received by sender
- Monotonic updates: server rejects any status regression (e.g., read→delivered)
Client storage:
- Full message history with current status
- Pending status updates queue for offline resilience
- On sync, client sends monotonic position: "all messages through ID X are read"
Volume Control
Assumptions: 500M daily active users, 100 messages per user per day = 50B messages daily = ~580K messages/sec. Each message generates 2-3 status events, so ~1.5M status events/sec.
Optimizations:
- Batching: Client aggregates status updates over 1-2 second windows, sends one batch instead of per-message events
- Watermark protocol: Instead of individual read receipts, send "read through message ID X" covering all prior messages in that conversation
- Server-side deduplication: Use message ID + status type as idempotency key
- Compression: WebSocket frame compression reduces status event payload size by 60-70%
Group Conversations
With N members, one message could generate 2N status events (delivered + read per member). For a 100-person group:
Fan-out problem: Naively, 100 members × 2 status updates each = 200 events back to sender.
Solution:
- Store per-member status server-side but don't send individual updates
- Sender receives aggregate counts: "delivered to 47/100, read by 23/100"
- Provide drill-down UI showing individual member status, fetched on-demand via API call, not pushed
- Use bloom filters or bitmaps for efficient "who has read this" queries at scale
- Update aggregates every 5-10 seconds instead of real-time
Multi-Device Consistency
One user with phone + desktop:
- Reading on either device should mark as read on both
- Server maintains one canonical status per account (not per device)
- When device A sends "read", server broadcasts to all user's devices including device B
- Use vector clocks or lamport timestamps to handle race conditions when both devices update simultaneously
Privacy & Encryption
Privacy toggle: If users can disable read receipts, common patterns:
- Reciprocal: disabling means you neither send nor receive them
- One-way: you stop sending but still see others' (fewer apps do this)
End-to-end encryption:
- Server cannot inspect message content but can see metadata (sender, recipient, message ID, timestamp)
- Status events (delivered/read) travel as separate metadata packets, not encrypted
- Message ID serves as correlation key between encrypted payload and status
Edge Cases & Consistency
Duplicates: Client may resend status due to network retry. Server uses (message_id, status_type, device_id) tuple for idempotent processing.
Reordering: Delivered event arrives after read event due to network delay. Server enforces monotonic rule: if already read, ignore delivered update.
Clock skew: Use server timestamp as source of truth, client timestamps only for UI hints.
Deleted messages: Retain status records even if message deleted; prevents status leakage ("why did delivered/read counts not match message count?").
Architecture Components
- Status Service: Dedicated microservice for status events, separate from message delivery
- Status Store: Fast key-value store (Redis/DynamoDB) with message_id as key, TTL for cleanup
- Event Queue: Kafka/Kinesis for asynchronous status propagation between sender and recipient regions
- WebSocket Gateway: Maintains persistent connections, forwards status events to connected clients
- Aggregation Workers: For group chats, consume status events and update aggregate counts
Scalability Numbers
With 1.5M status events/sec:
- Each event ~100 bytes = 150 MB/sec = ~13 TB/day
- Partition by conversation_id for horizontal scaling
- Cache hot conversations (active in last hour) in memory
- 30-day retention at 13 TB/day = ~390 TB total, compressed to ~100 TB
Common Mistakes
- Sending individual group status updates instead of aggregates (fan-out explosion)
- Not handling offline->online transition with bulk sync
- Forgetting monotonic enforcement leads to flickering UI
- Storing status forever instead of TTL-based cleanup
- Not batching high-frequency updates (read receipts as user scrolls)