Chat API and Database System
Design the APIs and durable database flows for a bounded text-chat service without requiring real-time push delivery.
Problem statement
For this exercise, assume authenticated users create small chat rooms, add members, send text messages, and page through room history.
The interview emphasis is API semantics, database ownership, and basic request flows; clients poll for newer messages, so live sockets, presence, read receipts, and media are out of scope.
A successful send must be durable, retries must not create duplicate visible messages, and each room must expose one stable message order. Design the API contracts, entities, storage boundaries, minimum service flow, and failure behavior.
What to build
- A user can create a small chat room and add or remove authorized members.
- A current member can idempotently send a durable text message to a room.
- A current member can page through a stable room order and poll from a cursor for newer messages.
At scale
- For this exercise, assume peak traffic is 30,000 history-page or polling reads and 5,000 message sends per second.
- For this exercise, assume a room has at most 100 members, may retain 10 million messages, and a history response returns at most 100 messages.
- For this exercise, assume a successful send remains durable after any single service restart and a history page returns within 300 milliseconds at the 95th percentile.
- For this exercise, assume membership changes can race with sends; within two seconds of a committed removal, new sends by that user must be rejected, and every raced request has one auditable outcome.