Files
2nd/10_Wiki/Topics/Architecture/Simple event processing.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

172 lines
4.8 KiB
Markdown

---
id: wiki-2026-0508-simple-event-processing
title: Simple Event Processing
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [SEP, Direct Event Handling, 1:1 Event Processing]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [event-driven, architecture, eda, messaging]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: typescript
framework: kafka
---
# Simple Event Processing
## 매 한 줄
> **"매 1 event → 1 reaction. No correlation, no aggregation, no temporal pattern."**. 매 EDA 의 simplest tier — notable event 의 detect 후 매 single downstream action 의 trigger. 매 CEP (Complex Event Processing) / ESP (Event Stream Processing) 와 대비되는 매 baseline pattern.
## 매 핵심
### 매 SEP vs ESP vs CEP
- **SEP**: 1 event → 1 action. No state, no correlation.
- **ESP**: stream 의 windowing, aggregation (Flink, Kafka Streams).
- **CEP**: pattern matching across events (Drools Fusion, Esper).
### 매 properties
- Stateless (매 event 의 self-contained).
- Low latency (no buffering / windowing).
- High throughput (parallelize trivially).
- Idempotent handlers preferred (at-least-once delivery).
### 매 응용
1. Order placed → email confirmation.
2. User signup → welcome workflow.
3. Sensor reading → threshold alert.
4. Payment captured → inventory reserve.
5. Log line → metric increment.
## 💻 패턴
### Kafka consumer (TypeScript)
```typescript
import { Kafka } from 'kafkajs';
const kafka = new Kafka({ brokers: ['localhost:9092'] });
const consumer = kafka.consumer({ groupId: 'order-emails' });
await consumer.subscribe({ topic: 'orders.placed' });
await consumer.run({
eachMessage: async ({ message }) => {
const order = JSON.parse(message.value!.toString());
await sendOrderEmail(order.userId, order.id);
},
});
```
### AWS EventBridge rule
```typescript
import { EventBridgeClient, PutRuleCommand } from '@aws-sdk/client-eventbridge';
await client.send(new PutRuleCommand({
Name: 'order-placed-email',
EventPattern: JSON.stringify({
source: ['app.orders'],
'detail-type': ['OrderPlaced'],
}),
Targets: [{ Arn: lambdaArn, Id: 'send-email' }],
}));
```
### NATS subject handler
```typescript
import { connect, StringCodec } from 'nats';
const nc = await connect({ servers: 'nats://localhost:4222' });
const sc = StringCodec();
const sub = nc.subscribe('orders.placed');
for await (const msg of sub) {
const order = JSON.parse(sc.decode(msg.data));
await reserveInventory(order);
}
```
### Idempotent handler
```typescript
async function handleOrderPlaced(event: OrderEvent) {
const seen = await redis.set(`processed:${event.id}`, '1', 'NX', 'EX', 86400);
if (!seen) return; // already handled
await sendEmail(event);
}
```
### Dead-letter handling
```typescript
await consumer.run({
eachMessage: async ({ message }) => {
try {
await handle(message);
} catch (err) {
await producer.send({
topic: 'orders.placed.dlq',
messages: [{ value: message.value, headers: { error: err.message } }],
});
}
},
});
```
### CloudEvents envelope
```typescript
const cloudEvent = {
specversion: '1.0',
type: 'com.example.order.placed',
source: '/orders',
id: crypto.randomUUID(),
time: new Date().toISOString(),
data: { orderId, userId, amount },
};
await producer.send({ topic: 'orders.placed', messages: [{ value: JSON.stringify(cloudEvent) }] });
```
### Webhook fan-out
```typescript
app.post('/webhooks/payment', async (req, res) => {
await eventBus.publish('payment.captured', req.body);
res.status(202).end();
});
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| 1:1 event → action, stateless | SEP |
| Stream aggregation (window sums) | ESP (Flink) |
| Pattern detect (A then B within 5s) | CEP (Esper) |
| Cross-system fan-out | SEP via EventBridge/Kafka |
**기본값**: Kafka or EventBridge + idempotent stateless handlers.
## 🔗 Graph
- 부모: [[Event-Driven-Architecture]]
- 변형: [[Event-Stream-Processing]]
- 응용: [[Webhooks]] · [[Pub-Sub]] · [[Event-Sourcing]]
- Adjacent: [[CQRS]]
## 🤖 LLM 활용
**언제**: stateless 1:1 event handling — webhook, notification, simple workflow trigger.
**언제 X**: pattern correlation 필요 — CEP / ESP 사용.
## ❌ 안티패턴
- **Stateful SEP**: 매 cross-event state 가지면 ESP 로 reframe.
- **No idempotency**: at-least-once delivery 에서 매 duplicate side-effect.
- **Synchronous webhook chain**: 매 cascading failure — async queue 사이로.
## 🧪 검증 / 중복
- Verified (Hohpe Enterprise Integration Patterns, Confluent docs, AWS EventBridge guide).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — SEP vs ESP vs CEP, Kafka/EventBridge/NATS patterns |