KatInterview

Design a Serialized BLE Command Queue and Transport Handler

System DesignModel answer
HardModel answerSystem Designsystem-designiosbluetooth

Last updated

Architect a reliable, serialized command dispatch system for Bluetooth Low Energy peripherals with response matching, timeout management, and fault tolerance.

Architect an event-driven BLE (Bluetooth Low Energy) Command Handler for a mobile application communicating with an external peripheral device.

System Requirements

  1. Strict Serialization: Commands must be processed sequentially—no command can be issued until the preceding command completes (either via success, failure, or timeout).
  2. Response & Timeout Guarantee: Once a command is transmitted, the system must wait for a matching incoming response frame or an explicit execution timeout.
  3. Queue Unblocking & Failure Policy: A timed-out or failed command must unblock the dispatch queue according to a deterministic policy (e.g., configurable retries, drop, or queue invalidation).
  4. Thread-Safe Concurrent Submission: Multiple features within the app must be able to enqueue commands concurrently from any thread without race conditions.
  5. Robust Operations: Address transport fragmenting (MTU limits), asynchronous disconnects, Task cancellation, and unit testability.

Design the architecture, data models, state machine, concurrency/cancellation semantics, and edge-case failure strategies.