Design a Customer Support Chat
💬 What is a customer support chat? It is the chat bubble in the corner of a website. A customer types a question, the message lands in a shared inbox, and the system hands the conversation to a human agent who is free. Other agents can join to help, everyone sees who has read what, and people can react to a message with an emoji.
This problem looks like "build a chat app", which sounds huge. The trick is to notice that the interviewer is not asking for sockets or a database. They want to see three small pieces of logic done cleanly: routing a conversation to the right agent, read receipts for several people in one conversation, and reactions that can be toggled on and off. Each piece has an obvious first version that breaks in a specific way, which makes it a good medium problem.
Requirements
"Design the backend of a customer support chat like Intercom. Customers start conversations, agents answer them, several agents can work on one conversation, and we need read receipts and reactions."
That is a lot of nouns and very few rules. The questions below turn it into rules we can code against.
Clarifying Questions
You: How does a new conversation reach an agent? Do agents pick from a list, or does the system assign?
Interviewer: The system assigns it. Each agent has a capacity, the number of conversations they can own at once. Give the conversation to the least busy agent who still has room. If two are equally busy, pick the one who has been on the team longest, meaning the one added first.
You: And if every agent is full?
Interviewer: The conversation waits. When an agent frees up, or a new agent comes online, the oldest waiting conversation goes first.
You: What does "several agents on one conversation" mean? Do they share ownership?
Interviewer: One agent owns it, the assignee. Other agents can join as helpers, for example a billing expert. Helpers can read and write, but the conversation only counts against the owner's capacity.
You: For read receipts, do we need "seen by" for every participant, or just "seen" yes or no?
Interviewer: Per participant. The customer wants to know the agent saw the message, and the agents want to know the customer saw the reply. Also show each person how many messages they have not read.
You: Can a user add several different reactions to one message? And how do they remove one?
Interviewer: Yes, several different emojis, but each emoji once per user. Tapping the same emoji again removes it, like in most chat apps.
You: What happens when a conversation is closed?
Interviewer: Nobody can send new messages or join. People can still read the history and react.
You: Do we deliver messages to phones and browsers in real time?
Interviewer: Not in this round. Assume the clients call your methods. We can talk about live delivery at the end.
The first two answers are the heart of the problem. "Least busy, ties by seniority" and "oldest waiting first" are two separate rules: one picks the agent, the other picks the conversation. Keep them apart in your head and in the code.
💡 Interview tip: When a prompt lists features ("threads, multiple agents, read receipts, reactions"), ask one question per feature about the rule behind it. Features are easy to name; the rules are what you will be graded on.
Final Requirements
- Agents are registered with a capacity: the most conversations they can own at once.
- A customer opens a conversation with a first message. Conversations and messages get ids
1, 2, 3, ...(messages are numbered inside their conversation). - A new conversation joins a waiting queue. Waiting conversations are assigned oldest first, each to the agent with the fewest owned open conversations among agents with room; ties go to the agent added first. This runs whenever a conversation opens, an agent is added, or an owned conversation closes.
- Other agents can join a conversation as helpers. Helpers do not use capacity.
- Only participants (customer, assignee, helpers) can send messages. Only agent participants can close a conversation. A closed conversation accepts no new messages and no new helpers.
- Every participant has read receipts: we can mark messages read, count unread messages, and list who has read a given message.
- Any participant can toggle an emoji reaction on a message and see how many users have that emoji.
- The routing rule will probably change later (skills, languages, round robin), so swapping it must not touch the rest of the system.
Out of scope
- Network delivery: WebSockets, push notifications, typing indicators (see Extensibility).
- Storage, search and attachments.
- Bots, auto-replies and business hours.
- Several servers handling the same inbox.