Part 03 of 16 · Day 1 · publish/subscribe, queues

A sender that knows every recipient

Problem and experience

Who should react to the event?

The sender doesn't want to know everyone who needs the event. The recipient doesn't want to process what doesn't concern it.

Direct call

  1. Calculator
  2. calls Risk
  3. calls Process
  4. calls Projection

Consequence

  1. New servicemeans changing the sender

From practiceHow many places does a sender in your system have to know today for a change to spread?

TakeawayThe more recipients the sender knows, the harder it is to change.

More on this topic

What it means

A subscriber is a service that has subscribed to a certain type of event.

Why we use it

The sender sends the event once. Who reads it is decided by routing, not by the sender.

When it makes sense

When several services react to one event and the list changes.

Where it breaks

  • A sender that sends a message “to a specific service”.
  • A subscriber that reads everything and filters on its own.

Imagine

MortgageApplicationSubmitted is read by Risk Service and Process Manager. A new service, say an Audit one, just subscribes.

Who reads an event should not be the concern of whoever writes it.

Principle, application and exercise

Each subscriber has its own queue

The broker receives the event and delivers it to subscriber queues according to the routing table. Each consumes at its own pace.

Routing

  1. MortgageApplicationSubmitted
  2. Brokerrouting by type
  3. Risk queue
  4. Risk Service

Same event, second subscriber

  1. Broker
  2. Process queue
  3. Process Manager

Trade-offLoose coupling means nobody sees the whole flow. We need documented routing and event correlation.

TakeawayA queue decouples the sender's pace from the recipient's.

More on this topic

What it means

The routing table says which event types go to which queue. Each queue has one reader.

Why we use it

Recipients don't have to know each other or run at the same time.

When it makes sense

When we need one subscriber's outage not to affect the others.

Where it breaks

  • Routing scattered across the code instead of one place.
  • One shared queue for all subscribers.
  • Forgetting that reactions arrive with a delay.

Imagine

Risk Service is slower. The Process queue is processed immediately and Risk takes messages at its own pace.

A queue is an agreement that anyone can be slower or faster.

Training for your team

Would you like this training for your team?

We run the training on your code and your domain problem. We agree the scope, dates and format with you.

Discuss the training