← Hot Agent Startup Interview Insights
Start by clarifying requirements and constraints, then outline a high-level design using a central broker with per-topic subscriber lists protected by locks. Implement the core classes (Broker, Topic, Subscriber) with careful lock management to avoid deadlocks and race conditions, and discuss trade-offs like lock granularity and delivery guarantees.
Pro tip: Mention that you would use a single lock per topic to reduce contention and avoid deadlocks, and that you would copy the subscriber list under lock before delivering messages to prevent holding the lock during I/O.
Ask about expected scale, message delivery guarantees (at-least-once, at-most-once), and whether subscribers can be slow or unresponsive. This shows you think about real-world implications.
Propose a central broker that manages topics and subscribers. Each topic maintains a list of subscribers and a lock. Publishers send messages to the broker, which dispatches to subscribers.
Outline classes: Broker (with methods subscribe, unsubscribe, publish), Topic (with subscriber list and lock), and Subscriber (with a thread-safe queue and a worker thread). Use threading.Lock or RLock for synchronization.
Use a lock per topic to protect the subscriber list. When publishing, acquire the lock, copy the subscriber list, release the lock, then deliver messages to avoid holding the lock during I/O. Use condition variables or queues for subscriber message delivery.
Talk about lock granularity (global vs per-topic), handling slow subscribers (bounded queues, dropping messages), and potential deadlocks (lock ordering). Mention testing with stress tests.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.