1. Subscribe
A consumer subscribes to an event by name; it never knows who emits it.
bus.on("order.placed", sendEmail)Typorithm · medium
Step 1 of 8 · intro card
Scale & Decoupling
In event-driven architecture, components communicate through events on a bus. Producers emit events and consumers subscribe; neither calls the other directly, so they stay decoupled and fan out asynchronously.
A producer emits a named event onto a bus; any number of consumers subscribe to that name. The producer never references a consumer, and consumers never reference each other.
One emit fans out to every subscriber: sending an email, updating inventory, and tracking analytics all happen from the single order.placed event, independently.
Because consumers run asynchronously and may finish at different times, the system reaches eventual consistency rather than updating everything in one synchronous step.
Producers emit events; consumers subscribe by name.
One event fans out to many independent subscribers.
Decoupling brings async fan-out and eventual consistency.
const bus = new EventEmitter()
bus.on("order.placed", sendEmail)
bus.on("order.placed", updateInventory)
bus.on("order.placed", trackAnalytics)
bus.emit("order.placed", order)Connect each part of the code to the concept before you type.
A consumer subscribes to an event by name; it never knows who emits it.
bus.on("order.placed", sendEmail)Multiple consumers subscribe to the same event and react independently.
bus.on("order.placed", updateInventory)The producer emits an event with a payload; it never calls the consumers directly.
bus.emit("order.placed", order)The payload travels with the event so each consumer has the data it needs.
orderRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.