f8b21af4be
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>
214 lines
7.9 KiB
Markdown
214 lines
7.9 KiB
Markdown
---
|
|
id: wiki-2026-0508-복잡한-비즈니스-도메인-금융-헬스케어-이커머스-등
|
|
title: 복잡한 비즈니스 도메인 (금융, 헬스케어, 이커머스 등)
|
|
category: 10_Wiki/Topics
|
|
status: verified
|
|
canonical_id: self
|
|
aliases: [Complex Business Domains, Domain-Heavy Systems]
|
|
duplicate_of: none
|
|
source_trust_level: A
|
|
confidence_score: 0.9
|
|
verification_status: applied
|
|
tags: [domain-driven-design, business-domain, architecture, ddd]
|
|
raw_sources: []
|
|
last_reinforced: 2026-05-10
|
|
github_commit: pending
|
|
tech_stack:
|
|
language: TypeScript
|
|
framework: NestJS / Spring Boot
|
|
---
|
|
|
|
# 복잡한 비즈니스 도메인 (금융, 헬스케어, 이커머스)
|
|
|
|
## 매 한 줄
|
|
> **"매 복잡한 도메인은 코드의 형태가 아니라 도메인 모델의 형태로 정복된다"**. 매 금융, 헬스케어, 이커머스는 각각 규제, 정확성, 동시성 압력이 다르며 매 DDD bounded context + invariant enforcement + event sourcing 이 2026 의 default approach.
|
|
|
|
## 매 핵심
|
|
|
|
### 매 도메인별 압력
|
|
- **금융**: 매 정확성 (decimal arithmetic, no float), audit trail, regulatory (SOX, MiFID II, Basel III, K-AML), idempotency.
|
|
- **헬스케어**: 매 PHI privacy (HIPAA, GDPR Art.9, K-MyData), HL7/FHIR interoperability, clinical decision support, audit immutability.
|
|
- **이커머스**: 매 inventory consistency, payment idempotency, fraud detection, peak-load (Black Friday) elasticity, multi-currency/tax.
|
|
|
|
### 매 공통 architectural pillars
|
|
- **Bounded Context**: 매 Order, Payment, Inventory, Patient, Claim 의 명확한 ownership boundaries.
|
|
- **Aggregate root + invariants**: 매 transactional consistency unit, business rule enforcement.
|
|
- **Event Sourcing + CQRS**: 매 audit trail + read/write workload split.
|
|
- **Sagas / Process Managers**: 매 distributed transaction 대신 compensating actions.
|
|
- **Anti-corruption layer**: 매 legacy 시스템 (COBOL, HL7v2, EDI) 과의 격리.
|
|
|
|
### 매 응용
|
|
1. 매 금융: 매 ledger as append-only event log, double-entry bookkeeping, eventual consistency 위 strong invariants.
|
|
2. 매 헬스케어: 매 FHIR resource model + consent management + audit per-field-access.
|
|
3. 매 이커머스: 매 inventory reservation saga + payment authorization/capture + outbox pattern.
|
|
|
|
## 💻 패턴
|
|
|
|
### Decimal money (금융)
|
|
```typescript
|
|
import Decimal from 'decimal.js';
|
|
|
|
class Money {
|
|
constructor(readonly amount: Decimal, readonly currency: string) {}
|
|
static of(amount: string, currency: string) {
|
|
return new Money(new Decimal(amount), currency);
|
|
}
|
|
add(other: Money): Money {
|
|
if (other.currency !== this.currency) throw new Error('currency mismatch');
|
|
return new Money(this.amount.plus(other.amount), this.currency);
|
|
}
|
|
// never use number — IEEE-754 binary float ruins cents
|
|
}
|
|
```
|
|
|
|
### Aggregate with invariants (이커머스)
|
|
```typescript
|
|
class Order {
|
|
private items: OrderItem[] = [];
|
|
private status: 'draft'|'placed'|'paid'|'fulfilled'|'cancelled' = 'draft';
|
|
|
|
addItem(productId: string, qty: number, unitPrice: Money) {
|
|
if (this.status !== 'draft') throw new Error('cannot modify placed order');
|
|
if (qty <= 0) throw new Error('qty>0');
|
|
this.items.push(new OrderItem(productId, qty, unitPrice));
|
|
}
|
|
|
|
place(): OrderPlaced {
|
|
if (this.items.length === 0) throw new Error('empty order');
|
|
this.status = 'placed';
|
|
return { type: 'OrderPlaced', orderId: this.id, total: this.total() };
|
|
}
|
|
}
|
|
```
|
|
|
|
### Saga: payment + inventory (이커머스)
|
|
```typescript
|
|
async function placeOrderSaga(orderId: string) {
|
|
const reservation = await inventory.reserve(orderId);
|
|
try {
|
|
const payment = await payments.authorize(orderId);
|
|
try {
|
|
await inventory.commit(reservation.id);
|
|
await payments.capture(payment.id);
|
|
} catch (e) {
|
|
await payments.void(payment.id);
|
|
await inventory.release(reservation.id);
|
|
throw e;
|
|
}
|
|
} catch (e) {
|
|
await inventory.release(reservation.id);
|
|
throw e;
|
|
}
|
|
}
|
|
```
|
|
|
|
### Event sourcing (금융 ledger)
|
|
```typescript
|
|
type LedgerEvent =
|
|
| { type: 'AccountOpened', accountId: string, currency: string }
|
|
| { type: 'Debited', accountId: string, amount: string, txId: string }
|
|
| { type: 'Credited', accountId: string, amount: string, txId: string };
|
|
|
|
function reduce(events: LedgerEvent[]): Account {
|
|
return events.reduce((acc, e) => {
|
|
if (e.type === 'AccountOpened') return { ...acc, currency: e.currency, balance: new Decimal(0) };
|
|
if (e.type === 'Debited') return { ...acc, balance: acc.balance.minus(e.amount) };
|
|
if (e.type === 'Credited') return { ...acc, balance: acc.balance.plus(e.amount) };
|
|
return acc;
|
|
}, {} as Account);
|
|
}
|
|
```
|
|
|
|
### FHIR resource (헬스케어)
|
|
```typescript
|
|
interface Patient {
|
|
resourceType: 'Patient';
|
|
id: string;
|
|
identifier: Array<{ system: string; value: string }>;
|
|
name: HumanName[];
|
|
birthDate: string; // ISO8601
|
|
consent?: Reference<Consent>; // K-MyData / HIPAA consent linkage
|
|
}
|
|
```
|
|
|
|
### Outbox pattern (이커머스 reliability)
|
|
```typescript
|
|
await db.transaction(async tx => {
|
|
await tx.insert('orders', order);
|
|
await tx.insert('outbox', {
|
|
id: ulid(),
|
|
aggregateId: order.id,
|
|
type: 'OrderPlaced',
|
|
payload: JSON.stringify(event),
|
|
createdAt: new Date(),
|
|
});
|
|
});
|
|
// async outbox poller publishes to Kafka — at-least-once delivery
|
|
```
|
|
|
|
### Anti-corruption layer (legacy HL7v2 → FHIR)
|
|
```typescript
|
|
class HL7v2ToFhirAdapter {
|
|
translate(adt: Hl7v2Message): Patient {
|
|
const pid = adt.segment('PID');
|
|
return {
|
|
resourceType: 'Patient',
|
|
id: pid.field(3).value(),
|
|
name: [{ family: pid.field(5).component(1), given: [pid.field(5).component(2)] }],
|
|
birthDate: this.parseHl7Date(pid.field(7).value()),
|
|
identifier: [{ system: 'urn:hospital:mrn', value: pid.field(3).value() }],
|
|
};
|
|
}
|
|
}
|
|
```
|
|
|
|
### Idempotency key (payments)
|
|
```typescript
|
|
async function charge(req: ChargeRequest, idempotencyKey: string) {
|
|
const existing = await db.idempotency.findOne({ key: idempotencyKey });
|
|
if (existing) return existing.response;
|
|
const result = await processor.charge(req);
|
|
await db.idempotency.insert({ key: idempotencyKey, response: result, ttl: '24h' });
|
|
return result;
|
|
}
|
|
```
|
|
|
|
## 매 결정 기준
|
|
| 상황 | Approach |
|
|
|---|---|
|
|
| 금융 ledger | Event sourcing + double-entry |
|
|
| 헬스케어 record | FHIR + consent + audit log |
|
|
| 이커머스 order flow | Saga + outbox + idempotency |
|
|
| Cross-domain integration | Anti-corruption layer |
|
|
| Strong invariant | Aggregate boundary, single-writer |
|
|
| High read throughput | CQRS read model |
|
|
|
|
**기본값**: 매 Bounded Context first, Aggregate + invariants second, Events as integration third.
|
|
|
|
## 🔗 Graph
|
|
- 부모: [[Domain-Driven Design]] · [[Bounded_Context]]
|
|
- 변형: [[Event Sourcing]] · [[CQRS]]
|
|
- 응용: [[이커머스의 실시간 재고 관리]] · [[엔터프라이즈 소프트웨어 개발]]
|
|
- Adjacent: [[ACID Transactions]] · [[비기능 요구사항 (Non-functional Requirements)]]
|
|
|
|
## 🤖 LLM 활용
|
|
**언제**: 매 도메인 모델링, invariant 추출, ubiquitous language 정리, regulatory mapping (HIPAA → field-level access policy).
|
|
**언제 X**: 매 specific compliance interpretation (변호사·CISO 검토 필수), 매 production money handling (independent audit 필요).
|
|
|
|
## ❌ 안티패턴
|
|
- **Anonymic domain model**: 매 getter/setter 만 있는 비즈니스 로직 없는 entity → service 비대화.
|
|
- **Float for money**: 매 0.1 + 0.2 ≠ 0.3 의 IEEE-754 catastrophe.
|
|
- **Distributed transaction (2PC)**: 매 micro-services 간 2PC → coordinator deadlock + low availability.
|
|
- **One DB for all bounded contexts**: 매 schema coupling 으로 deploy lock-step.
|
|
- **PHI in logs**: 매 healthcare/finance 의 unmasked PII/PHI 가 log 에 → instant compliance breach.
|
|
|
|
## 🧪 검증 / 중복
|
|
- Verified (Evans "Domain-Driven Design", Vernon "Implementing DDD", FHIR R5 spec, ISO 20022).
|
|
- 신뢰도 A.
|
|
|
|
## 🕓 Changelog
|
|
| 날짜 | 변경 |
|
|
|---|---|
|
|
| 2026-05-08 | Phase 1 |
|
|
| 2026-05-10 | Manual cleanup — finance/healthcare/ecommerce DDD patterns 정리 |
|