What Is Event-Driven Architecture? Explained with Ruby on Rails
A customer places an order. Now an email has to go out, inventory has to move, and shipping has to be told. In a tightly coupled design the order code knows about all three, calls all three, and waits on all three - so when shipping gets slow, checkout gets slow with it.
Event-driven architecture turns that around. The application publishes one event saying what happened, and whoever cares subscribes and reacts on their own. This video follows a single Rails e-commerce example all the way through it.
What you will learn:
- Why direct calls between services become dependencies you pay for later
- What an event actually is, and how it differs from a command
- Producer, event, broker, consumer - what each one is responsible for
- The full flow, from saving the order to three consumers finishing their work
- What happens when one consumer is down, and what that depends on
- How Rails can get publishing off the web request using Active Job
- Why Active Job is a job queue and not a message broker
- The trade-offs: infrastructure, eventual consistency, repeats, debugging
- What the transactional outbox solves, and why you need it
The honest part: event-driven architecture does not give you exactly-once processing. Consumers will sometimes see the same event twice and have to tolerate it. Different parts of the system will briefly disagree. And saving the order and publishing its event are two separate writes - if the process dies between them, the event is simply lost. The transactional outbox is how you make those two writes one.
A note on the code: OrderEvents.publish is an application-level publisher you would write yourself. Rails has no such method.
Chapters:
00:00 - One order, three things to do
00:10 - The problem with direct calls
00:25 - What event-driven architecture is
00:40 - How it works, end to end
01:00 - A Ruby on Rails example
01:25 - Benefits and trade-offs
01:45 - The key takeaway
#EventDrivenArchitecture #RubyOnRails #SoftwareArchitecture #DistributedSystems #BackendDevelopment #SystemDesign #MessageBroker #Microservices #DevOps #PubSub
— #Astmation —
#software #systems, #automation, and #AI-powered #applications.
Build. Automate. Evolve.
https://astmation.com/
Watch on YouTube