Skip to main content

Overview

The User Service communicates with other services via Amazon EventBridge, a serverless event bus. This provides loose coupling, enabling services to react to user lifecycle events without direct dependencies.

Why EventBridge?

SQS is ideal for point-to-point messaging or work queues. EventBridge is better for event-driven architectures where multiple services react to the same event.

Events Published

User Events

Email Events

Event Schema

All events follow a consistent envelope:

Schema Fields

Always include version in events. Consumers can handle multiple versions during migration periods.

Event Consumers

Who Subscribes to What?

EventBridge Rules

Events Consumed

The User Service also consumes events from other services:

Hard Parts

Event Ordering

Problem: Events may arrive out of order. user.updated might arrive before user.created. Solution:
  1. Timestamps: Every event includes time. Consumers can discard stale events.
  2. Idempotent handlers: Operations should be safe to retry or reorder.
  3. Last-write-wins: For non-critical data, accept the latest timestamp.

Eventual Consistency

Problem: After user.deleted, other services may still show the user briefly. Solution:
  1. Accept it: Most use cases tolerate seconds of delay.
  2. Critical path queries: For operations that cannot tolerate stale data, query the source service directly.

Failed Event Processing

Problem: Consumer fails to process an event (bug, downstream outage). Solution: Dead Letter Queue (DLQ) with alerting and replay capability. DLQ Configuration:
  • Max retries: 3 (with exponential backoff)
  • DLQ retention: 14 days
  • Alarm on DLQ depth > 0

Guaranteed Delivery

Problem: Lambda publishes to DynamoDB but EventBridge call fails. Event is lost. Solution: Transactional Outbox Pattern
1

Write to Outbox

In the same DynamoDB transaction, write the event to an outbox table
2

Async Publisher

Separate Lambda polls outbox (or uses DynamoDB Streams) and publishes to EventBridge
3

Delete from Outbox

After successful publish, delete from outbox
The outbox pattern adds complexity. Only use it when event delivery is truly critical. For many use cases, at-least-once delivery with idempotent consumers is sufficient.

Schema Evolution

Adding Fields

New fields can be added without breaking consumers:

Changing Fields

For breaking changes:
  1. Increment version
  2. Publish both versions during transition
  3. Consumers upgrade to new version
  4. Stop publishing old version

EventBridge Schema Registry

Register schemas for documentation and validation: