Event-Driven AI Systems
You'll learn to
- -Describe an event, a topic, a producer and a consumer
- -Explain why adding a consumer should not require changing the producer
- -Name what event-driven design costs: ordering, duplicates and harder debugging
- -Pick AI workloads where events fit, such as ingestion and feedback
Tip: the highlighter is on - just select any text below to mark it. Use the highlighter button up top to change color or turn it off. Highlights are saved on this device only. Log in to save them to your account instead.
In the last chapter each stage called the next one. That is simple, and it creates a quiet problem: the code that uploads a document has to know about the chunker, the embedder, the virus scanner and the audit log, and it must change every time someone adds a new step. An event-driven system turns this around. The uploader announces what happened and walks away. Anyone who cares listens.
An Analogy: The Office Notice Board
Imagine an office notice board. Someone pins 'New policy document uploaded'. The compliance team reads it and files a copy. The search team reads it and updates the index. Nobody asked the person who pinned the note to tell each team in turn, and a new team can start reading the board tomorrow without anyone changing how notes are pinned. The board is the broker, a note is an event, and a team is a consumer.
The Vocabulary
- -An event is a fact about something that already happened, named in the past tense: doc.uploaded, answer.rated, release.promoted.
- -A topic is the name events are published under, so consumers can subscribe to the ones they care about.
- -A producer publishes events and does not know who is listening. A consumer reacts to events and does not know who produced them.
- -A broker, such as a message queue or a log, carries events between them and can hold them while a consumer is busy or down.
The code below is a tiny in-memory broker. Uploading a document triggers a chunker, which publishes one chunk.created event per chunk, and an embedder reacts to each. An audit log and a virus scanner also listen for the upload, and the scanner is built to fail. Run it and notice what the failure does and does not stop.
The upload produced three embedding lines, one for each chunk, and one audit line. The scanner raised an error and the broker recorded it, but the chunker, the audit log and the embedder all ran anyway. Then a thumbnail consumer was added in two lines, and the second upload picked it up without any change to the code that publishes uploads. That is the whole promise of the pattern: new behavior, no edits to the producer, and one broken listener does not take the others down.
What It Costs You
- -Duplicates: most brokers promise at-least-once delivery, so a consumer can see the same event twice. Make consumers idempotent, meaning a second delivery changes nothing.
- -Ordering: events may arrive out of order across topics. Do not assume the order unless the broker guarantees it for that topic.
- -Debugging: there is no single call stack. Put a correlation id on every event so one upload can be followed through every consumer.
- -Eventual consistency: a document is uploaded before it is searchable. Tell the user instead of pretending it is instant.
In AI systems events fit best where work fans out. Document ingestion is the classic case: upload, chunk, embed, index, audit. Feedback is another: a thumbs-down becomes an event that a consumer turns into a candidate eval case, as the production flywheel chapter describes. Model releases are a third: release.promoted can trigger a cache flush and a dashboard annotation. The HLD course covers brokers, replay and event sourcing in depth.
Do not use events for a step the user is waiting on that needs an answer back. 'Call the model and return the reply' is a request, not an announcement. Events suit work that can happen after the fact, in parallel, or for many listeners.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Discussion0
Join the Discussion
Sign in to leave comments, reply to others, or like insights.
No comments yet. Be the first to start the thread!