InterviewDB
Experience
Chat Service: Implement a Multi-Room Chat Backend with Message History
phone
Interview Experience
Round 1 Coding
Problem
Implement a backend for a multi-room chat service. Users can join rooms, send messages, and fetch message history. Each message has a sender, timestamp, and content.
python
from datetime import datetime
class ChatService:
def create_room(self, room_id: str) -> None:
...
def join_room(self, user_id: str, room_id: str) -> bool:
...
def send_message(self, user_id: str, room_id: str,
content: str) -> dict:
**returns** message dict with auto-generated timestamp
...
def get_history(self, room_id: str,
limit: int = 50, before_ts: datetime = None) -> list[dict]:
...
def active_users(self, room_id: str) -> list[str]:
...
Example
chat = ChatService()
chat.create_room("general")
chat.join_room("alice", "general")
chat.join_room("bob", "general")
chat.send_message("alice", "general", "Hello!")
# -> {"id": "uuid", "sender": "alice", "content": "Hello!", "ts": ...}
chat.get_history("general", limit=10)
# -> [{"sender":"alice","content":"Hello!","ts":...}]
chat.active_users("general") -> ["alice", "bob"]
Follow-ups
- How would you implement
get_historywith cursor-based pagination for efficient scrolling? - How do you handle a user sending a message to a room they haven't joined?
- How would you push new messages to connected clients in real time (WebSockets vs. SSE vs. long polling)?
- How do you design the data model if rooms can have thousands of messages and you need fast lookups by time range?
Full Details
Round 1 Coding
Problem
Implement a backend for a multi-room chat service. Users can join rooms, send messages, and fetch message history. Each message has a sender, timestamp, and content.
python
from datetime import datetime
class ChatService:
def create_room(self, room_id: str) -> None:
...
def join_room(self, user_id: str, room_id: str) -> bool:
...
def send_message(self, user_id: str, room_id: str,
content: str) -> dict:
**returns** message dict with auto-generated timestamp
...
def get_history(self, room_id: str,
limit: int = 50, before_ts: datetime = None) -> list[dict]:
...
def active_users(self, room_id: str) -> list[str]:
...
Example
chat = ChatService()
chat.create_room("general")
chat.join_room("alice", "general")
chat.join_room("bob", "general")
chat.send_message("alice", "general", "Hello!")
# -> {"id": "uuid", "sender": "alice", "content": "Hello!", "ts": ...}
chat.get_history("general", limit=10)
# -> [{"sender":"alice","content":"Hello!","ts":...}]
chat.active_users("general") -> ["alice", "bob"]
Follow-ups
- How would you implement
get_historywith cursor-based pagination for efficient scrolling? - How do you handle a user sending a message to a room they haven't joined?
- How would you push new messages to connected clients in real time (WebSockets vs. SSE vs. long polling)?
- How do you design the data model if rooms can have thousands of messages and you need fast lookups by time range?
Free preview. Unlock all Notion questions →
About This Question
This is a candidate experience report from a notion interview during the phone round.
More Notion Interview Questions
InterviewDB
Notion SWE Phone - Document Store
InterviewDB
Mobile Logging Library: Design a Thread-Safe In-App Logger for Android and iOS
InterviewDB
Inline Database: Build an In-Memory Key-Value Store with SQL-Like Query Support
InterviewDB
JSON Display: Render Nested JSON as a Collapsible Tree in the Browser
InterviewDB
Mobile TODO App: Implement a Persistent TODO List with Offline Sync on Android/iOS