Ahmed Hassan·
Orchestrated saga for checkout, choreography for the rest, plus the outbox pattern I kept forgetting
Creates a robust event-driven architecture with event schemas, choreography vs orchestration decisions, saga patterns, and dead letter handling.
Event-Driven Architecture Design
Act as an Event-Driven Architecture specialist who implemented EDA at Uber and Airbnb. Design an event-driven system for my domain.
**Business Domain**: {{business_domain}} (e.g., order processing, ride sharing, insurance claims)
**Event Producers**: {{event_producers}} (services/systems that generate events)
**Event Consumers**: {{event_consumers}} (services/systems that react to events)
**Consistency Requirements**: {{consistency_requirements}} (eventual vs strong, out-of-order handling, exactly-once semantics)
Design the following:
1. **Event Catalog** - Complete list of domain events with schema (CloudEvents or custom), version, and ownership
2. **Event Schema Design** - JSON Schema/Avro/Protobuf for each event type with field definitions and evolution rules
3. **Choreography vs Orchestration Map** - Which flows use choreography (decentralized) vs orchestration (centralized saga coordinator)
4. **Saga Patterns** - Each business transaction as a saga with compensating actions, timeout policies, and failure handling
5. **Event Bus Selection** - Kafka, NATS, EventBridge, RabbitMQ with justification and cluster topology
6. **Topic/Channel Design** - Naming convention, partitioning strategy, consumer group assignments
7. **Event Sourcing Decision** - Which aggregates use event sourcing vs CRUD, snapshot strategy, event store selection
8. **CQRS Implementation** - Command and query model separation, read model projection strategy and storage
9. **Outbox Pattern** - Implementation for guaranteed event delivery from transactional systems
10. **Dead Letter Handling** - DLQ configuration, retry policies (exponential backoff), poison pill handling, alerting
11. **Idempotency Strategy** - Consumer idempotency keys, idempotency storage, deduplication window
12. **Observability** - Event tracing (correlation IDs), lag monitoring, event flow visualization, schema registry monitoring
13. **Testing Strategy** - Contract testing (Pact), event-driven integration tests, chaos testing event flows
Include actual event schemas in Avro/JSON Schema format and pseudocode for saga orchestration.
Ergebnisse
Event-driven design for **order processing** (order-service produces, payment/inventory/notification consume; eventual consistency, exactly-once effects). Orchestrated saga for the checkout flow, choreography for everything else.
**Event schema (Avro)**
```json
{
"type": "record", "name": "OrderPlaced", "namespace": "shop.order.v1",
"fields": [
{ "name": "orderId", "type": "string" },
{ "name": "customerId", "type": "string" },
{ "name": "totalCents", "type": "long" },
{ "name": "occurredAt", "type": { "type": "long", "logicalType": "timestamp-millis" } }
]
}
```
**Checkout saga (orchestrated)** — central coordinator with compensations:
```
PlaceOrder ─▶ ReserveStock ──ok──▶ ChargePayment ──ok──▶ ConfirmOrder
│ fail │ fail
▼ ▼
(none) ReleaseStock ◀── compensating action
```
**Why orchestration here:** money + inventory must unwind in a defined order; a coordinator makes the compensation logic explicit and testable. Everything downstream of `OrderConfirmed` (emails, analytics) is plain choreography — those consumers just react.
**Reliability primitives:** the **outbox pattern** writes the event in the same DB transaction as the order, so no event is lost if the broker is down; a relay polls the outbox into Kafka. Consumers dedupe on `orderId` with a 24h idempotency store. **DLQ** per topic with exponential-backoff retry topics (1m, 5m, 30m), then alert. Correlation IDs flow through every event for end-to-end tracing.
Modell: Claude Opus 4
24 Likes4 SavesScore: 20
1 Kommentar
Jonas Weber·
Wish I'd had this prompt six months ago, would've saved a weekend.