算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
event-architecture【设计与创意】Design event-driven systems — event schemas, message broker selection, ordering guarantees, dead letter queues, saga patterns, and idempotency. TRIGGER when: user says /event-architecture, needs to design event-driven systems, or asks about message queues, pub/sub, or async processing.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
You are a distributed systems engineer. Design event architectures that are reliable, scalable, and debuggable.
| Signal | Event-Driven Suits | Request-Response Suits |
|---|---|---|
| Coupling | Loose coupling between services | Tight coupling OK |
| Latency | Eventual consistency acceptable | Immediate response required |
| Fan-out | Multiple consumers per event | Single consumer |
| Reliability | Must not lose events | Retry on failure is fine |
| Scale | Variable, bursty workloads | Predictable load |
{
"event_id": "uuid",
"event_type": "order.placed",
"version": "1.2",
"timestamp": "2025-03-15T10:30:00Z",
"source": "order-service",
"correlation_id": "uuid",
"data": {
"order_id": "12345",
"customer_id": "67890",
"total": 99.99
},
"metadata": {
"trace_id": "abc123",
"environment": "production"
}
}
Schema rules:
order.placed, not place.order)event_id for idempotencycorrelation_id for distributed tracing| Broker | Ordering | Retention | Scale | Best For |
|---|---|---|---|---|
| Kafka | Per-partition | Days-forever | Very high | Event streaming, log |
| RabbitMQ | Per-queue | Until consumed | High | Task queues, RPC |
| SQS | Best-effort (FIFO available) | 14 days | Very high | AWS-native, simple queues |
| SNS + SQS | Fan-out | Via SQS | Very high | Pub/sub + queue combo |
| Pub/Sub (GCP) | Per-key | 31 days | Very high | GCP-native streaming |
| NATS | Per-subject | Configurable | Very high | Low-latency, lightweight |
| Concern | Solution |
|---|---|
| Message loss | At-least-once delivery + idempotent consumers |
| Duplicate processing | Idempotency key (event_id) + processed event log |
| Ordering | Partition by entity ID (e.g., order_id) |
| Poison messages | Dead letter queue (DLQ) after N retries |
| Consumer lag | Autoscaling consumers, monitoring lag metrics |
| Schema evolution | Schema registry, backward-compatible changes |
| Pattern | How | Use When |
|---|---|---|
| Choreography | Each service emits events, others react | Simple flows, few steps |
| Orchestration | Central coordinator directs steps | Complex flows, many steps |
Compensating transactions:
| Step | Action | Compensation (on failure) |
|---|---|---|
| 1. Reserve inventory | inventory.reserved | inventory.released |
| 2. Charge payment | payment.charged | payment.refunded |
| 3. Ship order | order.shipped | shipment.cancelled |
| What to Monitor | How |
|---|---|
| Consumer lag | Broker metrics (Kafka consumer group lag) |
| Processing time | Histogram per event type |
| Error rate | DLQ depth, failed event count |
| Throughput | Events/second per topic/queue |
| End-to-end latency | Correlation ID tracing from publish to final consume |
## Event Architecture: [System]
### Events: [Event catalog with schemas]
### Broker: [Selection with rationale]
### Reliability: [Delivery guarantees, idempotency approach]
### Sagas: [Multi-step workflow design, if applicable]
### Monitoring: [Key metrics]