esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Event-Driven: Announce What Happened and Let Other Parts React

In an event-driven system, one part announces that something happened, and other parts react on their own instead of being called and made to wait.

In short

An event-driven system is one where a part announces that something happened and other parts react on their own, instead of being called and made to wait.

10 min readFree

What You Will Learn

In this lesson you will learn what event-driven means in system design. You will meet the three roles that make it work, see how it differs from a normal call where one part waits for another, and weigh what you gain and what you give up. A worked example from an online store shows the idea in use, and short quizzes let you test your understanding.

Most software starts work by calling another part and waiting for the answer. An event-driven design changes that habit. One part says that something happened, and the parts that care react on their own. Teams often use this style to start background tasks, such as sending an email, without making the user wait for them.

Key words

Event
A short record that says something happened, such as an order being placed. It usually has a name and some data.
Producer
The part of the system where something happens. It creates the event and sends it out.
Consumer
A part that listens for certain events and does its own work when one arrives.
Event channel
The path that carries events from producers to consumers. It is often a queue or a message broker.
Message broker
A program that receives events, keeps them in order, and delivers them to the consumers that want them.
Queue
A line of messages. In a basic queue, each message goes to one consumer.
Asynchronous
Not waiting. The sender moves on without waiting for the receiver to finish.
Loose coupling
Parts depend on each other as little as possible. One part does not need to know the others exist.
Duplicate
The same event arriving more than once.
Out-of-order
Events arriving in a different sequence from the one in which they were sent.

What Does Event-driven Mean?

An event is a fact about something that already happened. It is written down as a small record with a name, such as OrderPlaced, and some data, such as the order number and the total. Because the event describes the past, it is a notice, not an order to a specific part to do a specific job.

In this course, event-driven means that one part announces that something happened, and other parts react to that announcement on their own. Nobody calls them directly and waits for a reply. Writers on the subject describe the same basic pattern: components communicate by producing and reacting to events rather than calling each other. This style is often used to trigger background work and to keep parts loosely connected, so a change in one part does not force changes in the others.

What Are the Three Roles?

Almost every event-driven system has three roles. Each role has one job, and the sender never needs to know who listens.

  • Producer

    The part where something happens. It creates the event and publishes it to the channel. It does not look up who will handle the event.

  • Event channel

    The middle path, usually a queue or a message broker. It holds events for a while and hands them to the parts that want them.

  • Consumer

    A part that subscribes to the events it cares about. When a matching event arrives, it does its own work and does not call the producer back.

The key result is that the producer and consumers are separated. The producer only needs to know the event's name and shape. A consumer only needs to know which events it wants.

Queue or Broker

A queue is a line of messages. In a basic queue each message goes to one consumer, which suits sharing out work, such as a list of emails to send. A broker is a larger program that receives events, keeps them in order, and routes them to every consumer that subscribes. Many people use the word broker for both. The main point is the same: the channel sits between the producer and the consumers, so they never talk directly.

Tip

Think of the channel as a mailbox. The sender drops the letter in and goes back to work. The reader picks it up when ready.

How Do Events Compare with Direct Calls?

A direct call works like a phone call. The caller asks a question and waits on the line until the answer comes back. An event works more like a notice on a board. The writer posts it and leaves, and readers who need it check the board when they can.

  • Timing

    A direct call makes the caller wait. An event is asynchronous, so the producer continues right after it publishes.

  • Coupling

    A direct call needs the caller to know the other part's address and what it offers. An event needs only the event's name and its shape.

  • Adding new work

    With direct calls, a new feature often means editing the caller. With events, you add a new consumer, and the producer stays the same as long as the event keeps its shape.

  • Reply

    A direct call returns an answer right away. An event usually sends nothing back to the producer.

Event-driven systems can still get a reply when they truly need one. That is an extra pattern built on top of events, so the default stays asynchronous.

Adding a New Consumer

Suppose a team wants a new report that counts orders per day. With direct calls, the checkout code must change so it calls the report. With events, the report team subscribes to the OrderPlaced event and starts receiving it. The checkout team does not need to change its code. This is the main reason teams choose the style for systems that grow.

Worked Example: An Online Order

