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
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:
- Timestamps: Every event includes
time. Consumers can discard stale events. - Idempotent handlers: Operations should be safe to retry or reorder.
- Last-write-wins: For non-critical data, accept the latest timestamp.
Eventual Consistency
Problem: Afteruser.deleted, other services may still show the user briefly.
Solution:
- Accept it: Most use cases tolerate seconds of delay.
- 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 Pattern1
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
Schema Evolution
Adding Fields
New fields can be added without breaking consumers:Changing Fields
For breaking changes:- Increment version
- Publish both versions during transition
- Consumers upgrade to new version
- Stop publishing old version