PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Discord

Implement an asyncio-based chat server

Last updated: Apr 18, 2026

Quick Overview

This question evaluates a candidate's skill in asynchronous network programming and concurrent connection handling, including protocol parsing, room management, message broadcasting, and graceful resource cleanup using Python's asyncio.

  • medium
  • Discord
  • Coding & Algorithms
  • Software Engineer

Implement an asyncio-based chat server

Company: Discord

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Async Chat Server (Python `asyncio`) Implement a TCP chat server using Python `asyncio`. ### Part 1 — Single global room Your server listens on a given port and supports multiple concurrent clients. **Protocol (line-based text):** - When a client connects, the server prompts for a **username** (single line). - After login, each line a client sends is treated as a chat message. - The server **broadcasts** each message to all *other* connected clients in the format: - `<username>: <message>` **Behavior requirements:** - A client should not receive its own message back. - Handle client disconnects gracefully (no crashes; cleanup resources). - The server should continue serving other clients if one client misbehaves (e.g., disconnects mid-line). ### Part 2 — Basic chat commands Extend the protocol to support: - `/join <room>`: join (and create if needed) a named room. - Each user is in exactly **one room at a time**. - After joining, broadcasts only go to users in the **same room**. - `/who`: return the list of usernames currently in the user’s room. - `/quit`: disconnect. **Constraints / assumptions:** - Up to ~1,000 concurrent connections. - Use only standard library (`asyncio` / `socket` / etc.). - Favor clear concurrency handling and correctness over advanced features (no persistence required).

Quick Answer: This question evaluates a candidate's skill in asynchronous network programming and concurrent connection handling, including protocol parsing, room management, message broadcasting, and graceful resource cleanup using Python's asyncio.

Related Interview Questions

  • Implement Game Metadata Lookups - Discord (hard)
  • Implement User Sessionization From Event Stream - Discord (hard)
Discord logo
Discord
Oct 25, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
30
0

Async Chat Server (Python asyncio)

Implement a TCP chat server using Python asyncio.

Part 1 — Single global room

Your server listens on a given port and supports multiple concurrent clients.

Protocol (line-based text):

  • When a client connects, the server prompts for a username (single line).
  • After login, each line a client sends is treated as a chat message.
  • The server broadcasts each message to all other connected clients in the format:
    • <username>: <message>

Behavior requirements:

  • A client should not receive its own message back.
  • Handle client disconnects gracefully (no crashes; cleanup resources).
  • The server should continue serving other clients if one client misbehaves (e.g., disconnects mid-line).

Part 2 — Basic chat commands

Extend the protocol to support:

  • /join <room> : join (and create if needed) a named room.
    • Each user is in exactly one room at a time .
    • After joining, broadcasts only go to users in the same room .
  • /who : return the list of usernames currently in the user’s room.
  • /quit : disconnect.

Constraints / assumptions:

  • Up to ~1,000 concurrent connections.
  • Use only standard library ( asyncio / socket / etc.).
  • Favor clear concurrency handling and correctness over advanced features (no persistence required).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Discord•More Software Engineer•Discord Software Engineer•Discord Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.