PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/System Design/Akuna Capital

Design communication handler and exceptions

Last updated: Mar 29, 2026

Quick Overview

This question evaluates object-oriented design, API and state management skills along with exception handling and identity-based reasoning by requiring implementation of a single-connection communication handler and a custom CommunicationException; it belongs to the System Design domain and emphasizes practical implementation details rather than purely conceptual theory. Such questions are commonly asked to assess a candidate's ability to enforce invariants, manage limited resources and error conditions in a mutable service interface, and demonstrate practical coding-level design and testing of runtime behaviors.

  • medium
  • Akuna Capital
  • System Design
  • Software Engineer

Design communication handler and exceptions

Company: Akuna Capital

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: Take-home Project

Create two classes: ( 1) CommsHandler(CommsHandlerABC), an abstract base class with methods connect(self, user1: Caller, user2: Caller) -> str, hangup(self, user1: Caller, user2: Caller) -> str, and clear_all(self) -> None. Behavior: connect establishes a connection and stores the two callers; if user1 is user2, raise CommunicationException with the message "{user1.name} cannot connect with {user2.name}!"; if user1 and user2 are different and the communication line is already in use, raise CommunicationException with "Connection in use. Please try later"; otherwise store the connected users and return "Connection established between {user1.name} and {user2.name}". Behavior: hangup ends the connection if user1 and user2 are currently communicating; if user1 is user2, raise CommunicationException with "{user1.name} cannot hangup with {user2.name}"; if user1 and user2 are different and communicating, disconnect them and return "{user1.name} and {user2.name} are disconnected"; if they are not communicating, raise CommunicationException with "{user1.name} and {user2.name} not found in the communication channel". Behavior: clear_all clears the communication channel regardless of current users. ( 2) CommunicationException(Exception): accepts an error message in its constructor and is raised as specified. Assume class Caller is already implemented. Provide class definitions and brief tests or examples.

Quick Answer: This question evaluates object-oriented design, API and state management skills along with exception handling and identity-based reasoning by requiring implementation of a single-connection communication handler and a custom CommunicationException; it belongs to the System Design domain and emphasizes practical implementation details rather than purely conceptual theory. Such questions are commonly asked to assess a candidate's ability to enforce invariants, manage limited resources and error conditions in a mutable service interface, and demonstrate practical coding-level design and testing of runtime behaviors.

Related Interview Questions

  • Implement a two-user communications handler - Akuna Capital (medium)
  • Design an order-matching engine - Akuna Capital (hard)
  • Fix and harden an object pool - Akuna Capital (hard)
  • Design user communication functions - Akuna Capital (easy)
  • Design user communication manager APIs - Akuna Capital (medium)
Akuna Capital logo
Akuna Capital
Sep 6, 2025, 12:00 AM
Software Engineer
Take-home Project
System Design
1
0

Implement a Communication Handler with Exceptions

Context

You are building a single-line communication handler that can connect exactly two Caller instances at a time. The environment already provides:

  • Caller: a class with at least a .name attribute (assume implemented elsewhere).
  • CommsHandlerABC: an abstract base class specifying the interface for a communication handler.

Your task is to implement a concrete CommsHandler subclass that enforces the specified behaviors and to define a custom CommunicationException.

Requirements

Classes to Implement

  1. CommsHandler(CommsHandlerABC)
    • Methods to implement:
      • connect(self, user1: Caller, user2: Caller) -> str
      • hangup(self, user1: Caller, user2: Caller) -> str
      • clear_all(self) -> None
    • Behavior:
      • connect:
        • If user1 is user2, raise CommunicationException with the exact message: "{user1.name} cannot connect with {user2.name}!"
        • If user1 and user2 are different and the communication line is already in use, raise CommunicationException with: "Connection in use. Please try later"
        • Otherwise, store the two connected users and return: "Connection established between {user1.name} and {user2.name}"
      • hangup:
        • If user1 is user2, raise CommunicationException with: "{user1.name} cannot hangup with {user2.name}"
        • If user1 and user2 are different and are currently communicating, disconnect them and return: "{user1.name} and {user2.name} are disconnected"
        • If they are not communicating, raise CommunicationException with: "{user1.name} and {user2.name} not found in the communication channel"
      • clear_all:
        • Clear the communication channel regardless of current users (no return value).
  2. CommunicationException(Exception)
    • Accepts an error message in its constructor and is raised as specified.

Notes

  • Use identity checks (is) when comparing callers (i.e., same object instance), not name equality.
  • The handler supports only one active connection at a time.
  • Provide brief tests or usage examples demonstrating the specified behaviors.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Akuna Capital•More Software Engineer•Akuna Capital Software Engineer•Akuna Capital System Design•Software Engineer System Design
PracHub

Master your tech interviews with 7,500+ 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.