Customer places order: A customer submits an order on an e-commerce website.
Order event: The order placement generates an “order created” event.
Event router: The event is sent to a central event router or event bus (e.g., Amazon EventBridge, Azure Event Grid).
Parallel processing: Multiple serverless functions are triggered in parallel:
Inventory check function: A function checks if the ordered items are in stock.
Payment processing function: A function processes the customer’s payment.
Fraud detection function: A function analyzes the order for potential fraud.
Order Confirmation: A final serverless function gathers results from previous steps and sends an order confirmation email to the customer.
Events can trigger chains of other events, like a domino effect. A single action can cause a cascade of transformations and updates throughout your system.
Using EDA with serverless computing offers several features:
Decoupling: EDA allows for loose coupling between components, a key strength of serverless functions. Each function acts independently, reacting to specific events.
Scalability: Serverless functions scale automatically based on demand. EDA’s asynchronous nature complements this, allowing the system to handle bursts of events efficiently.
Efficiency: With serverless, you only pay when functions are running. EDA prevents idle waiting; functions are triggered only when necessary.
Reactivity: EDA lets applications respond to events in real time, which is crucial for use cases like real-time data processing or user interactions.
Common use cases
EDA and serverless computing are relatively new terms in the software field. But as time goes on, new applications are being discovered that can greatly benefit from them.
Data processing pipelines: Files uploaded to storage can trigger serverless functions for image resizing, video transcoding, etc.
Microservices communication: Services in a microservices architecture can communicate via events without requiring direct, synchronous calls.
IoT applications: Events from sensors and devices can trigger real-time actions or analysis.
Key considerations
As with anything in computing, EDA in serverless computing comes with a few cautionary steps that must be taken to ensure the effectiveness of their application:
Event routing: Choose a robust event routing mechanism (e.g., Amazon EventBridge, AWS SNS, Azure Event Grid)
Error handling: Design for event-driven failures and implement retry mechanisms.
Observability: Monitor the flow of events in your system for debugging and optimization.
Note: With EDA and serverless, failures become less catastrophic. If an event doesn't get processed, you can easily retry, while the rest of your system is unaware and functioning normally.
Test yourself
Before moving on to the conclusion, test your understanding: