System Design Quiz Practice
Active Recall Drill Session
← Exit SessionQuestion 1 of 1
hardSystem Design
Given this NotificationRouter, what happens when the SAME event id is published twice to the same subscribed channels?
code
class NotificationRouter {
constructor() { this.channels = []; this.delivered = new Set(); }
subscribe(c) { this.channels.push(c); }
publish(event) {
for (const c of this.channels) {
const key = `${c.name}:${event.id}`;
if (this.delivered.has(key)) continue;
this.delivered.add(key);
c.deliver(event);
}
}
}
const r = new NotificationRouter();
r.subscribe({ name: "email", deliver: (e) => console.log("sent:", e.id) });
r.publish({ id: "evt1" });
r.publish({ id: "evt1" });