AI Hints
Home›System Design Tutorial›Robust Messaging
System Design · Lesson 72 of 120

Event-Driven Design

React to what happened.

⏱ 2 min read▶ Video at 1:26:16🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

So far, the checkout service tells other services what to do. Send an email. Update stock. In an event driven design, it simply announces what happened, order placed, and other services decide how to react.

Event-Driven Design
From the video: Event-Driven Design
  • Commands: do this
  • Events: this happened
  • Others decide what to do

Commands vs events

With commands, the checkout service must know about every other service, and call each one. Adding a new feature means changing checkout. With events, checkout just publishes order placed. A new loyalty service can subscribe tomorrow, without anyone touching checkout.

Commands

  • Sender knows everyoneNew feature: change senderTightly coupled

Events

  • Sender just announcesNew feature: subscribeLoosely coupled

An order, event by event

Here's an order in an event driven Shoply. Checkout publishes order placed. Payments reacts, charges the card, and publishes payment succeeded. The warehouse reacts to that, packs the box, and publishes order shipped. And the email service reacts to each event, keeping the customer informed.

  1. Order placed
  2. Payment succeeded
  3. Order shipped
  4. Emails at each step
An order, event by event
From the video: An order, event by event

Summary

Event driven designs announce what happened, and let other services react. They're flexible and loosely coupled, but harder to follow. Next, doing work now or later. Batch versus stream.

Key takeaways
  • Announce events
  • Others react
  • Loosely coupled
Next up: Batch vs Stream — later or now