Design a packet reassembler API

Read the full interview experience this question came from →

Quick Overview

This question evaluates API design, stream-oriented buffer management, stateful packet assembly, input validation, concurrency control, testing strategy, and time/space complexity reasoning.

Design a packet reassembler API

Company: Bloomberg

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: Technical Screen

Design a PacketAssembler API that accepts streaming fragments and emits a completed payload once enough bytes have been received. Example interaction: packetit(0x04, 'a', 'b', 'c') -> no output (header 4 indicates total size; only 3 bytes arrived); packetit('d') -> 'abcd' (completes the prior packet). Specify the class/method signatures, state management (buffering and expected size), behavior for multiple consecutive packets, handling of invalid headers or oversized input, when/if state resets after emission, and thread-safety considerations. Provide tests and analyze time and space complexity.

Overview: This question evaluates API design, stream-oriented buffer management, stateful packet assembly, input validation, concurrency control, testing strategy, and time/space complexity reasoning.

Read the full Bloomberg Software Engineer interview experience this question came from

|Home/System Design/Bloomberg
Bloomberg logo
Bloomberg
Sep 6, 2025
mediumSoftware EngineerTechnical ScreenSystem Design
17
0

Design a PacketAssembler API for Streaming Fragments

Context and Assumptions

  • You are building a small component that assembles packets from a byte stream.
  • Each packet begins with a 1-byte header that encodes the payload length N (0–255). The header byte is not part of the payload.
  • The stream may arrive fragmented arbitrarily; a single call may contain parts of a packet or multiple full packets back-to-back.

Example interaction:

  • packetit(0x04, 'a', 'b', 'c') -> no output (header 4 indicates a 4-byte payload; only 3 bytes arrived)
  • packetit('d') -> 'abcd' (completes the prior packet)

Requirements

  1. Specify the class and method signatures of a PacketAssembler API.
  2. Describe state management: buffering, expected size, and how fragments are handled.
  3. Behavior when receiving multiple consecutive packets within one or many calls.
  4. Handling of invalid headers and oversized input (e.g., header value exceeds a configured maximum).
  5. Define when/how state resets after emission and on errors.
  6. Thread-safety considerations and options.
  7. Provide tests (unit-style examples) that exercise common and edge cases.
  8. Analyze time and space complexity.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...