PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/System Design/Bloomberg

Design in-memory trade subscription processor

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to design concurrent, high-throughput in-memory subscription matching systems, covering skills in data structure selection, algorithmic complexity analysis, and concurrency control.

  • medium
  • Bloomberg
  • System Design
  • Software Engineer

Design in-memory trade subscription processor

Company: Bloomberg

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: Onsite

You are asked to design and implement the internal logic of an in-memory trade subscription processor in C++. A simplified interface is provided: ```cpp using HANDLE = int; struct Tread { std::string symbol; // e.g. "AAPL" int size; // number of shares std::string flag; // e.g. trade condition / venue flag }; class TreadProcessor { public: TreadProcessor() {} // Called whenever a new trade arrives from the market feed. void onNewTread(const Tread &tread); // Register interest in trades matching a given template. // Returns a handle that can later be used to unsubscribe. HANDLE subscribe(const Tread &filter, std::function<void(const Tread &)> callback); // Cancel a previous subscription. void unSubscribe(HANDLE handle); private: // Design and add your internal data structures here. }; ``` You may assume: - A **subscription** is defined by a `filter` of type `Tread` and a `callback` function. - A new trade `t` delivered via `onNewTread` **matches** a subscription `filter` if: - `t.symbol == filter.symbol` (exact match), and - optionally, for this question, you can assume `size` and `flag` must also match if they are non-zero / non-empty in the filter (i.e., the filter can act as a simple template with optional fields). - If a trade matches multiple subscriptions, **all** corresponding callbacks must be invoked with the trade. Functional requirements: 1. `subscribe(filter, callback)` - Registers a new subscription using the given `filter` and `callback`. - Returns a unique `HANDLE` that identifies this subscription. 2. `onNewTread(tread)` - Called for every incoming trade. - Must efficiently find all subscriptions that match `tread` and invoke their callbacks. 3. `unSubscribe(handle)` - Cancels the subscription associated with `handle` so that its callback is no longer invoked for future trades. Non-functional / design goals: - There can be up to `10^5` active subscriptions. - There can be tens of thousands of trades per second. - Aim for efficient average time complexity for `onNewTread` and `subscribe`. - Design for reasonable memory usage. - Assume at least one thread will be calling `onNewTread`, and another thread may be adding/removing subscriptions. Discuss how you would handle thread safety. **Task** Describe and justify a design for the internals of `TreadProcessor`: - What data structures will you store in `private` to support fast matching? - How will `subscribe`, `onNewTread`, and `unSubscribe` be implemented conceptually using those data structures? - Analyze the time and space complexity of your design. - Discuss how you would handle concurrency (e.g., locks, lock-free approaches, sharding, or other strategies) to support high throughput while maintaining correctness.

Quick Answer: This question evaluates a candidate's ability to design concurrent, high-throughput in-memory subscription matching systems, covering skills in data structure selection, algorithmic complexity analysis, and concurrency control.

Related Interview Questions

  • Design streaming mention analytics with search and alerts - Bloomberg (hard)
  • Design a Global Marketing Email Platform - Bloomberg (medium)
  • Design a fair event registration queue API - Bloomberg (medium)
  • Explain Kafka partitions and delivery semantics - Bloomberg (hard)
  • Design auth, session security, and top-N users - Bloomberg (hard)
Bloomberg logo
Bloomberg
Oct 16, 2025, 12:00 AM
Software Engineer
Onsite
System Design
6
0

You are asked to design and implement the internal logic of an in-memory trade subscription processor in C++. A simplified interface is provided:

using HANDLE = int;

struct Tread {
    std::string symbol;  // e.g. "AAPL"
    int         size;    // number of shares
    std::string flag;    // e.g. trade condition / venue flag
};

class TreadProcessor {
public:
    TreadProcessor() {}

    // Called whenever a new trade arrives from the market feed.
    void onNewTread(const Tread &tread);

    // Register interest in trades matching a given template.
    // Returns a handle that can later be used to unsubscribe.
    HANDLE subscribe(const Tread &filter,
                     std::function<void(const Tread &)> callback);

    // Cancel a previous subscription.
    void unSubscribe(HANDLE handle);

private:
    // Design and add your internal data structures here.
};

You may assume:

  • A subscription is defined by a filter of type Tread and a callback function.
  • A new trade t delivered via onNewTread matches a subscription filter if:
    • t.symbol == filter.symbol (exact match), and
    • optionally, for this question, you can assume size and flag must also match if they are non-zero / non-empty in the filter (i.e., the filter can act as a simple template with optional fields).
  • If a trade matches multiple subscriptions, all corresponding callbacks must be invoked with the trade.

Functional requirements:

  1. subscribe(filter, callback)
    • Registers a new subscription using the given filter and callback .
    • Returns a unique HANDLE that identifies this subscription.
  2. onNewTread(tread)
    • Called for every incoming trade.
    • Must efficiently find all subscriptions that match tread and invoke their callbacks.
  3. unSubscribe(handle)
    • Cancels the subscription associated with handle so that its callback is no longer invoked for future trades.

Non-functional / design goals:

  • There can be up to 10^5 active subscriptions.
  • There can be tens of thousands of trades per second.
  • Aim for efficient average time complexity for onNewTread and subscribe .
  • Design for reasonable memory usage.
  • Assume at least one thread will be calling onNewTread , and another thread may be adding/removing subscriptions. Discuss how you would handle thread safety.

Task

Describe and justify a design for the internals of TreadProcessor:

  • What data structures will you store in private to support fast matching?
  • How will subscribe , onNewTread , and unSubscribe be implemented conceptually using those data structures?
  • Analyze the time and space complexity of your design.
  • Discuss how you would handle concurrency (e.g., locks, lock-free approaches, sharding, or other strategies) to support high throughput while maintaining correctness.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Bloomberg•More Software Engineer•Bloomberg Software Engineer•Bloomberg 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.