![Screenshot 2024-01-27 at 8 32 59 AM](https://private-user-images.githubusercontent.com/2610866/300148948-68cf5dc7-e6e9-4b6c-9f16-4bff1b019bb6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxMDg0OTcsIm5iZiI6MTcyMjEwODE5NywicGF0aCI6Ii8yNjEwODY2LzMwMDE0ODk0OC02OGNmNWRjNy1lNmU5LTRiNmMtOWYxNi00YmZmMWIwMTliYjYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjdUMTkyMzE3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njc2MjcyYWJlN2IyNGViZjlkZjdiZjE5M2I2OGFlZmY5NTIzMmE1MjhlNmExYTU4M2VkZWNmZTkyZDRlZjI0ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.gZ9JIyVZzwW4ZHAYC9ua6qodvW3cg87_lqUv2XLG4zM)
-
Event - Events are immutable. Something that happened in the past.
-
Producer - Creates Events
-
Consumer - reacts to Events
-
Channel - service/mechanism that events flow through
-
Idempotency - if the same event is processed more than once, it will not cause unintended or duplicate effects on the system. Implemented via unique identifiers.(e.g. pushing an elevator button)
Response Models (how to communicate / process events)
- Synchronous (1:1) - AWS API Gateway - must respond within 30 seconds
- Async queue (1:1) - AWS SQS - latency due to polling model, 256KB message size,
- Broadcast (1:N) - AWS SNS (Simple Notification Service)
- Async bus - Event Bus Routing (N:N) - AWS EventBridge -
- Async router - Multi-Model Event Routing (N:N) -
Change Data Capture Events
Notes:
- Why EDA? Reduce complexity of an application, breaking it down, communicating between blocks by Events?
- REST based architecture with CRON for periodic wakeups instead use Events to react
- Embrace Eventual consistency
============================================
Coordinate process flows in a Distributed application
- Using Event Driven Architecture
![Screenshot 2024-01-27 at 8 22 14 AM](https://private-user-images.githubusercontent.com/2610866/300148197-eaa28e4c-f95a-4840-b95e-ddd831d5cee3.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxMDg0OTcsIm5iZiI6MTcyMjEwODE5NywicGF0aCI6Ii8yNjEwODY2LzMwMDE0ODE5Ny1lYWEyOGU0Yy1mOTVhLTQ4NDAtYjk1ZS1kZGQ4MzFkNWNlZTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjdUMTkyMzE3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ODUyNTBmOTY2YWFlNDc5ZTAzMDJjZjQ3NTkwNDFmNDc2ZDRjOWVjNWQ4MDhiYWMyMDNmZWVhNmJiMjE0ZjIyYyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.g5IvqDVi1f3Eg_3OTot33ppJ4pmrzFWh9C2J4N5hRW4)
- Using AWS Step functions
![Screenshot 2024-01-27 at 8 23 11 AM](https://private-user-images.githubusercontent.com/2610866/300148208-9d97403a-d4c1-4a12-a5a9-58583373e649.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxMDg0OTcsIm5iZiI6MTcyMjEwODE5NywicGF0aCI6Ii8yNjEwODY2LzMwMDE0ODIwOC05ZDk3NDAzYS1kNGMxLTRhMTItYTVhOS01ODU4MzM3M2U2NDkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjdUMTkyMzE3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmM4YThkMDkyOTE4ZmVhNjA0YmVhYjIxNTM3ZTAwZTc1NDIzMTYzM2ZjMWYzOGViZjdhYmVjNWRlODNmYzU0NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.-bsDVXk_4woGziAgotfxjxPfjvHQ0hb05nWyve6KtKw)
============================================
4 practical examples
- External integrations
- Workflows (Event choreography - way to execute a long running process)
- State transfer
- Temporal decoupling
============================================
Pub-sub model
Pros:
- Decoupling of Publisher - Subscriber
- Dependency inversion - both pub/sub are dependent on an abstraction
- Scalability
Cons:
- Eventual consistency - two people ordering the last item. Use cache.
- Duplicate messages - broker doesn't checkpoint at a very granular level so when a subscriber goes down and comes back it might receive an already processed message - Use Idempotency to mitigate - Unique id in the event
- More complex - harder to debug
References: