← Back
00:00

AI Coding Chat Server Design

Discord interview questions · Hard · Coding round · 6 tests

Discord reportedly uses an AI-assisted coding round where the candidate is asked to build a Discord-like chat server over TCP. For this practice version, ignore socket I/O and implement the server core: client sessions, slash commands, chat rooms, reconnection, and persisted room history.

Interface

type ChatEvent =
  | { type: 'connect'; clientId: string }
  | { type: 'disconnect'; clientId: string }
  | { type: 'input'; clientId: string; text: string }
  | { type: 'restart' };

interface Delivery {
  to: string;
  room: string | null;
  from: string | null;
  text: string;
}

interface SimulationResult {
  deliveries: Delivery[];
  state: {
    clients: Array<{
      clientId: string;
      nickname: string;
      connected: boolean;
      activeRoom: string | null;
      rooms: string[];
    }>;
    rooms: Array<{
      name: string;
      members: string[];
      history: Array<{ from: string; text: string }>;
    }>;
  };
}

simulateChatServer(events: ChatEvent[]): SimulationResult

Supported commands

  • /help - return the supported command list to that client.
  • /nick <name> - change the caller's nickname.
  • /users - list all currently connected nicknames, sorted ascending.
  • /quit - disconnect that client.
  • /create <room> - create a room if it does not already exist.
  • /join <room> - join a room, make it the active room, and replay the last 10 messages from that room to the joining client, oldest first.
  • /list - list all existing room names, sorted ascending.
Idle