Take an online store. When a customer places an order, the checkout is the producer. Three other services need to react: one sends a confirmation email, one reserves stock in inventory, and one updates the sales dashboard. Here is how the flow runs.

  1. 1

    Checkout saves the order

    The checkout service records the order and completes its own part of the work.

  2. 2

    Checkout emits OrderPlaced

    It publishes an event named OrderPlaced with the order number, the items, and the total, and sends it to the event channel.

  3. 3

    The channel keeps the event

    The broker stores the event and keeps it in order with the other events.

  4. 4

    Consumers react on their own

    The email service, the inventory service, and the dashboard service each receive the event and do their own work at their own speed.

  5. 5

    Checkout does not wait

    Checkout never waits for any of the three. The customer can already see the thank-you page while the email is still being prepared.

The Code Sketch

The sketch below is a toy, not a real broker. It keeps a list of consumers and passes each event to all of them. It shows the wiring. The publish step names no email or stock code, so the producer does not know who reacts. This toy runs everything in one step, so it does not show the waiting-free part of a real system. Real brokers add storage, retries, and separate workers.

Python
class Broker:
    def __init__(self):
        self.consumers = []

    def subscribe(self, handler):
        self.consumers.append(handler)

    def publish(self, event):
        for handler in self.consumers:
            handler(event)


def send_email(event):
    print("email sent for order", event["order_id"])


def reserve_stock(event):
    print("stock reserved for order", event["order_id"])


broker = Broker()
broker.subscribe(send_email)
broker.subscribe(reserve_stock)
broker.publish({"type": "OrderPlaced", "order_id": 1001})

Output

email sent for order 1001
stock reserved for order 1001

Check Your Thinking

Quick check

A photo app must resize each uploaded image, notify the user's followers, and update the search index whenever someone posts a photo. Why might the upload service publish one PhotoUploaded event instead of calling those three services itself, and what new problem must you plan for?

What You Gain and What It Costs

Event-driven design is a trade, not a free upgrade. Its benefits matter most when a system has many parts and heavy traffic. Its costs show up in how the system behaves and how people find and fix problems.

  • Resilience

    If a consumer is offline, events can wait in the channel until it returns. The producer keeps working while one reader is down.

  • Scalability

    A busy consumer can be run as several copies that share the load, and the producer does not have to change.

  • Eventual results

    Some parts may show older data for a short time. Results arrive later rather than instantly. The full model has its own lesson.

  • Harder debugging

    One user action now spreads across many parts. Tracing what happened needs logs and IDs that follow each event, because a single call stack no longer shows the whole story.

Duplicates and Out-of-Order Events

MQTT offers at-least-once delivery as one of its three quality-of-service levels. Events can also arrive out of order, so an older event may land after a newer one. Removing repeats does not fix order. An old event that arrives late is not a duplicate, but applying it can still produce the wrong result.

  1. 1

    Give each event a unique ID

    The producer stamps every event with an ID that never changes, even when the event is sent again.

  2. 2

    Record what was handled

    The consumer saves the IDs of the events it has already processed.

  3. 3

    Skip repeats

    When an incoming event's ID is already saved, the consumer ignores it.

  4. 4

    Check the version

    If events carry a version or sequence number, the consumer ignores any event that is not newer than the data it already holds.

Tip

A customer charged twice because a retry arrived twice is a classic bug. Build every consumer so that running it twice gives the same result as running it once.

When Should You Choose It?

Event-driven design fits best when several parts must react to the same fact, when some work can finish later, and when a slow task should not hold up the user. It fits poorly when the caller needs an answer right now and must be exactly right at that moment. A request that expects a direct response is clearer as a function call, while using events everywhere makes a system hard to follow.

Tip

Ask two questions before you pick events: Does the caller need the answer in this same step? Can the work finish a little later without harm? If the answer to the first is yes and the second is no, a direct call is usually safer.

Quick check

A bank app must show a customer's exact balance on screen right after a transfer. A teammate proposes publishing a TransferMade event and updating the balance later from the consumers. What is the strongest reason to push back?

Key Takeaways

Event-driven design means a producer announces what happened, and consumers react on their own. A channel such as a queue or a broker sits between them, so the sender never waits and never needs to know who receives the event. You gain loose coupling, room to add new consumers, and resilience when one consumer is down. You pay with delayed results, harder debugging, and the need to handle duplicate and out-of-order events. Job queues, scheduled timing, and returned results each have their own lessons.

Sources

How is this lesson?

Last updated on 17 November 2026

Learn with me

Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.