Preparing your design workspace

Loading the problem and your saved attempt…

Design an In-Memory Publish-Subscribe Library

Model one application-scoped event manager, token-based subscriptions, snapshot delivery, and truthful per-callback outcomes.

Design the low-level object model and interfaces for an in-memory publish-subscribe library. The library exposes one application-scoped EventManager access point; the construction or dependency-injection mechanism is open, and the manager need not be a static global or own every internal responsibility.

For this exercise, named events are registered before use. subscribe(event, callback) creates a registration and returns an opaque token. For this exercise, the library issues opaque tokens that are distinct across all events for the lifetime of that EventManager and are never reused after removal.

Repeated subscriptions of the same callback to the same event receive different tokens. unsubscribe(event, token) removes exactly that event-token registration and returns whether it existed; a token used with another event and a repeated removal both return false without changing other registrations.

publish(event, data) treats the publication data as immutable for that call, captures the event's active callbacks in subscription order, invokes each captured callback at most once, and returns a read-only success or failure outcome list for the captured tokens. One callback failure must not prevent later callbacks.

A subscription change after the snapshot affects later publishes only. Unknown events are explicit errors. Durable storage, retries, distributed brokers, consumer groups, networking, and user-interface concerns are outside scope.