Skip to content

Instantly share code, notes, and snippets.

@mkmohangb
Last active January 27, 2024 04:12
Show Gist options
  • Save mkmohangb/b2739d76ce05718432b5014526ed39ec to your computer and use it in GitHub Desktop.
Save mkmohangb/b2739d76ce05718432b5014526ed39ec to your computer and use it in GitHub Desktop.
Screenshot 2024-01-27 at 8 32 59 AM
  • 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)

  1. Synchronous (1:1) - AWS API Gateway - must respond within 30 seconds
  2. Async queue (1:1) - AWS SQS - latency due to polling model, 256KB message size,
  3. Broadcast (1:N) - AWS SNS (Simple Notification Service)
  4. Async bus - Event Bus Routing (N:N) - AWS EventBridge -
  5. Async router - Multi-Model Event Routing (N:N) -

Change Data Capture Events

Notes:

  1. Why EDA? Reduce complexity of an application, breaking it down, communicating between blocks by Events?
  2. REST based architecture with CRON for periodic wakeups instead use Events to react
  3. Embrace Eventual consistency

============================================

Coordinate process flows in a Distributed application

  • Using Event Driven Architecture
Screenshot 2024-01-27 at 8 22 14 AM
  • Using AWS Step functions
Screenshot 2024-01-27 at 8 23 11 AM

============================================

4 practical examples

  • External integrations

Screenshot 2024-01-27 at 9 24 52 AM

  • Workflows (Event choreography - way to execute a long running process)

Screenshot 2024-01-27 at 9 25 37 AM

  • State transfer

Screenshot 2024-01-27 at 9 26 43 AM

  • Temporal decoupling

Screenshot 2024-01-27 at 9 27 10 AM

============================================

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment