liveBook · Manning

Handler

As explained in Microservices Patterns, Second Edition

An event handler is a software component that receives an event and performs the associated processing.

An event handler receives an event and performs the associated processing. It can advance a choreography-based saga, carry out an asynchronous follow-up action, or update a CQRS view. section 10.1.2 section 6.2.4 section 13.3

In a choreography-based saga, services exchange events over channels. Events communicate operation outcomes and carry data between participants; inbound adapters handle them, while outbound adapters publish events. An outgoing event can be published by domain logic or by the handler for an incoming event. section 10.1.2

Order creation and notification

An order operation can publish an event to a message channel, allowing a notification handler to send a confirmation email separately. Order creation can then succeed even when the external email service is unavailable. section 6.2.4

Asynchronous handlers reduce runtime coupling to slow or unavailable external systems and can support scalable background processing. They also introduce more complexity than direct calls or the Observer pattern: event publication, duplicate messages, and transactions spanning multiple steps need careful design. Use the simpler collaboration mechanism when that complexity is not justified. section 6.2.4

In a CQRS view, an event handler typically delegates updates to a view repository; a query handler delegates queries to it. To ensure idempotency, the event handler must update the view and record the event ID atomically. Concurrent handlers must not corrupt a record they both update. section 13.3 section 13.3.1

Figure 10.2 The choreography-based implementation of the Create Order Saga consists of events, channels, event publishers, and event handlers
simple create order choreography design

Follow the event handlers, publishers, and channels that coordinate the order saga. section 10.1.2

How Microservices Patterns, Second Edition covers it

How deep it goes
Explains handler responsibilities and operational trade-offs, including atomic event recording and concurrent view updates.
Examples
Illustrates order events coordinating services and triggering confirmation emails, alongside a configured Eventuate event consumer.
What you can do after
Evaluate when asynchronous handlers reduce coupling and what publication, deduplication, and transaction complexities they introduce.
How it connects
Connects handlers to publish/subscribe, choreography-based sagas, CQRS, and the Idempotent Consumer pattern.

Also explained in

Compare how 29 books explain handler →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.