
We all know that our imagination can take us beyond the unthinkable. I was sitting inside a beautiful conference room in Stockholm, listening to a great talk on ‘Serverless Data Streaming at Scale’ by Anahit Pogosova at the AWS Nordics Community Day 2020. I was due to get to the stage next to talk about Amazon EventBridge and specifically about streamlining the microservices communications in an event-driven architecture.
As much as I wanted to listen in, my mind was searching for a simple analogy to explain the EventBridge event filtering and dispatch rules to the audience. Few thoughts came and went. I was still searching and thinking, and that’s when the lunch I had an hour ago flashed through my mind. I don’t recollect the name of the dish but it had salmon in it. Flash bulb moment and the idea was born!
Here we go…
Event flow
Imagine you go out fishing to a resourceful part of the sea. You see the abundance of fish in various types and shapes. These are like the different events carrying different information flowing through the event bus in EventBridge.
Remember that you still haven’t laid the nets out there yet. Hence all these fish are swimming freely and disappearing. This is the case when you don’t have any filtering rules set in EventBridge. The events that are sent to the bus simply disappear as there is nothing to trap them.
Filtering
You have now anchored your boat and about to lay out the fishing nets. As you are a techie, you are laying out not just any fishing net but a hi-tech fishing net. This means, one net can catch the salmon, the other net can trap only the tuna, then there is one for bigger tuna, smaller tuna, so on and so forth. You get the idea, right? This is how the event filtering rules are configured. You lay the trap for those events that need to be filtered in. Sometimes you filter at a higher level to catch all the events of the same type and other times you go deeper to match specific data for finer filtering. In EventBridge, such filtering is done by setting out ‘event filtering pattern’ JSON templates.
{
"detail": {
"metadata": {
"type": [
"ORDER"
],
"status": [
"SUBMITTED"
]
}
}
}
Event dispatch
You had a productive day with a good catch and you are now returning to the shores. Lets say today you used the tuna net and caught plenty of them.
Now that you had the perfect net (filter) to catch the desired fish (events), it is time to see how to send (dispatch) the fish (events) to the consumer markets (targets).
Say there is a fisheries department that keeps count of how much fish is caught for the purpose of sustainability, control over fishing, etc. To comply with this, you need to send a count of tuna you caught. The department is not interested in any fish but the count. The equivalent in EventBridge is the ‘Constant (or Static) event flow’, where a static piece of data is passed to the consuming targets. The event data never get exposed to the consumer.

Lets assume that tuna is in great demand in certain overseas markets. However, these markets (consumers), only want the good part of the fish and not necessarily the head, tail, etc. EventBridge helps to achieve this with its ‘Part of the matched event flow’ pattern. Using this, certain part of the event data can be identified and routed to the consuming targets.

How about dealing with a demanding consumer who needs cooked tuna chunks or tuna paste for making sandwiches? Here you need to transform the raw fish into something different by using the best bits. This is where EventBridge’s ‘Input transformer event flow’ pattern comes to the rescue. Using this pattern, required data attribute values can be extracted from the original event and can be then used to form a new data structure in order to send to the event targets.

Now its all about your local markets, such as fine dining restaurants, where they look for fresh produce with originality and authenticity without any alterations. So you send them the whole fish. EventBridge offers the ‘Matched event’ pattern, which is also the default option, where the filtered event is routed to the target without any change to the event data.
Unlike a fish, an event can carry potentially sensitive data. So it makes perfect sense to use this routing option only in cases where the exposure of the entire event is acceptable and not in violation of any data privacy issues.

There you have it! A very fishy tale to explain the EventBridge event filtering and dispatch configuration options.
Conclusion
When technology becomes a reflection of our day to day life, we can break new grounds and reach more audience. After all #ServerlessIsForEveryone and #ServerlessIsEverywhere.
Go Build Serverless!
Now that you are here, you can find the technical version of this write-up (with no fish attached) in my previous post The power of EventBridge is in its detail.
If you are new to Amazon EventBridge then I would encourage you to watch Deep Dive on Amazon EventBridge by Nick Smit for a detailed coverage.
A fishing analogy for EventBridge filtering rules was originally published in LEGO Engineering on Medium, where people are continuing the conversation by highlighting and responding to this story.