This question has two distinct parts and I spent way too long on the WebSocket layer before the interviewer nudged me toward the email pipeline.
Start by clarifying requirements and scale, then design the core real-time messaging architecture using WebSockets and a pub/sub system. Next, design the email notification service that tracks user activity and unread messages, ensuring it scales and avoids spamming users. Finally, discuss trade-offs and potential optimizations.
Pro tip: Emphasize idempotency and rate limiting in the email notification service to prevent duplicate emails and respect user preferences, showing you consider real-world operational concerns.
Ask about expected number of users, messages per second, and whether chat is 1:1 or group. Also confirm email notification specifics: frequency, opt-out, and definition of 'logged in'.
Outline components: WebSocket servers for real-time messaging, a message queue (e.g., Kafka) for asynchronous processing, a database for message storage, and a separate service for email notifications.
Detail how messages are sent and received: clients connect via WebSockets, messages are published to a channel, and delivered to recipients. Discuss message ordering, delivery guarantees, and offline handling.
Design a scheduled job that queries for users inactive for 10+ days with unread messages, then sends emails via an email service (e.g., SES). Ensure idempotency and rate limiting.
Discuss trade-offs: push vs. pull for notifications, database choices (SQL vs. NoSQL), and how to scale WebSocket servers horizontally. Mention monitoring and failure handling.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.