liveBook · Manning

Event-driven architecture

As explained in Learn Docker in a Month of Lunches, Second Edition

An event-driven architecture is a software design in which components publish events representing occurrences and other components react to those events.

Event-driven architecture lets an application publish events when things happen, while separate components react asynchronously. This keeps publishers loosely coupled to the features that consume their events. section 21.4

A practical message-queue design can provide:

  • Multiple subscribers receiving copies of the same event, such as a database saver and an audit handler. section 21.4
  • Independent feature additions, including Elasticsearch indexing, Google Calendar reminders, or audit logging, without changing event-publishing logic. section 21.4
  • Independent scaling and zero-downtime deployment, because a new handler can run in its own container while existing containers remain unchanged. section 21.4
  • Flexible infrastructure choices: Redis and NATS appear alongside RabbitMQ for routing and persistence, and Kafka for very high message volumes. section 21.5

Adding an audit handler

A to-do web app publishes an event when a user creates an item. The existing save handler stores it in SQL, while a separate audit handler subscribes to the same subject and logs its date and text. The web UI does not wait for either process, so additional subscribers do not change its request latency. section 21.4

# run the audit message handler, keeping the same scale 
# for the save handler:
docker compose -f docker-compose.yml `
 -f docker-compose-audit.yml up -d --scale save-handler=3
# check that the audit handler is listening:
docker logs todo-list-audit-handler-1
# browse to http:/./localhost:8080 and add some new items
# check the audit trail:
docker logs todo-list-audit-handler-1

Run the audit handler with Docker Compose, add items through the web UI, and inspect the resulting audit logs. section 21.4

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains publishing, subscription, handler isolation, deployment, and scaling, but does not detail queue internals.
Examples
Demonstrates a to-do audit handler, SQL persistence, Elasticsearch indexing, Google Calendar reminders, and Docker Compose deployments.
What you can do after
Apply it by adding independent message handlers, scaling consumers, and deploying new asynchronous features without changing existing containers.
How it connects
Connects event-driven architecture with message queues, asynchronous messaging, publish-subscribe messaging, and loose coupling.

Also explained in

Compare how 10 books explain event-driven architecture →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.