Design an in-process pub/sub library
Medium35 minFree, no account
Twenty lines that work and three questions about failure that decide the round.
The question
Design a publish/subscribe library used inside one process: topics, wildcard subscriptions, and ordering guarantees.
Be explicit about what happens when a subscriber throws, when one is slow, and when a subscriber is garbage.
Functional
- Subscribe to a topic or a wildcard pattern such as
order.*. - Publish a message to a topic.
- Unsubscribe, and subscribe-once.
- Optional: replay the last N messages to a new subscriber.
Non-functional
- One misbehaving subscriber must not affect the others or the publisher.
- A forgotten subscription must not keep its object alive forever.
- Ordering guarantees must be stated, not assumed.
35:00Commit to an answer before you open the solution. Reading it first teaches you to recognise good answers, which is not the skill being tested.
Stuck?
0 of 3 hints takenThe worked solution
written by a person · not a gradeScore yourself
0 of 5 marked- Efficient topic matching including wildcards20
- Error isolation per subscriber, surfaced rather than swallowed25
- A deliberate position on sync vs async delivery and slow subscribers25
- Addressed the subscription leak with a returned unsubscribe20
- Stated the ordering guarantees and handled re-entrancy10
We run no AI here and nothing on this page grades you. The score is yours, and the useful number is the one you get on the same problem a month from now, cold.
kept in this browser only